Skip to content

Commit

Permalink
Fixed error querying current a tag
Browse files Browse the repository at this point in the history
  • Loading branch information
MrSpaar committed Sep 11, 2024
1 parent 90dbc1d commit cdd8991
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions doc/static/script.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
function currentURL() {
return window.location.href.endsWith("/")
function currentA() {
let href = window.location.href.endsWith("/")
? window.location.href
: `${window.location.href}/`;

const links = document.querySelectorAll("ul a");
const targetLink = Array.from(links).find(
(link) => link.href.toLowerCase() === href.toLowerCase(),
);

return targetLink;
}

let loader = document.getElementById("loader");
let input = document.getElementById("show-nav");
let a = document.querySelector(`ul a[href='${currentURL()}']`);
let a = currentA();

function preFetch() {
loader.classList.add("active");
Expand All @@ -24,7 +31,7 @@ function updateWithJSON(json) {

function postFetch() {
a.classList.remove("active");
a = document.querySelector(`ul a[href='${currentURL()}']`);
a = currentA();
a.classList.add("active");

for (let h2 of document.getElementsByTagName("h2")) {
Expand Down

0 comments on commit cdd8991

Please sign in to comment.