diff --git a/web/src/custom-section-builder.ts b/web/src/custom-section-builder.ts index 6601ad7..631f10b 100644 --- a/web/src/custom-section-builder.ts +++ b/web/src/custom-section-builder.ts @@ -651,6 +651,6 @@ function builderEscapeHtml(text: string): string { return div.innerHTML; } -document.addEventListener("DOMContentLoaded", initCustomSectionBuilder); +initCustomSectionBuilder(); export { addBookToSelection, removeBookFromSelection }; diff --git a/web/src/dashboard.ts b/web/src/dashboard.ts index d7e8249..0297bf5 100644 --- a/web/src/dashboard.ts +++ b/web/src/dashboard.ts @@ -425,65 +425,63 @@ function initDragAndDrop(): void { }); } -document.addEventListener("DOMContentLoaded", () => { - initDragAndDrop(); +initDragAndDrop(); - document.addEventListener("click", (e: Event) => { - const target = e.target as HTMLElement; - const actionElem = target.closest("[data-action]") as HTMLElement; - const action = actionElem?.getAttribute("data-action"); +document.addEventListener("click", (e: Event) => { + const target = e.target as HTMLElement; + const actionElem = target.closest("[data-action]") as HTMLElement; + const action = actionElem?.getAttribute("data-action"); - switch (action) { - case "scroll-carousel": { - const collectionId = - target.dataset.collectionId || actionElem?.dataset.collectionId; - const direction = parseInt( - target.dataset.direction || actionElem?.dataset.direction || "0", - ); - if (collectionId) scrollCarousel(collectionId, direction); - break; - } - - case "open-dashboard-settings": - openDashboardSettings(); - break; - - case "close-dashboard-settings": - closeDashboardSettings(); - break; - - case "save-dashboard-settings": - saveDashboardSettings(); - break; - - case "restore-system-collection": { - const colName = - actionElem?.dataset.collectionName || target.dataset.collectionName; - const colTitle = - actionElem?.dataset.collectionTitle || - target.dataset.collectionTitle || - "System Collection"; - if (colName) restoreSystemCollection(colName, colTitle); - break; - } - - case "view-book": { - const bookId = target.dataset.bookId || actionElem?.dataset.bookId; - if (bookId) viewBook(bookId); - break; - } - - case "reload-page": - reloadPage(); - break; - - case "switch-library": { - const select = target as HTMLSelectElement; - if (select.value) switchLibrary(select.value); - break; - } + switch (action) { + case "scroll-carousel": { + const collectionId = + target.dataset.collectionId || actionElem?.dataset.collectionId; + const direction = parseInt( + target.dataset.direction || actionElem?.dataset.direction || "0", + ); + if (collectionId) scrollCarousel(collectionId, direction); + break; } - }); + + case "open-dashboard-settings": + openDashboardSettings(); + break; + + case "close-dashboard-settings": + closeDashboardSettings(); + break; + + case "save-dashboard-settings": + saveDashboardSettings(); + break; + + case "restore-system-collection": { + const colName = + actionElem?.dataset.collectionName || target.dataset.collectionName; + const colTitle = + actionElem?.dataset.collectionTitle || + target.dataset.collectionTitle || + "System Collection"; + if (colName) restoreSystemCollection(colName, colTitle); + break; + } + + case "view-book": { + const bookId = target.dataset.bookId || actionElem?.dataset.bookId; + if (bookId) viewBook(bookId); + break; + } + + case "reload-page": + reloadPage(); + break; + + case "switch-library": { + const select = target as HTMLSelectElement; + if (select.value) switchLibrary(select.value); + break; + } + } document.addEventListener("input", (e: Event) => { const target = e.target as HTMLElement; diff --git a/web/src/search.ts b/web/src/search.ts index 67b16fd..028e91b 100644 --- a/web/src/search.ts +++ b/web/src/search.ts @@ -303,10 +303,9 @@ function selectLibraryAndBook(libraryId: string, bookId: string): void { hideSearchResults(); } -document.addEventListener("DOMContentLoaded", initializeSearch); - -export { selectLibraryAndBook }; +export { selectLibraryAndBook, initializeSearch }; Alpine.data("search", () => ({ selectLibraryAndBook, + initializeSearch, })); diff --git a/web/src/theme.ts b/web/src/theme.ts index 1802221..968e637 100644 --- a/web/src/theme.ts +++ b/web/src/theme.ts @@ -202,24 +202,15 @@ const updateWoodPanelingIndicators = (): void => { }); }; -// Auto-initialize when DOM is ready -if (typeof document !== "undefined") { - if (document.readyState === "loading") { - document.addEventListener("DOMContentLoaded", () => { - initializeTheme(); - loadWoodPaneling(); - updateWoodPanelingIndicators(); - }); - } else { - initializeTheme(); - loadWoodPaneling(); - updateWoodPanelingIndicators(); - } -} - Alpine.data("theme", () => ({ + applyTheme, changeTheme, changeWoodPaneling, + initializeTheme, + loadTheme, + loadUserTheme, + loadWoodPaneling, + updateWoodPanelingIndicators, })); export { diff --git a/web/src/toast.ts b/web/src/toast.ts index 435f01f..284713d 100644 --- a/web/src/toast.ts +++ b/web/src/toast.ts @@ -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 };