forked from parcel-bundler/lightningcss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocs.js
More file actions
38 lines (35 loc) · 1.05 KB
/
docs.js
File metadata and controls
38 lines (35 loc) · 1.05 KB
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
31
32
33
34
35
36
37
38
// Mark the current section in the table of contents with aria-current when scrolled into view.
let tocLinks = document.querySelectorAll('.table-of-contents a');
let headers = new Map();
for (let link of tocLinks) {
let headerId = link.hash.slice(1);
let header = document.getElementById(headerId);
headers.set(header, link);
}
let intersectingHeaders = new Set();
let observer = new IntersectionObserver(entries => {
for (let entry of entries) {
if (entry.isIntersecting) {
intersectingHeaders.add(entry.target);
} else {
intersectingHeaders.delete(entry.target);
}
}
if (intersectingHeaders.size > 0) {
let current = document.querySelector('.table-of-contents a[aria-current]');
if (current) {
current.removeAttribute('aria-current');
}
let first;
for (let [header, link] of headers) {
if (intersectingHeaders.has(header)) {
first = link;
break;
}
}
first.setAttribute('aria-current', 'location');
}
});
for (let header of headers.keys()) {
observer.observe(header);
}