stylescape
Version:
Stylescape is a visual identity framework developed by Scape Agency.
28 lines • 930 B
JavaScript
export class ActiveLinkHighlighter {
constructor(activeClass = "active") {
this.activeClass = activeClass;
this.highlightAllLinks();
}
normalizeUrl(url) {
const a = document.createElement("a");
a.href = url;
return a.pathname.replace(/\/+$/, "");
}
highlightAllLinks() {
const currentPath = this.normalizeUrl(window.location.href);
const links = document.querySelectorAll("a");
links.forEach((link) => {
if (link.closest(".ribbon__title")) {
return;
}
if (!link.hasAttribute("href") || !link.getAttribute("href")) {
return;
}
const linkPath = this.normalizeUrl(link.href);
if (linkPath === currentPath) {
link.classList.add(this.activeClass);
}
});
}
}
//# sourceMappingURL=ActiveLinkHighlighter.js.map