Skip to content

Commit

Permalink
fix: multiple listeners on document state change
Browse files Browse the repository at this point in the history
  • Loading branch information
beryxz committed Jun 18, 2023
1 parent 6dd5d91 commit f47a1a3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions _includes/externals/anchor_links.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
}
};

document.onreadystatechange = function () {
if (this.readyState === "complete") {
document.addEventListener('readystatechange', function (evt) {
if (evt.target.readyState === "complete") {
let contentBlocks = document.getElementsByClassName("content");
for (const contentBlock of contentBlocks) {
for (var level = 1; level <= 3; level++) {
linkifyAnchors(level, contentBlock);
}
}
}
};
}, false);
</script>
6 changes: 3 additions & 3 deletions _includes/externals/toc.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
}
}

document.onreadystatechange = function() {
if (this.readyState === "complete") {
document.addEventListener('readystatechange', function (evt) {
if (evt.target.readyState === "complete") {
generateToc();

let tocNavbar = document.querySelector('#toc nav');
Expand All @@ -80,5 +80,5 @@
window.addEventListener("scroll", () => { tocUpdateStatus(tocNavbar, tocElements, tocPointedElements); });
tocUpdateStatus(tocNavbar, tocElements, tocPointedElements);
}
};
}, false);
</script>

0 comments on commit f47a1a3

Please sign in to comment.