From 4b7a12fafad0c2c059515e0a0a73e588d83ccb09 Mon Sep 17 00:00:00 2001 From: interlope Date: Wed, 26 Aug 2026 22:33:40 +0200 Subject: [PATCH] fix Issue #1 mobile ToC highlight --- js/blowfish.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/js/blowfish.js b/js/blowfish.js index 51f872c..18902d6 100644 --- a/js/blowfish.js +++ b/js/blowfish.js @@ -262,12 +262,16 @@ var top = h.getBoundingClientRect().top + scrollY; if (top <= threshold) active = h; }); - var links = tocNav.querySelectorAll('.toc-link'); - Array.prototype.forEach.call(links, function (a) { a.classList.remove('active'); }); - if (active) { - var link = tocNav.querySelector('a[href="#' + active.id + '"]'); - if (link) link.classList.add('active'); - } + // Document-wide, not scoped to tocNav: the mobile drawer holds a clone + // of this list and needs the same highlight. Match on .toc-link so the + // heading "#" anchors, which share the href, aren't marked active; and + // compare the href rather than building a selector from the id, which + // would throw on a hand-written id containing a quote. + var links = document.querySelectorAll('.toc-link'); + var href = active ? '#' + active.id : null; + Array.prototype.forEach.call(links, function (a) { + a.classList.toggle('active', a.getAttribute('href') === href); + }); } window.addEventListener('scroll', updateActive, { passive: true });