-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
87 lines (74 loc) · 2.48 KB
/
Copy pathscript.js
File metadata and controls
87 lines (74 loc) · 2.48 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
83
84
85
const checkboxContainers = document.getElementsByClassName("checkbox-container");
const instrumentsContainer = document.getElementById("instruments-panel");
const defaultMessage = "Narrow down instruments by selecting from the criteria below. If criteria are inapplicable, please leave them unselected.";
const msg = document.getElementById("msg");
const clearBtn = document.getElementById("clear-btn");
clearBtn.addEventListener('click', () => {
clearCriteria();
});
let selectedCriteria = [];
function addOption(option) {
selectedCriteria.push(option);
}
function removeOption(optionToRemove) {
selectedCriteria.splice(selectedCriteria.indexOf(optionToRemove), 1);
}
function clearCriteria(){
while (selectedCriteria.length > 0) {
selectedCriteria.pop();
}
for (let container of checkboxContainers) {
container.querySelector("input").checked = false;
}
updateInstruments();
}
function updateInstruments() {
let anySuccess = false;
for (let name in data) {
let match = true;
for (let i = 0; i < selectedCriteria.length; i++) {
if (!data[name][selectedCriteria[i]]) {
match = false;
break;
}
}
let instrumentDiv = document.getElementById(name);
if (match) {
instrumentDiv.classList.remove("greyed-out");
anySuccess = true;
} else {
instrumentDiv.classList.add("greyed-out");
}
}
msg.textContent = anySuccess ? defaultMessage
: 'No instruments match the selected criteria.';
msg.style.color = anySuccess ? "#21314d" : 'red';
}
// create all instruments in instrument panel
for (let name in data) {
// create new div
let div = document.createElement('div');
div.id = name;
div.className = "instrument";
// create div contents
let a = document.createElement('a');
a.appendChild(document.createTextNode(name));
a.setAttribute('href', data[name].link);
if (data[name].link !== "") {
a.setAttribute('target', "_blank");
}
div.appendChild(a);
// add to instruments panel
instrumentsContainer.appendChild(div);
}
for (let container of checkboxContainers) {
let checkbox = container.querySelector("input");
checkbox.addEventListener('click', () => {
if (checkbox.checked) {
addOption(checkbox.id);
} else {
removeOption(checkbox.id);
}
updateInstruments();
})
}