/* ========================================================= Smartex — Header helper (sticky + auto-hide + anchor offset) v6 (instant hide on any downward scroll; no thresholds) ========================================================= */ (function () { // Find the navbar across templates var bar = document.querySelector('.navbar.navbar-inverse.navbar-static-top') || document.querySelector('.navbar.navbar-inverse') || document.querySelector('header .navbar') || document.querySelector('.site-header .navbar'); if (!bar) { console && console.warn && console.warn('[Smartex Header] Navbar not found on this page.'); return; } console && console.log && console.log('[Smartex Header] Hooked navbar:', bar.className); /* Keep CSS var --header-h in sync with real header height */ function syncHeaderH() { document.documentElement.style.setProperty('--header-h', bar.getBoundingClientRect().height + 'px'); } window.addEventListener('load', syncHeaderH); window.addEventListener('resize', syncHeaderH); if (document.fonts && document.fonts.ready) { document.fonts.ready.then(syncHeaderH).catch(function(){}); } syncHeaderH(); /* Instant hide/show logic */ var lastY = window.pageYOffset || document.documentElement.scrollTop || 0; function applyState(y, dy) { var menuOpen = document.body.classList.contains('nav-open'); if (menuOpen) { bar.classList.remove('navbar--hidden'); return; } if (dy > 0) { // any down movement -> hide bar.classList.add('navbar--hidden'); } else if (dy < 0) { // any up movement -> show bar.classList.remove('navbar--hidden'); } } function onScroll() { var y = window.pageYOffset || document.documentElement.scrollTop || 0; var dy = y - lastY; if (dy !== 0) applyState(y, dy); lastY = y; } // Scroll window.addEventListener('scroll', onScroll, { passive: true }); // Wheel: react even on pages with tiny scroll changes window.addEventListener('wheel', function (e) { if (e.deltaY > 0) { document.body.classList.contains('nav-open') || bar.classList.add('navbar--hidden'); } else if (e.deltaY < 0) { bar.classList.remove('navbar--hidden'); } }, { passive: true }); // Touch (mobile) var touchStartY = 0; window.addEventListener('touchstart', function (e) { if (e.touches && e.touches.length) touchStartY = e.touches[0].clientY; }, { passive: true }); window.addEventListener('touchmove', function (e) { if (!(e.touches && e.touches.length)) return; var dy = touchStartY - e.touches[0].clientY; // >0 means moving finger up => page scrolls down if (dy > 0) { document.body.classList.contains('nav-open') || bar.classList.add('navbar--hidden'); } else if (dy < 0) { bar.classList.remove('navbar--hidden'); } }, { passive: true }); /* Keep bar visible while mobile nav is open & track open state */ var nav = document.getElementById('navbar'); function updateOpenState() { var open = nav && (nav.classList.contains('in') || nav.classList.contains('show')); document.body.classList.toggle('nav-open', !!open); if (open) bar.classList.remove('navbar--hidden'); syncHeaderH(); } if (nav) { nav.addEventListener('shown.bs.collapse', updateOpenState); nav.addEventListener('hidden.bs.collapse', updateOpenState); var mo = new MutationObserver(updateOpenState); mo.observe(nav, { attributes: true, attributeFilter: ['class', 'style', 'aria-expanded'] }); } })(); (function () { var btn = document.querySelector('.navbar-toggle'); var nav = document.getElementById('navbar'); if (!btn || !nav) return; var ham = btn.querySelector('.icon-hamburger'); var close = btn.querySelector('.icon-close'); function setIcons(open) { if (!ham || !close) return; ham.style.display = open ? 'none' : 'inline'; close.style.display = open ? 'inline': 'none'; btn.setAttribute('aria-expanded', open ? 'true' : 'false'); } // initial state setIcons(false); // Prefer Bootstrap 3 collapse events if available if (typeof jQuery !== 'undefined' && typeof jQuery.fn.collapse !== 'undefined') { jQuery('#navbar').on('show.bs.collapse', function () { setIcons(true); }); jQuery('#navbar').on('hide.bs.collapse', function () { setIcons(false); }); } else { // Fallback: infer state on click btn.addEventListener('click', function () { var isOpen = nav.classList.contains('in') || nav.style.display === 'block'; setIcons(!isOpen); }); } })();