-
Notifications
You must be signed in to change notification settings - Fork 3
/
schedule.js
46 lines (46 loc) · 1.78 KB
/
schedule.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
"use strict";
window.addEventListener('DOMContentLoaded', init, false);
function init() {
document.getElementById('expand').addEventListener('click', expand, false);
document.getElementById('collapse').addEventListener('click', collapse, false);
var localExpands = document.querySelectorAll('button.localExpand');
for (var i = 0, length = localExpands.length; localExpands[i]; i++) {
localExpands[i].addEventListener('click', localExpand, false);
}
var localCollapses = document.querySelectorAll('button.localCollapse');
for (var i = 0, length = localCollapses.length; localCollapses[i]; i++) {
localCollapses[i].addEventListener('click', localCollapse, false);
}
var answers = document.querySelectorAll('button.answer');
for (var i = 0, length = answers.length; answers[i]; i++) {
answers[i].addEventListener('click', showAnswer, false);
}
}
function expand() {
var sections = document.querySelectorAll('section > ol > li > ol');
for (var i = 0, length = sections.length; sections[i]; i++) {
sections[i].style.display = 'block';
}
}
function collapse() {
var sections = document.querySelectorAll('section > ol > li > ol');
for (var i = 0, length = sections.length; sections[i]; i++) {
sections[i].style.display = 'none';
}
}
function localExpand() {
this.parentElement.nextElementSibling.style.display = 'block';
}
function localCollapse() {
this.parentElement.nextElementSibling.style.display = 'none';
}
function showAnswer() {
var target = this.nextElementSibling;
if (target.tagName == 'DIV') {
target.style.display = 'block';
target.style.whiteSpace = 'pre';
target.style.backgroundColor = 'rgba(0,0,0,0.1)';
} else {
target.style.display = 'inline';
}
}