-
Notifications
You must be signed in to change notification settings - Fork 5
/
script.js
149 lines (95 loc) · 2.91 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/**
* Binds navigation children toggling
*/
function bindNavToggle() {
function bindItem(el) {
el.addEventListener("click", function() {
el.parentElement.classList.toggle("nav-tree__item--collapsed");
});
}
var links = document.querySelectorAll(".nav-tree__item__label--togglable");
for (var i = 0; i < links.length; i++)
bindItem( links.item(i) );
}
/**
* Binds collapsibles
*/
function bindCollapsibles() {
function bindItem(el) {
el.addEventListener("click", function() {
const targetId = el.getAttribute("data-target");
const targetEl = document.getElementById(targetId);
if (targetEl)
targetEl.classList.toggle("collapsible--collapsed");
});
}
var links = document.querySelectorAll(".collapsible__toggler");
for (var i = 0; i < links.length; i++)
bindItem( links.item(i) );
}
/**
* Binds tab components
*/
function bindTabs() {
function bindTabsEl(el) {
var links = el.querySelectorAll("a");
if (links.length === 0) return;
function activateTab(linkEl) {
for (var i = 0; i < links.length; i++) {
var itemEl = links.item(i);
var targetEl = document.getElementById(itemEl.href.split("#", 2)[1]);
if (!targetEl) {
console.warn("Tab container element '%s' not found.", itemEl.href.split("#", 2)[1]);
continue;
}
if (links.item(i) === linkEl) {
itemEl.parentElement.classList.add("tabs__item--active");
targetEl.classList.add("tabs__content--active");
} else {
itemEl.parentElement.classList.remove("tabs__item--active");
targetEl.classList.remove("tabs__content--active");
}
}
}
function bindLink(linkEl) {
linkEl.addEventListener("click", function(ev) {
ev.preventDefault();
activateTab(linkEl);
return false;
});
};
for (var i = 0; i < links.length; i++)
bindLink(links.item(i));
activateTab(links.item(0));
}
var tabEls = document.querySelectorAll(".tabs");
for (var i = 0; i < tabEls.length; i++)
bindTabsEl( tabEls.item(i) );
}
function bindFilters() {
function updateFilter(el) {
if (el.checked) {
document.body.classList.remove("annot-hide-" + el.getAttribute("data-annotation"));
localStorage["raml2html_filters_" + el.getAttribute("data-annotation")] = "1";
} else {
document.body.classList.add("annot-hide-" + el.getAttribute("data-annotation"));
localStorage["raml2html_filters_" + el.getAttribute("data-annotation")] = "0";
}
}
function bindFilterOption(el) {
el.addEventListener("change", () => updateFilter(el));
if (localStorage["raml2html_filters_" + el.getAttribute("data-annotation")] == "0") {
el.checked = false;
updateFilter(el);
}
}
var filterOptEls = document.querySelectorAll(".nav-tree__filter-checkbox");
for (var i = 0; i < filterOptEls.length; i++)
bindFilterOption( filterOptEls.item(i) );
}
window.addEventListener("load", function() {
bindNavToggle();
bindCollapsibles();
bindTabs();
bindFilters();
});