diff --git a/static/theme.ts b/static/theme.ts index ecff721..c254744 100644 --- a/static/theme.ts +++ b/static/theme.ts @@ -61,20 +61,15 @@ const initTheme = (): void => { const saved = getSavedTheme(); applyTheme(saved); - const headerBtn = document.getElementById( - "theme-toggle", - ) as HTMLButtonElement | null; - const footerBtn = document.getElementById( - "footer-theme-toggle", - ) as HTMLButtonElement | null; - - if (headerBtn) { - headerBtn.addEventListener("click", cycleTheme); - } - - if (footerBtn) { - footerBtn.addEventListener("click", cycleTheme); - } + // Use event delegation to handle theme toggles + document.addEventListener("click", (e) => { + const target = e.target as HTMLElement; + const btn = target.closest("#theme-toggle, #footer-theme-toggle") as HTMLButtonElement | null; + + if (btn) { + cycleTheme(); + } + }); }; if (document.readyState === "loading") { diff --git a/web/shared/layout/layout.templ b/web/shared/layout/layout.templ index 67bad84..7a7d52a 100644 --- a/web/shared/layout/layout.templ +++ b/web/shared/layout/layout.templ @@ -13,17 +13,17 @@ templ Layout(title string, showHeader bool) { { title } - + - - - - - + + + + + - + }