-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
82 lines (69 loc) · 2.38 KB
/
Copy pathscript.js
File metadata and controls
82 lines (69 loc) · 2.38 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
(function () {
"use strict";
var tabList = document.querySelector(".tabs");
if (!tabList) return;
var tabs = tabList.querySelectorAll('[role="tab"]');
var panels = document.querySelectorAll(".tab-panel");
function activateTab(selected) {
var targetId = selected.getAttribute("aria-controls");
tabs.forEach(function (tab) {
var isSelected = tab === selected;
tab.setAttribute("aria-selected", isSelected ? "true" : "false");
tab.tabIndex = isSelected ? 0 : -1;
});
panels.forEach(function (panel) {
var show = panel.id === targetId;
panel.classList.toggle("hidden", !show);
panel.hidden = !show;
});
}
tabs.forEach(function (tab) {
tab.addEventListener("click", function () {
activateTab(tab);
});
tab.addEventListener("keydown", function (e) {
var index = Array.prototype.indexOf.call(tabs, tab);
var next = -1;
if (e.key === "ArrowRight") next = (index + 1) % tabs.length;
else if (e.key === "ArrowLeft") next = (index - 1 + tabs.length) % tabs.length;
else if (e.key === "Home") next = 0;
else if (e.key === "End") next = tabs.length - 1;
if (next >= 0) {
e.preventDefault();
tabs[next].focus();
activateTab(tabs[next]);
}
});
});
var tocLinks = document.querySelectorAll(".toc a, .nav a");
var sections = [];
tocLinks.forEach(function (link) {
var id = link.getAttribute("href");
if (!id || id.charAt(0) !== "#") return;
var section = document.getElementById(id.slice(1));
if (section && sections.indexOf(section) === -1) {
sections.push(section);
}
});
if (sections.length && "IntersectionObserver" in window) {
var observer = new IntersectionObserver(
function (entries) {
entries.forEach(function (entry) {
if (!entry.isIntersecting) return;
var id = entry.target.id;
tocLinks.forEach(function (link) {
var href = link.getAttribute("href");
var active = href === "#" + id;
link.classList.toggle("active", active);
if (active) link.setAttribute("aria-current", "true");
else link.removeAttribute("aria-current");
});
});
},
{ rootMargin: "-40% 0px -50% 0px", threshold: 0 }
);
sections.forEach(function (section) {
observer.observe(section);
});
}
})();