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

Fix python micro-site table of content bugs #18664

Merged
merged 4 commits into from
Jul 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ footer.mdl-mini-footer {
border-top: 1px solid $grey-color-light;
padding: $spacing-unit 0;
background-color: #424242;
position: relative;
z-index: 10;
.footer-category-title {
color: $color-mxnet;
}
Expand All @@ -136,6 +138,8 @@ footer.mdl-mini-footer {
background-color: #424242;
padding-top: 40px;
padding-bottom: 10px;
position: relative;
z-index: 10;
}

.footer-heading {
Expand Down