refactor: remove unnecessary DOMContentLoaded wrappers
Since main.js has 'defer' attribute, the DOM is guaranteed to be ready when modules execute. These wrappers are unnecessary. dashboard.ts: - Removed DOMContentLoaded wrapper, code runs directly - Event delegation setup runs immediately custom-section-builder.ts: - Removed DOMContentLoaded wrapper - initCustomSectionBuilder() called directly toast.ts: - Removed DOMContentLoaded wrapper - initializeToastSystem() called directly at top level - Removed dead Alpine.data registration (unused) search.ts: - Removed DOMContentLoaded wrapper - initializeSearch exported for use in header theme.ts: - Removed DOMContentLoaded wrapper - Functions now exported for use in header Alpine component
This commit is contained in:
+1
-19
@@ -1,4 +1,3 @@
|
||||
import { Alpine } from "./alpine";
|
||||
// Toast notification system for backend errors
|
||||
// Displays toast notifications at the top of the page
|
||||
|
||||
@@ -216,24 +215,7 @@ const initializeToastSystem = (): void => {
|
||||
setupFetchInterceptor();
|
||||
};
|
||||
|
||||
// Auto-initialize when DOM is ready
|
||||
if (typeof document !== "undefined") {
|
||||
if (document.readyState === "loading") {
|
||||
document.addEventListener("DOMContentLoaded", initializeToastSystem);
|
||||
} else {
|
||||
initializeToastSystem();
|
||||
}
|
||||
}
|
||||
|
||||
// Export toast API for manual use
|
||||
Alpine.data("showToast", () => ({
|
||||
error: (message: string, duration?: number) =>
|
||||
showToast(message, "error", duration),
|
||||
success: (message: string, duration?: number) =>
|
||||
showToast(message, "success", duration),
|
||||
info: (message: string, duration?: number) =>
|
||||
showToast(message, "info", duration),
|
||||
}));
|
||||
initializeToastSystem();
|
||||
|
||||
export { showToast };
|
||||
export type { ToastType };
|
||||
|
||||
Reference in New Issue
Block a user