// Shared docs-site behaviors. Loaded at the bottom of every page. // // Sidebar active-pill sync: the .active class on sidebar links is // baked into each HTML file as a baseline (page-level link only), // which means clicking an in-page anchor link (e.g. "Discount codes" // → index.html#discounts) leaves the pill stuck on whatever the // statically-marked page link was. This script keeps the active // state in sync with the current URL hash so the pill follows // what the user clicked. (function () { var sidebarLinks = Array.prototype.slice.call( document.querySelectorAll('aside.side a') ); if (!sidebarLinks.length) return; var currentFile = (location.pathname.split('/').pop() || 'index.html'); function findActive(hash) { var desired = hash ? (currentFile + hash) : currentFile; var match = null; sidebarLinks.forEach(function (a) { if (a.getAttribute('href') === desired) match = a; }); if (match) return match; // Fallback: bare current-file link when no hash matches sidebarLinks.forEach(function (a) { if (a.getAttribute('href') === currentFile) match = a; }); return match; } function setActive(link) { if (!link) return; sidebarLinks.forEach(function (a) { a.classList.remove('active'); }); link.classList.add('active'); } setActive(findActive(location.hash)); window.addEventListener('hashchange', function () { setActive(findActive(location.hash)); }); sidebarLinks.forEach(function (a) { a.addEventListener('click', function () { setActive(a); }); }); })();