-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom.js
More file actions
65 lines (61 loc) · 2.21 KB
/
custom.js
File metadata and controls
65 lines (61 loc) · 2.21 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
// Script to filter sections of webpage
function openSection(secName) {
var i;
// Hide all "sectionDiv"
var secItems = document.getElementsByClassName("sectionDiv");
for (i = 0; i < secItems.length; i++) {
secItems[i].style.display = "none";
}
document.getElementById(secName).style.display = "block";
var secButtons = document.getElementsByClassName("secNav");
for (var i = 0; i < secButtons.length; i++) {
w3RemoveClass(secButtons[i], "w3-light-grey");
if (secButtons[i].className.indexOf("secButton" + secName) > -1) {
w3AddClass(secButtons[i], "w3-light-grey");
}
}
}
// Script to filter items by category in bibliography
function filterBibliography(bibName) {
var bibItems, bibButtons, i;
// Add "w3-teal" class to button that was clicked, removing it from others
bibButtons = document.getElementsByClassName("bibNav");
for (i = 0; i < bibButtons.length; i++) {
w3RemoveClass(bibButtons[i], "w3-teal");
if (bibButtons[i].className.indexOf(bibName) > -1) {
w3AddClass(bibButtons[i], "w3-teal");
}
}
bibItems = document.getElementsByClassName("filterBib");
if (bibName == "showall") bibName = "";
// Add the "show" class (display:block) to the filtered elements, and remove the "show" class from the elements that are not selected
for (i = 0; i < bibItems.length; i++) {
w3RemoveClass(bibItems[i], "show");
if (bibItems[i].className.indexOf(bibName) > -1) {
w3AddClass(bibItems[i], "show");
}
}
}
// Show filtered elements
function w3AddClass(element, name) {
var i, arr1, arr2;
arr1 = element.className.split(" ");
arr2 = name.split(" ");
for (i = 0; i < arr2.length; i++) {
if (arr1.indexOf(arr2[i]) == -1) {
element.className += " " + arr2[i];
}
}
}
// Hide elements that are not selected
function w3RemoveClass(element, name) {
var i, arr1, arr2;
arr1 = element.className.split(" ");
arr2 = name.split(" ");
for (i = 0; i < arr2.length; i++) {
while (arr1.indexOf(arr2[i]) > -1) {
arr1.splice(arr1.indexOf(arr2[i]), 1);
}
}
element.className = arr1.join(" ");
}