diff --git a/weed/admin/static/js/theme.js b/weed/admin/static/js/theme.js deleted file mode 100644 index 79b5ce21f7..0000000000 --- a/weed/admin/static/js/theme.js +++ /dev/null @@ -1,43 +0,0 @@ -// Applies the saved color theme (auto, light or dark) before the page paints. -(function () { - var storageKey = 'admin-theme'; - var choices = ['auto', 'light', 'dark']; - var media = window.matchMedia ? window.matchMedia('(prefers-color-scheme: dark)') : null; - var root = document.documentElement; - - function savedChoice() { - try { - var value = localStorage.getItem(storageKey); - return choices.indexOf(value) >= 0 ? value : 'auto'; - } catch (e) { - return 'auto'; - } - } - - function apply(choice) { - var dark = choice === 'dark' || (choice === 'auto' && media && media.matches); - root.setAttribute('data-bs-theme', dark ? 'dark' : 'light'); - root.setAttribute('data-theme-choice', choice); - } - - var current = savedChoice(); - apply(current); - - if (media && media.addEventListener) { - media.addEventListener('change', function () { - apply(current); - }); - } - - document.addEventListener('click', function (event) { - var toggle = event.target.closest && event.target.closest('[data-theme-toggle]'); - if (!toggle) { - return; - } - current = choices[(choices.indexOf(current) + 1) % choices.length]; - try { - localStorage.setItem(storageKey, current); - } catch (e) {} - apply(current); - }); -})(); diff --git a/weed/admin/static_gz/js/theme.js.gz b/weed/admin/static_gz/js/theme.js.gz deleted file mode 100644 index 4b18d0dc25..0000000000 Binary files a/weed/admin/static_gz/js/theme.js.gz and /dev/null differ diff --git a/weed/admin/view/layout/layout.templ b/weed/admin/view/layout/layout.templ index 11c766bd3d..ebf437d3a7 100644 --- a/weed/admin/view/layout/layout.templ +++ b/weed/admin/view/layout/layout.templ @@ -12,6 +12,56 @@ script setBasePath(prefix string) { window.__BASE_PATH__ = prefix; } +// themeScript applies the saved color theme (auto, light or dark) inline, so +// the root is themed before any external script or stylesheet is fetched. +templ themeScript() { + +} + templ Layout(view ViewContext, content templ.Component) { {{ username := view.Username @@ -55,7 +105,7 @@ templ Layout(view ViewContext, content templ.Component) { - + @themeScript() @@ -404,7 +454,7 @@ templ LoginForm(title string, errorMessage string, csrfToken string) {
Please sign in to continue
Please sign in to continue