v3.0.0.2
FlatlyPage
- const MINIMAL_KEY = 'admin-minimalism';
-
- const isMinimalOn = () => document.documentElement.getAttribute('data-minimal') === 'on';
-
- const setMinimal = (on) => {
- if (on) {
- document.documentElement.setAttribute('data-minimal', 'on');
- } else {
- document.documentElement.removeAttribute('data-minimal');
- }
- try {
- localStorage.setItem(MINIMAL_KEY, on ? 'on' : 'off');
- } catch (error) {}
- };
-
- try {
- if (localStorage.getItem(MINIMAL_KEY) === 'on') {
- document.documentElement.setAttribute('data-minimal', 'on');
- }
- } catch (error) {}
-
- const GLASS_KEY = 'admin-glass-effect';
-
- const isGlassOn = () => document.documentElement.getAttribute('data-glass') !== 'off';
-
- const setGlass = (on) => {
- if (on) {
- document.documentElement.removeAttribute('data-glass');
- } else {
- document.documentElement.setAttribute('data-glass', 'off');
- }
- try {
- localStorage.setItem(GLASS_KEY, on ? 'on' : 'off');
- } catch (error) {}
- };
-
- try {
- if (localStorage.getItem(GLASS_KEY) === 'off') {
- document.documentElement.setAttribute('data-glass', 'off');
- }
- } catch (error) {}
-
- const THEME_KEY = 'admin-data-theme';
-
- const applyTheme = (theme) => {
- document.documentElement.setAttribute('data-theme', theme);
- localStorage.setItem(THEME_KEY, theme);
- };
-
- const savedTheme = localStorage.getItem(THEME_KEY);
- const systemTheme = window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark';
- const currentTheme = savedTheme || systemTheme;
-
- applyTheme(currentTheme);
-
- const toggleTheme = () => {
- const activeTheme = document.documentElement.getAttribute('data-theme');
- const newTheme = activeTheme === 'dark' ? 'light' : 'dark';
- applyTheme(newTheme);
- };
-
- document.addEventListener('DOMContentLoaded', () => {
- const sidebar = document.querySelector('.sidebar');
- const nav = document.querySelector('.sidebar-nav');
- if (!sidebar || !nav) return;
-
- const MAX_VISIBLE = 4;
- const links = Array.from(nav.querySelectorAll('a.nav-item'));
-
- const avatar = sidebar.querySelector('.user-avatar');
- const actions = document.querySelector('.header-actions');
- if (avatar && actions) {
- const account = document.createElement('a');
- account.href = (window.FLATLY_BASE || '') + '/admin/account';
- account.className = 'mobile-avatar';
- account.textContent = avatar.textContent.trim();
- actions.appendChild(account);
- }
-
- if (links.length <= MAX_VISIBLE) return;
-
- const visibleCount = MAX_VISIBLE - 1;
- const active = links.findIndex((a) => a.classList.contains('active'));
- const visible = new Set(links.slice(0, visibleCount));
- if (active >= visibleCount) {
- visible.delete(links[visibleCount - 1]);
- visible.add(links[active]);
- }
- const overflow = links.filter((a) => !visible.has(a));
- overflow.forEach((a) => a.classList.add('nav-overflow-item'));
-
- const moreBtn = document.createElement('button');
- moreBtn.type = 'button';
- moreBtn.className = 'nav-more-btn';
- moreBtn.innerHTML = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><circle cx="5" cy="12" r="1.5"/><circle cx="12" cy="12" r="1.5"/><circle cx="19" cy="12" r="1.5"/></svg><span>More</span>';
-
- const backdrop = document.createElement('div');
- backdrop.className = 'nav-sheet-backdrop';
- const sheet = document.createElement('div');
- sheet.className = 'nav-sheet';
- const handle = document.createElement('div');
- handle.className = 'nav-sheet-handle';
- sheet.appendChild(handle);
-
- overflow.forEach((a) => {
- const item = a.cloneNode(true);
- item.className = 'nav-sheet-link' + (a.classList.contains('active') ? ' active' : '');
- sheet.appendChild(item);
- });
-
- nav.appendChild(moreBtn);
- document.body.appendChild(backdrop);
- document.body.appendChild(sheet);
-
- const setOpen = (open) => {
- backdrop.classList.toggle('open', open);
- sheet.classList.toggle('open', open);
- moreBtn.classList.toggle('open', open);
- };
-
- moreBtn.addEventListener('click', () => setOpen(!sheet.classList.contains('open')));
- backdrop.addEventListener('click', () => setOpen(false));
- });
-
- (() => {
- const desktop = window.matchMedia('(min-width: 769px)');
- let app = null;
-
- const reset = (el) => {
- if (el && (el.scrollTop !== 0 || el.scrollLeft !== 0)) {
- el.scrollTop = 0;
- el.scrollLeft = 0;
- }
- };
-
- document.addEventListener('scroll', (e) => {
- if (!desktop.matches) return;
- const target = e.target;
- if (!app) app = document.querySelector('.app');
- if (target === document || target === document.documentElement || target === document.body || target === app || (target.classList && target.classList.contains('sidebar'))) {
- reset(document.scrollingElement);
- reset(document.body);
- reset(app);
- reset(document.querySelector('.sidebar'));
- }
- }, { capture: true, passive: true });
- })();
-