const header = document.querySelector('[data-header]'); const menuToggle = document.querySelector('.menu-toggle'); const mobileNav = document.querySelector('.mobile-nav'); const allNavLinks = [...document.querySelectorAll('.nav-link')]; const sections = [...document.querySelectorAll('[data-section]')]; const revealItems = [...document.querySelectorAll('[data-reveal]')]; const setHeaderState = () => { header?.classList.toggle('is-scrolled', window.scrollY > 24); }; setHeaderState(); window.addEventListener('scroll', setHeaderState, { passive: true }); menuToggle?.addEventListener('click', () => { const isOpen = menuToggle.classList.toggle('is-open'); mobileNav?.classList.toggle('is-open', isOpen); menuToggle.setAttribute('aria-expanded', String(isOpen)); menuToggle.setAttribute('aria-label', isOpen ? 'Fermer le menu' : 'Ouvrir le menu'); }); allNavLinks.forEach((link) => { link.addEventListener('click', () => { menuToggle?.classList.remove('is-open'); mobileNav?.classList.remove('is-open'); menuToggle?.setAttribute('aria-expanded', 'false'); menuToggle?.setAttribute('aria-label', 'Ouvrir le menu'); }); }); if ('IntersectionObserver' in window) { const revealObserver = new IntersectionObserver((entries, observer) => { entries.forEach((entry) => { if (entry.isIntersecting) { entry.target.classList.add('is-visible'); observer.unobserve(entry.target); } }); }, { threshold: 0.12, rootMargin: '0px 0px -6% 0px' }); revealItems.forEach((item) => revealObserver.observe(item)); const sectionObserver = new IntersectionObserver((entries) => { entries.forEach((entry) => { if (!entry.isIntersecting) return; const id = entry.target.id; if (!id) return; allNavLinks.forEach((link) => link.classList.toggle('is-active', link.getAttribute('href') === `#${id}`)); }); }, { threshold: 0, rootMargin: '-35% 0px -55% 0px' }); sections.forEach((section) => sectionObserver.observe(section)); } else { revealItems.forEach((item) => item.classList.add('is-visible')); } document.querySelectorAll('a[href^="#"]').forEach((anchor) => { anchor.addEventListener('click', (event) => { const target = document.querySelector(anchor.getAttribute('href')); if (!target) return; event.preventDefault(); target.scrollIntoView({ behavior: window.matchMedia('(prefers-reduced-motion: reduce)').matches ? 'auto' : 'smooth' }); }); }); document.querySelectorAll('details').forEach((detail) => { detail.addEventListener('toggle', () => { if (!detail.open) return; document.querySelectorAll('details[open]').forEach((other) => { if (other !== detail) other.removeAttribute('open'); }); }); }); const year = document.querySelector('[data-year]'); if (year) year.textContent = String(new Date().getFullYear());