/* * app.js - the only JavaScript of the panel (no inline scripts: the Content-Security-Policy forbids them). * It never talks to the network. It does five small things: * 1. theme switch (Dark / Light / System) remembered in this browser (localStorage) * 2. collapsible sidebar rail, remembered in this browser * 3. mobile menu toggle * 4.
asks before submitting (every destructive action) * 5. a live clock in the header */ (function () { var root = document.documentElement; function store(k, v) { try { if (v === undefined) { return localStorage.getItem(k); } localStorage.setItem(k, v); } catch (e) { return null; } } // 1. theme --------------------------------------------------------------- function applyTheme(t) { if (['dark', 'light', 'system'].indexOf(t) < 0) { t = 'dark'; } root.setAttribute('data-theme', t); document.querySelectorAll('[data-theme-set]').forEach(function (b) { b.classList.toggle('on', b.getAttribute('data-theme-set') === t); }); } applyTheme(store('salam-theme') || 'dark'); // 2. sidebar rail --------------------------------------------------------- if (store('salam-rail') === '1') { root.classList.add('rail'); } document.addEventListener('click', function (ev) { var t = ev.target.closest ? ev.target.closest('button') : null; if (!t) { return; } if (t.hasAttribute('data-theme-set')) { var v = t.getAttribute('data-theme-set'); store('salam-theme', v); applyTheme(v); } if (t.id === 'railtoggle') { root.classList.toggle('rail'); store('salam-rail', root.classList.contains('rail') ? '1' : '0'); } if (t.id === 'navtoggle') { document.getElementById('sidebar').classList.toggle('open'); } // 3. mobile }); // 4. confirmation dialogs --------------------------------------------------- document.addEventListener('submit', function (ev) { var msg = ev.target && ev.target.getAttribute && ev.target.getAttribute('data-confirm'); if (msg && !window.confirm(msg)) { ev.preventDefault(); } }); // 5. clock ------------------------------------------------------------------- var clock = document.getElementById('clock'); function tick() { if (clock) { clock.textContent = new Date().toLocaleString([], { weekday: 'short', hour: '2-digit', minute: '2-digit', second: '2-digit' }); } } tick(); setInterval(tick, 1000); })();