2022-01-27 17:10:37 +00:00
|
|
|
<script>
|
2022-01-26 13:44:47 +00:00
|
|
|
|
|
|
|
const menuBarHeight = document.querySelector("nav.navbar").clientHeight;
|
2022-01-27 17:10:37 +00:00
|
|
|
const mainTocMenuWidth = document.getElementById('main-toc-menu').clientWidth;
|
2022-01-26 13:44:47 +00:00
|
|
|
const tocItems = document.querySelectorAll(".toc");
|
|
|
|
const navSections = new Array(tocItems.length);
|
|
|
|
|
2022-01-27 17:10:37 +00:00
|
|
|
// Page content
|
|
|
|
/*
|
|
|
|
Focus effect on current section anchor when user scrolls.
|
|
|
|
*/
|
|
|
|
|
2022-01-26 13:44:47 +00:00
|
|
|
tocItems.forEach((el, i) => {
|
|
|
|
let id = el.getAttribute("id").substring(5);
|
|
|
|
navSections[i] = document.getElementById(id);
|
|
|
|
})
|
|
|
|
|
|
|
|
function isVisible(tocIndex) {
|
|
|
|
const current = navSections[tocIndex];
|
|
|
|
const next = tocIndex < tocItems.length - 1 ? navSections[tocIndex + 1]
|
|
|
|
: document.querySelectorAll("section.section").item(1);
|
|
|
|
|
|
|
|
const c = current.getBoundingClientRect();
|
2022-01-31 16:16:02 +00:00
|
|
|
if (next) {
|
|
|
|
const n = next.getBoundingClientRect();
|
|
|
|
const h = (window.innerHeight || document.documentElement.clientHeight);
|
2022-01-26 13:44:47 +00:00
|
|
|
|
2022-01-31 16:16:02 +00:00
|
|
|
return (c.top <= h) && (n.top - menuBarHeight >= 0);
|
|
|
|
} else {
|
|
|
|
const h = (window.innerHeight || document.documentElement.clientHeight);
|
|
|
|
|
|
|
|
return (c.top <= h);
|
|
|
|
}
|
2022-01-26 13:44:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function activateIfVisible() {
|
|
|
|
for (b = true, i = 0; i < tocItems.length; i++) {
|
|
|
|
if (b && isVisible(i)) {
|
|
|
|
tocItems[i].classList.add('is-active');
|
|
|
|
b = false;
|
|
|
|
} else
|
|
|
|
tocItems[i].classList.remove('is-active');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var isTicking = null;
|
|
|
|
window.addEventListener('scroll', () => {
|
|
|
|
if (!isTicking) {
|
|
|
|
window.requestAnimationFrame(() => {
|
|
|
|
activateIfVisible();
|
|
|
|
isTicking = false;
|
|
|
|
});
|
|
|
|
isTicking = true;
|
|
|
|
}
|
|
|
|
}, false);
|
|
|
|
|
2022-01-31 16:16:02 +00:00
|
|
|
</script>
|