Skip to content

Commit

Permalink
Merge pull request #463 from ndw/iss-451
Browse files Browse the repository at this point in the history
Try a little harder to scroll the ptoc into view
  • Loading branch information
ndw authored Jan 30, 2024
2 parents b0ceb13 + faa26d5 commit 67414a4
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/main/web/js/persistent-toc.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,26 @@
+ window.location.hash);
}

let path = window.location.pathname.substring(1) + window.location.hash;
// Try path#hash
let path = url.substring(1) + hash;
let target = document.querySelector("nav.toc div a[rel-path='"+path+"']");
if (target) {
target.scrollIntoView();
} else {
console.log(`ToC scroll, no match: ${path}`);
// Try #hash
target = document.querySelector("nav.toc div a[rel-path='"+hash+"']");
if (target) {
target.scrollIntoView();
} else {
// Try path
target = document.querySelector("nav.toc div a[rel-path='"+url.substring(1)+"']");
if (target) {
target.scrollIntoView();
} else {
// ???
console.log(`ToC scroll, no match: ${path}`);
}
}
}

if (!searchListener) {
Expand Down

0 comments on commit 67414a4

Please sign in to comment.