Skip to content

Commit a882bd6

Browse files
TMHSDigitalclaude
andcommitted
fix(site): scrollspy marks Examples and Showcase while their sections are in view
The Examples and Showcase nav links point at gallery/#k=..., so the spy skipped them and "Install" stayed highlighted through the whole #showcase section. Map #k=<id> links onto the same-id landing sections and sort the spy in document order. Verified in Chrome: each of the seven sections now marks its own nav link with aria-current. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent fc087a8 commit a882bd6

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

‎scripts/site/template.html.j2‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -616,13 +616,22 @@
616616
})();
617617
618618
// Scrollspy: mark the nav link of the section currently under the header.
619-
// Only the in-page anchors (#install, #new, ...) take part; the Examples
620-
// and Showcase links go to the gallery and are never marked.
619+
// In-page anchors (#install, #new, ...) map to their section. The
620+
// Examples and Showcase links go to the gallery (gallery/#k=examples),
621+
// but this page also has #examples and #showcase sections, so they map
622+
// by the filter key; otherwise scrolling through those sections left the
623+
// previous link (Install) marked.
621624
(function () {
622-
var links = Array.prototype.slice.call(document.querySelectorAll('.site-nav a[href^="#"]'));
625+
var links = Array.prototype.slice.call(document.querySelectorAll('.site-nav a'));
623626
var spy = links.map(function (a) {
624-
return { a: a, el: document.getElementById(a.getAttribute('href').slice(1)) };
627+
var href = a.getAttribute('href') || '';
628+
var m = href.charAt(0) === '#' ? [null, href.slice(1)] : href.match(/#k=([\w-]+)$/);
629+
return { a: a, el: m ? document.getElementById(m[1]) : null };
625630
}).filter(function (s) { return s.el; });
631+
// document order, so "the last section above the threshold" is right
632+
spy.sort(function (x, y) {
633+
return x.el.compareDocumentPosition(y.el) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1;
634+
});
626635
if (!spy.length) return;
627636
var queued = false;
628637
function update() {

0 commit comments

Comments
 (0)