18 lines
765 B
JavaScript
18 lines
765 B
JavaScript
// 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');
|
|
});
|
|
})();
|