-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclassy.js
30 lines (25 loc) · 1.23 KB
/
classy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Hook in tiny nav toggle's orphaned checkboxes
document.addEventListener("DOMContentLoaded", () => {
const source = document.querySelector("#tiny-page-nav-toggle");
const targets = [...document.querySelectorAll(".tiny-page-nav-target")];
source.addEventListener("change", (event) => {
for (let target of targets) target.checked = event.target.checked;
});
});
// Hook in table of contents smooth scroll behaviour
document.addEventListener("DOMContentLoaded", () => {
document.getElementById(document.location.hash.substring(1))?.scrollIntoView({behavior: "smooth"});
window.addEventListener("hashchange", () =>
document.getElementById(document.location.hash.substring(1))?.scrollIntoView({behavior: "smooth"}));
const toc = document.querySelector(".toc-tiny details");
const links = document.querySelectorAll(".toc a");
for (let a of links) {
const target = a.getAttribute("href");
a.addEventListener("click", (e) => {
e.preventDefault();
toc?.removeAttribute("open");
document.getElementById(target.substring(1))?.scrollIntoView({behavior: "smooth"});
window.history.pushState(null, null, target);
});
}
});