Spaces:
Running
Running
| document.addEventListener('DOMContentLoaded', () => { | |
| // Smooth scroll for any anchor links | |
| document.querySelectorAll('a[href^="#"]').forEach(anchor => { | |
| anchor.addEventListener('click', function (e) { | |
| e.preventDefault(); | |
| document.querySelector(this.getAttribute('href')).scrollIntoView({ | |
| behavior: 'smooth' | |
| // Smooth scrolling for navigation links | |
| document.querySelectorAll('nav a').forEach(anchor => { | |
| anchor.addEventListener('click', function(e) { | |
| e.preventDefault(); | |
| const targetId = this.getAttribute('href'); | |
| if (targetId.startsWith('#')) { | |
| const targetElement = document.querySelector(targetId); | |
| if (targetElement) { | |
| targetElement.scrollIntoView({ | |
| behavior: 'smooth' | |
| }); | |
| } | |
| } | |
| }); | |
| }); | |
| }); | |
| }); | |
| }); | |
| // Mobile menu toggle | |
| const mobileMenuBtn = document.querySelector('.mobile-menu-btn'); | |
| const nav = document.querySelector('nav'); | |
| if (mobileMenuBtn && nav) { | |
| mobileMenuBtn.addEventListener('click', () => { | |
| nav.classList.toggle('show'); | |
| const icon = mobileMenuBtn.querySelector('i'); | |
| if (nav.classList.contains('show')) { | |
| feather.icons.x.toSvg().then(svg => icon.outerHTML = svg); | |
| } else { | |
| feather.icons.menu.toSvg().then(svg => icon.outerHTML = svg); | |
| } | |
| }); | |
| } | |
| // Handle feather icons replacement after dynamic content changes | |
| const observer = new MutationObserver(() => { | |
| feather.replace(); | |
| }); | |
| observer.observe(document.body, { | |
| childList: true, | |
| subtree: true | |
| }); | |
| // Adjust layout for mobile | |
| function handleResize() { | |
| if (window.innerWidth > 1024 && nav) { | |
| nav.classList.remove('show'); | |
| const icon = mobileMenuBtn?.querySelector('i'); | |
| if (icon) { | |
| feather.icons.menu.toSvg().then(svg => icon.outerHTML = svg); | |
| } | |
| } | |
| } | |
| window.addEventListener('resize', handleResize); | |
| handleResize(); | |
| // Search functionality | |
| document.addEventListener('click', (e) => { | |
| // Handle search toggle | |
| if (e.target.closest('.search-toggle') || e.target.closest('.search-toggle svg')) { | |
| e.preventDefault(); | |
| document.querySelector('.search-overlay').classList.remove('hidden'); | |
| document.body.style.overflow = 'hidden'; | |
| document.querySelector('.search-overlay input').focus(); | |
| } | |
| // Handle search close | |
| if (e.target.closest('.search-close') || e.target.closest('.search-close svg')) { | |
| e.preventDefault(); | |
| document.querySelector('.search-overlay').classList.add('hidden'); | |
| document.body.style.overflow = ''; | |
| } | |
| // Handle auth toggle | |
| if (e.target.closest('.auth-toggle') || e.target.closest('.auth-toggle svg')) { | |
| e.preventDefault(); | |
| document.querySelector('.auth-overlay').classList.remove('hidden'); | |
| document.body.style.overflow = 'hidden'; | |
| document.querySelector('#email')?.focus(); | |
| } | |
| // Handle auth close | |
| if (e.target.closest('.auth-close') || e.target.closest('.auth-close svg')) { | |
| e.preventDefault(); | |
| document.querySelector('.auth-overlay').classList.add('hidden'); | |
| document.body.style.overflow = ''; | |
| } | |
| }); | |
| // Close overlays when clicking outside | |
| document.addEventListener('click', (e) => { | |
| const searchOverlay = document.querySelector('.search-overlay'); | |
| const authOverlay = document.querySelector('.auth-overlay'); | |
| if (searchOverlay && !searchOverlay.classList.contains('hidden')) { | |
| if (!e.target.closest('.search-overlay > div') && !e.target.closest('.search-toggle')) { | |
| searchOverlay.classList.add('hidden'); | |
| document.body.style.overflow = ''; | |
| } | |
| } | |
| if (authOverlay && !authOverlay.classList.contains('hidden')) { | |
| if (!e.target.closest('.auth-overlay > div') && !e.target.closest('.auth-toggle')) { | |
| authOverlay.classList.add('hidden'); | |
| document.body.style.overflow = ''; | |
| } | |
| } | |
| }); | |
| // Handle escape key to close overlays | |
| document.addEventListener('keydown', (e) => { | |
| if (e.key === 'Escape') { | |
| const searchOverlay = document.querySelector('.search-overlay'); | |
| const authOverlay = document.querySelector('.auth-overlay'); | |
| if (searchOverlay && !searchOverlay.classList.contains('hidden')) { | |
| searchOverlay.classList.add('hidden'); | |
| document.body.style.overflow = ''; | |
| } | |
| if (authOverlay && !authOverlay.classList.contains('hidden')) { | |
| authOverlay.classList.add('hidden'); | |
| document.body.style.overflow = ''; | |
| } | |
| } | |
| }); | |
| }); | |