forked from 14four/skills-assessment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
67 lines (54 loc) · 1.63 KB
/
scripts.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
// Toggles email / phone display.
function showHideDetail() {
const obj = document.getElementById("view-switch");
const value = obj.options[obj.selectedIndex].value;
if (value == "phone") {
Array.from(document.getElementsByClassName('email')).forEach((el) => {
hideElement(el);
});
Array.from(document.getElementsByClassName('phone')).forEach((el) => {
showElement(el);
});
} else {
Array.from(document.getElementsByClassName('phone')).forEach((el) => {
hideElement(el);
});
Array.from(document.getElementsByClassName('email')).forEach((el) => {
showElement(el);
});
}
}
function showElement(ele) {
ele.style.display = 'block';
}
function hideElement(ele) {
ele.style.display = 'none';
}
// Closes overlay and active class.
function closeActive() {
document.querySelectorAll('section.active')[0].classList.remove('active');
document.body.className = document.body.className.replace('open', '');
}
function makeActive(ele) {
document.body.classList.add('open');
ele.classList.add('active');
}
function handleRowAction(event) {
const clickedElement = event.target;
const detailCheck = clickedElement.closest('.full-info');
// Don't close active if they click on anything in the full details area.
if (detailCheck != null) {
return ;
}
let ele = clickedElement.closest('section');
// If they click on an active row, just close it and the overlay.
if (ele.classList.contains('active')) {
closeActive();
} else {
makeActive(ele);
}
}
const sectionList = document.getElementsByTagName('section');
for (let i = 0; i < sectionList.length; i++) {
sectionList[i].addEventListener('click', handleRowAction);
}