const initEnoveHeader = () => { if (typeof window === 'undefined') return; const sidebarEl = document.getElementById('sidebarMenu'); // انتقال سایدبار به بدنه اصلی (body) برای حل محدودیت لایه‌بندی z-index در محیط Next.js if (sidebarEl && sidebarEl.parentElement !== document.body) { document.body.appendChild(sidebarEl); } // ۱. سیستم تغییر تم یکپارچه و هوشمند const syncThemeIcons = (theme) => { const themeButtons = document.querySelectorAll('.theme-toggle-btn'); themeButtons.forEach(btn => { const icon = btn.querySelector('.theme-icon'); if (icon) { icon.className = theme === 'light' ? 'fa-solid fa-sun theme-icon text-warning' : 'fa-solid fa-moon theme-icon text-info'; } }); }; // اعمال تم اولیه const initialTheme = localStorage.getItem('enove-theme') || 'light'; document.documentElement.setAttribute('data-theme', initialTheme); setTimeout(() => syncThemeIcons(initialTheme), 100); // مدیریت کلیک برای تغییر تم (بدون بستن منو) document.addEventListener('click', (e) => { const themeBtn = e.target.closest('.theme-toggle-btn'); if (themeBtn) { e.preventDefault(); e.stopPropagation(); // جلوگیری از نفوذ رویداد const activeTheme = document.documentElement.getAttribute('data-theme'); const nextTheme = activeTheme === 'light' ? 'dark' : 'light'; document.documentElement.setAttribute('data-theme', nextTheme); localStorage.setItem('enove-theme', nextTheme); syncThemeIcons(nextTheme); } }); // ۲. مدیریت کلیک برای زیرمنوهای کشویی سایدبار موبایل (توقیف رویداد) document.addEventListener('click', (e) => { const toggleLink = e.target.closest('.sidebar-dropdown-toggle'); if (toggleLink) { e.preventDefault(); e.stopPropagation(); // جلوگیری از بسته شدن سایدبار هنگام کلیک روی دراپ‌دان‌ها const parentLi = toggleLink.parentElement; const submenu = toggleLink.nextElementSibling; if (parentLi && parentLi.classList.contains('active')) { parentLi.classList.remove('active'); if (submenu) submenu.style.maxHeight = null; } else { // بستن بقیه زیرمنوهای باز سایدبار const activeDropdowns = document.querySelectorAll('.glass-sidebar-dropdown.active'); activeDropdowns.forEach(otherLi => { otherLi.classList.remove('active'); const otherSubmenu = otherLi.querySelector('.sidebar-submenu-list'); if (otherSubmenu) otherSubmenu.style.maxHeight = null; }); if (parentLi) parentLi.classList.add('active'); if (submenu) submenu.style.maxHeight = submenu.scrollHeight + "px"; } } }); // ۳. مدیریت باز کردن سایدبار (منوی همبرگری) const closeSidebar = () => { const activeSidebar = document.getElementById('sidebarMenu'); if (activeSidebar) { activeSidebar.classList.remove('show'); document.body.style.overflow = ''; const backdrop = document.querySelector('.offcanvas-backdrop'); if (backdrop) { backdrop.classList.remove('show'); setTimeout(() => backdrop.remove(), 300); } } }; document.addEventListener('click', (e) => { const hamburgerBtn = e.target.closest('#hamburgerMenuBtn'); if (hamburgerBtn) { e.preventDefault(); e.stopPropagation(); const activeSidebar = document.getElementById('sidebarMenu'); if (activeSidebar) { activeSidebar.classList.add('show'); document.body.style.overflow = 'hidden'; let backdrop = document.querySelector('.offcanvas-backdrop'); if (!backdrop) { backdrop = document.createElement('div'); backdrop.className = 'offcanvas-backdrop fade'; document.body.appendChild(backdrop); setTimeout(() => backdrop.classList.add('show'), 50); backdrop.addEventListener('click', closeSidebar); } } } }); // ۴. مدیریت بستن سایدبار با زدن دکمه ضربدر document.addEventListener('click', (e) => { const closeBtn = e.target.closest('#sidebarMenu .btn-close, [data-bs-dismiss="offcanvas"]'); if (closeBtn) { e.preventDefault(); e.stopPropagation(); closeSidebar(); } }); }; // اجرای امن در محیط رندر کلاینت Next.js if (typeof window !== 'undefined') { if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', () => setTimeout(initEnoveHeader, 200)); } else { setTimeout(initEnoveHeader, 200); } }

وب 3.0: اینترنت جدید در راه است

وب 3.0: اینترنت جدید در راه است
ف

فرهاد آقائی

نویسنده

نویسنده و متخصص تولید محتوای ENOVE

پیشنهاد مطالعه مقالات دیگر

زیباترین رنگ جهان کدام است؟ (لیست محبوب‌ترین رنگ‌های دنیا در سال ۲۰۲۶)

زیباترین رنگ جهان کدام است؟ (لیست محبوب‌ترین رنگ‌های دنیا در سال ۲۰۲۶)

آیا می‌دانید زیباترین رنگ جهان از نظر علمی و روانشناسی کدام است؟ در این مقاله با محبوب‌ترین رنگ دنیا، خاص‌ترین و قشنگ‌ترین رنگ‌ها آشنا شوید و دلیل جذابیت آن‌ها را بدانید. (بروزرسانی ۲۰۲۶)

۲۷ تیر ۱۴۰۵مطالعه ←

نظرات کاربران (0)

دیدگاه خود را بنویسید