Skip to content

Commit 0242d6e

Browse files
Layout: WIP. Auto-scrolling to current location works, but only first matching title
1 parent f5abced commit 0242d6e

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

assets/js/sidebar-v2.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,21 @@ document.addEventListener('click', (e) => {
3737
}
3838
});
3939

40+
document.addEventListener('DOMContentLoaded', () => {
41+
// need to correlate path to page rather than h1, as headers can be repeated (ie. nested1c/nested2-1 is seen the same as nested1b/nested2-1)
42+
const currentPage = document.querySelector("h1").textContent;
43+
console.log("This is a test log "+currentPage);
44+
45+
const match = Array.from(document.querySelectorAll(".sidebar__link"))
46+
.find(el => el.textContent.includes(currentPage));
47+
48+
if (match){
49+
console.log("Matching pair? "+match)
50+
match.scrollIntoView({ behavior: "instant", block: "nearest" });
51+
}
52+
53+
});
54+
4055
const debounce = (callback, wait) => {
4156
let timeoutId = null;
4257
return (...args) => {
@@ -51,7 +66,7 @@ window.addEventListener(
5166
'resize',
5267
debounce(() => {
5368
const sidebar = document.getElementById('sidebar-v2');
54-
69+
console.log("This is a test log")
5570
if (
5671
window.innerWidth > 88 * 16 &&
5772
sidebar.classList.contains('sidebar__mobile-open')
@@ -60,3 +75,5 @@ window.addEventListener(
6075
}
6176
}, 200)
6277
);
78+
79+

0 commit comments

Comments
 (0)