/* smod js/theme.js — ported verbatim from the 1.0 dashboard_core.js:605-651 (entry 010) * as its own file because smod's login.html loads no dashboard.js and the module must run * in on EVERY page (prevents a wrong-theme first paint). Theme round 2026-08-06. */ /* ============================================================================ * THEME TOGGLE (light/dark) — entry 010, light-theme feature * ---------------------------------------------------------------------------- * Adds/removes the "light-theme" class on the root element. CSS owns all * colour (see styles.css :root.light-theme block); this only flips the class * and remembers the choice. Default = dark (no class). Exposed as a global so * the inline header onclick can reach it, matching this codebase's convention * of page-local inline handlers (e.g. toggleSidebar). * * localStorage is used for persistence. This is real on-device firmware, where * localStorage is available; the embedded browser retains it across reloads. * ==========================================================================*/ (function () { 'use strict'; var KEY = 'aw-theme'; // stored value: 'light' or 'dark' var CLASS = 'light-theme'; var root = document.documentElement; function apply(theme) { if (theme === 'light') { root.classList.add(CLASS); } else { root.classList.remove(CLASS); } } // Apply the saved choice as early as possible to avoid a flash of the // wrong theme. dashboard_core.js is loaded in , so this runs before // the body paints on most pages. try { var saved = window.localStorage ? localStorage.getItem(KEY) : null; apply(saved === 'light' ? 'light' : 'dark'); // default dark } catch (e) { apply('dark'); } // Global handler for the header toggle button's onclick. window.toggleTheme = function () { var nowLight = root.classList.toggle(CLASS); try { if (window.localStorage) { localStorage.setItem(KEY, nowLight ? 'light' : 'dark'); } } catch (e) { /* storage unavailable; theme still applies for this session */ } }; })();