-
Notifications
You must be signed in to change notification settings - Fork 2
/
script.js
97 lines (90 loc) · 3.74 KB
/
script.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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
(function () {
var createEl = function (tagName, attrs) {
var anchor = document.createElement(tagName);
Object.keys(attrs).forEach(function (key) {
anchor[key] = attrs[key];
});
return anchor;
};
var createAnchorFromHeading = function (headingEl) {
let href = '#' + (headingEl.id || headingEl.parentNode.id);
return createEl(
"a",
{
className: "ref",
href: href,
textContent: "#",
title: headingEl.textContent
}
);
};
window.addEventListener("load", function () {
Array.prototype.forEach.call(document.querySelectorAll("#main h1[id], #main h2[id], #main h3[id], #main h4[id], #main h5[id], #main section[id]>h2, #main section[id]>h3, #main section[id]>h4, #main p[id]"), function (el) {
if (el.id === "buttonbar") {
return;
}
var a = createAnchorFromHeading(el);
el.classList.add("has-ref");
if (el.nodeName !== 'P') {
el.addEventListener("click", function () {
a.click();
});
}
el.insertBefore(a, el.firstChild);
});
if (document.querySelector("[data-controls]")) {
document.querySelector("[data-controls]").setAttribute('style', '');
document.querySelector("[data-expand]").addEventListener("click", function () {
Array.prototype.forEach.call(document.querySelectorAll("details"), function (el) {
el.open = true;
});
});
document.querySelector("[data-collapse]").addEventListener("click", function () {
Array.prototype.forEach.call(document.querySelectorAll("details"), function (el) {
el.open = false;
});
});
}
if (window.location.hash) {
if (window.location.hash === "#openall") {
document.querySelector("[data-expand]").click();
}
else {
var el = document.querySelector(window.location.hash);
if (el && el.parentNode && (el.parentNode.nodeName === 'DETAILS')) {
el.parentNode.open = true;
}
}
window.setTimeout(() => {
window.location.hash = window.location.hash;
}, 50);
}
const toggle = document.querySelector('[data-action=toggle]');
if (toggle) {
const button = document.createElement('button');
button.innerHTML = 'Expand talks descriptions ▶';
button.setAttribute('data-action', 'expand');
toggle.appendChild(button);
button.addEventListener('click', _ => {
if (button.getAttribute('data-action') === 'expand') {
button.setAttribute('data-action', 'collapse');
button.innerHTML = 'Collapse talks descriptions ▼';
[...document.querySelectorAll('details.talk')].forEach(talk => {
if (!talk.hasAttribute('open')) {
talk.setAttribute('open', '');
}
});
}
else {
button.setAttribute('data-action', 'expand');
button.innerHTML = 'Expand talks descriptions ▶';
[...document.querySelectorAll('details.talk')].forEach(talk => {
if (talk.hasAttribute('open')) {
talk.removeAttribute('open');
}
});
}
});
}
});
})();