/* Loads header/footer partials into any element with data-include="...", * then fires a `partialsready` event on document once all are in place. * Keeps nav/footer markup in one place across all pages without a build step. */ (function () { var targets = document.querySelectorAll('[data-include]'); var pending = targets.length; if (pending === 0) { document.dispatchEvent(new Event('partialsready')); return; } targets.forEach(function (el) { fetch(el.getAttribute('data-include')) .then(function (res) { return res.text(); }) .then(function (html) { el.outerHTML = html; }) .catch(function (err) { console.error('Failed to load partial', el.getAttribute('data-include'), err); }) .finally(function () { pending -= 1; if (pending === 0) { document.dispatchEvent(new Event('partialsready')); } }); }); })(); document.addEventListener('partialsready', function () { // Highlight the active nav link based on the current page. var current = document.body.getAttribute('data-page'); if (current) { var link = document.querySelector('.site-header [data-nav="' + current + '"]'); if (link) link.classList.add('active'); } var yearEl = document.getElementById('copyYear'); if (yearEl) yearEl.textContent = new Date().getFullYear(); var logoutLink = document.getElementById('logoutLink'); if (logoutLink) { logoutLink.addEventListener('click', function (e) { e.preventDefault(); if (window.MilitiaAuth) window.MilitiaAuth.logout(); window.location.href = '/index.html'; }); } if (window.MilitiaAuth) { window.MilitiaAuth.reflectAuthUi(); } if (window.MilitiaCart) { window.MilitiaCart.updateBadge(); } });