-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
99 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,46 @@ | ||
function toggleTocLinkClasses(link, isActive) { | ||
const activeClasses = ['border-l-2', 'border-brand']; | ||
const activeLinkClasses = ['text-primary', '-ml-0.5']; | ||
const activeClasses = ["tab-button__vertical--active"]; | ||
|
||
if (isActive) { | ||
link.classList.add(...activeLinkClasses); | ||
link.classList.remove('text-secondary'); | ||
link.parentElement.classList.add(...activeClasses); | ||
link.classList.add(...activeClasses); | ||
} else { | ||
link.classList.add('text-secondary'); | ||
link.classList.remove(...activeLinkClasses); | ||
link.parentElement.classList.remove(...activeClasses); | ||
link.classList.remove(...activeClasses); | ||
} | ||
} | ||
|
||
window.addEventListener("scroll", () => { | ||
const anchors = document.querySelectorAll("a.header-link"); | ||
const scrollToLinks = document.querySelectorAll("a.scroll-to"); | ||
const navHeight = document.getElementById('header-nav').offsetHeight; | ||
const anchors = document.querySelectorAll("a.header-link"); | ||
const scrollToLinks = document.querySelectorAll("a.scroll-to"); | ||
const navHeight = document.getElementById("header-nav").offsetHeight; | ||
|
||
if (!anchors.length || !scrollToLinks.length) { | ||
return; | ||
} | ||
if (!anchors.length || !scrollToLinks.length) { | ||
return; | ||
} | ||
|
||
let activeSet = false; | ||
let activeSet = false; | ||
|
||
scrollToLinks.forEach(link => toggleTocLinkClasses(link, false)); | ||
scrollToLinks.forEach((link) => toggleTocLinkClasses(link, false)); | ||
|
||
// Convert NodeList to Array and reverse it | ||
const anchorsArray = Array.from(anchors).reverse(); | ||
// Convert NodeList to Array and reverse it | ||
const anchorsArray = Array.from(anchors).reverse(); | ||
|
||
for (const element of anchorsArray) { | ||
const elementTop = element.getBoundingClientRect().top + window.scrollY; | ||
for (const element of anchorsArray) { | ||
const elementTop = element.getBoundingClientRect().top + window.scrollY; | ||
|
||
// window top + header section + extra padding | ||
if (window.scrollY + navHeight + 20 >= elementTop) { | ||
const matchingLink = document.querySelector(`a.scroll-to[href$="${element.getAttribute("href")}"]`); | ||
if (matchingLink) { | ||
toggleTocLinkClasses(matchingLink, true); | ||
activeSet = true; | ||
} | ||
break; | ||
// window top + header section + extra padding | ||
if (window.scrollY + navHeight + 20 >= elementTop) { | ||
const matchingLink = document.querySelector( | ||
`a.scroll-to[href$="${element.getAttribute("href")}"]` | ||
); | ||
if (matchingLink) { | ||
toggleTocLinkClasses(matchingLink, true); | ||
activeSet = true; | ||
} | ||
}; | ||
|
||
if (!activeSet) { | ||
toggleTocLinkClasses(scrollToLinks[0], true); | ||
break; | ||
} | ||
}); | ||
} | ||
|
||
if (!activeSet) { | ||
toggleTocLinkClasses(scrollToLinks[0], true); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters