/* ─────────────────────────── UI behaviors ────────────────────────────── * Минимальный JS для sidebar collapse, theme toggle, modals. * Подключай в конце body, * или импортируй в фреймворк как обычно. * ─────────────────────────────────────────────────────────────────────── */ (function () { const STORAGE_THEME = 'app-theme'; const STORAGE_SIDEBAR = 'app-sb'; // ── Modal helpers (globals, т.к. вызываются из onclick атрибутов) ──── window.openModal = function (id) { document.getElementById(id)?.classList.add('open'); }; window.closeModal = function (id) { document.getElementById(id)?.classList.remove('open'); }; document.addEventListener('keydown', function (e) { if (e.key === 'Escape') { document.querySelectorAll('.overlay.open').forEach(function (m) { m.classList.remove('open'); }); } }); // ── Theme ─────────────────────────────────────────────────────────── const MOON = ''; const SUN = ''; function applyTheme(dark) { document.body.classList.toggle('dark', dark); document.querySelectorAll('[data-theme-icon]').forEach(function (el) { el.innerHTML = dark ? MOON : SUN; }); } window.toggleTheme = function () { const dark = !document.body.classList.contains('dark'); try { localStorage.setItem(STORAGE_THEME, dark ? 'dark' : 'light'); } catch (e) {} applyTheme(dark); }; try { applyTheme(localStorage.getItem(STORAGE_THEME) === 'dark'); } catch (e) {} // ── Sidebar collapse ──────────────────────────────────────────────── window.toggleSidebar = function () { const sb = document.getElementById('main-sidebar'); const mn = document.querySelector('.main'); if (!sb || !mn) return; const collapsed = sb.classList.toggle('sb-collapsed'); mn.classList.toggle('sb-collapsed', collapsed); try { localStorage.setItem(STORAGE_SIDEBAR, '' + collapsed); } catch (e) {} }; try { if (localStorage.getItem(STORAGE_SIDEBAR) === 'true') { document.getElementById('main-sidebar')?.classList.add('sb-collapsed'); document.querySelector('.main')?.classList.add('sb-collapsed'); } } catch (e) {} })();