Stackless-Website/header.js

19 lines
765 B
JavaScript
Raw Permalink Normal View History

2026-06-18 10:22:31 +00:00
// Stackless — shared header behaviour (mobile menu + current page highlight)
(function () {
var btn = document.getElementById('menuBtn');
var nav = document.getElementById('nav');
if (btn && nav) {
btn.addEventListener('click', function () { nav.classList.toggle('is-open'); });
nav.addEventListener('click', function (e) {
if (e.target.tagName === 'A') nav.classList.remove('is-open');
});
}
// Mark current nav item
var here = (location.pathname.split('/').pop() || 'index.html').toLowerCase();
document.querySelectorAll('.nav a').forEach(function (a) {
var href = (a.getAttribute('href') || '').toLowerCase();
if (!href || href.startsWith('#')) return;
if (href === here) a.classList.add('is-current');
});
})();