Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
more fix to the toc
Browse files Browse the repository at this point in the history
  • Loading branch information
ys2843 committed Jul 9, 2020
1 parent a6ade51 commit 6e72aa8
Show file tree
Hide file tree
Showing 5 changed files with 251 additions and 232 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

25 changes: 23 additions & 2 deletions docs/python_docs/themes/mx-theme/src/js/scrollspy.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,21 @@ export default class ScrollSpy {
}, 1);
});

this.scrollElement.addEventListener("click", (e) => {
const target = e.target;
if (target.tagName !== "A") return;
window.onclickToc = true;
for (let i = 0, max = this.nav.length; i < max; i++) {
const navElement = this.nav[i];
if (navElement.href === target.href) {
navElement.classList.add(this.className);
navElement.classList.add('mdl-color-text--primary');
} else {
navElement.classList.remove(this.className);
navElement.classList.remove('mdl-color-text--primary');
}
}
});
}

getContents(contentSelector) {
Expand Down Expand Up @@ -72,15 +87,21 @@ export default class ScrollSpy {

isView(element) {
const scrollTop = this.scrollElement.scrollTop;
const calcBotom = scrollTop + this.offsetTop;
const subHeaderRect = document.querySelector(".mdl-layout__header-row").getBoundingClientRect();
const headerHeight = subHeaderRect.top + subHeaderRect.height;
const scrollBottom = scrollTop + window.innerHeight - headerHeight;
const rect = element.getBoundingClientRect();
const elementTop = rect.top + scrollTop;
const elementBottom = elementTop + element.offsetHeight;

return elementTop <= calcBotom + this.offsetTop && elementBottom > scrollTop + this.offsetTop;
return elementTop < scrollBottom - 30 && elementBottom > scrollTop + headerHeight + 30;
}

toggleNavClass(elements) {
if (window.onclickToc) {
window.onclickToc = false;
return;
}
let maxDepth = 0;
let maxDepthElement = $();

Expand Down

0 comments on commit 6e72aa8

Please sign in to comment.