/** * Ophiro Navigation * Handles mobile menu toggle and header scroll effects */ ( function() { 'use strict'; const header = document.getElementById( 'o-site-header' ); const toggle = document.getElementById( 'o-menu-toggle' ); const nav = document.getElementById( 'o-main-nav' ); if ( ! header || ! toggle || ! nav ) return; // Mobile menu toggle toggle.addEventListener( 'click', function() { const expanded = this.getAttribute( 'aria-expanded' ) === 'true'; this.setAttribute( 'aria-expanded', ! expanded ); this.classList.toggle( 'is-active' ); nav.classList.toggle( 'is-mobile-open' ); document.body.style.overflow = expanded ? '' : 'hidden'; } ); // Close mobile menu on link click nav.querySelectorAll( '.o-nav__link' ).forEach( function( link ) { link.addEventListener( 'click', function() { toggle.classList.remove( 'is-active' ); nav.classList.remove( 'is-mobile-open' ); toggle.setAttribute( 'aria-expanded', 'false' ); document.body.style.overflow = ''; } ); } ); // Header scroll effect let lastScroll = 0; const scrollThreshold = 80; function handleScroll() { const currentScroll = window.pageYOffset; if ( currentScroll > scrollThreshold ) { header.classList.add( 'is-scrolled' ); } else { header.classList.remove( 'is-scrolled' ); } lastScroll = currentScroll; } // Throttled scroll handler let ticking = false; window.addEventListener( 'scroll', function() { if ( ! ticking ) { window.requestAnimationFrame( function() { handleScroll(); ticking = false; } ); ticking = true; } } ); // Initial check handleScroll(); // Active nav link based on current URL const currentPath = window.location.pathname; nav.querySelectorAll( '.o-nav__link' ).forEach( function( link ) { if ( link.getAttribute( 'href' ) === currentPath ) { link.classList.add( 'is-active' ); } } ); } )();