refactor: Add Alpine.js registration to existing TypeScript modules
Added Alpine.global() registration to enable template access to functions: - admin.ts: Added Alpine for scan, stats, and settings functions - api-explorer.ts: Already had Alpine (kept as is) - bookshelf.ts: Added Alpine for library/bookshelf interactions - collections.ts: Added Alpine for collection management - conflicts.ts: Added Alpine for conflict resolution - device-management.ts: Added Alpine with event delegation for dynamic content - header.ts: Added Alpine for theme dropdown and user menu - library.ts: Added Alpine registrations - linking.ts: Added Alpine registrations - queue.ts: Added Alpine for queue operations - search.ts: Added Alpine registrations - themeDropdown.ts: Added Alpine for theme switching Each module now exports functions both traditionally and via Alpine.global() for template access.
This commit is contained in:
+16
-8
@@ -1,5 +1,9 @@
|
||||
// Header functionality
|
||||
|
||||
import { Alpine } from "./alpine";
|
||||
import { applyTheme } from "./theme";
|
||||
import { updateThemeIndicators } from "./themeDropdown";
|
||||
|
||||
const toggleThemeDropdown = (): void => {
|
||||
const dropdown = document.getElementById("theme-dropdown");
|
||||
if (dropdown) {
|
||||
@@ -28,9 +32,7 @@ const toggleUserMenu = (): void => {
|
||||
|
||||
const changeThemeTo = (theme: string): void => {
|
||||
// Apply the theme using the consolidated function from theme.ts
|
||||
if ((window as any).applyTheme) {
|
||||
(window as any).applyTheme(theme);
|
||||
}
|
||||
applyTheme(theme);
|
||||
|
||||
// Save to server if logged in
|
||||
const token = localStorage.getItem("token");
|
||||
@@ -85,8 +87,14 @@ document.addEventListener("click", (e) => {
|
||||
}
|
||||
});
|
||||
|
||||
// Make functions available globally
|
||||
(window as any).toggleThemeDropdown = toggleThemeDropdown;
|
||||
(window as any).toggleUserMenu = toggleUserMenu;
|
||||
(window as any).changeThemeTo = changeThemeTo;
|
||||
(window as any).logout = logout;
|
||||
export { toggleThemeDropdown, toggleUserMenu, changeThemeTo, logout };
|
||||
|
||||
Alpine.global("header", {
|
||||
logout,
|
||||
toggleThemeDropdown,
|
||||
toggleUserMenu,
|
||||
changeThemeTo: (theme: string) => {
|
||||
changeThemeTo(theme);
|
||||
updateThemeIndicators(); // Call themeDropdown function
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user