forked from nodeschool/nodeschool.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
65 lines (54 loc) · 1.54 KB
/
main.js
File metadata and controls
65 lines (54 loc) · 1.54 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
var back = document.createElement('button');
back.appendChild(document.createTextNode('Back'));
back.id = 'back';
back.addEventListener('click', function (ev) {
window.location.hash = '#';
});
var boxContainer = document.querySelector('.boxes');
boxContainer.parentNode.insertBefore(back, boxContainer);
var boxes = [].slice.call(document.querySelectorAll('.box'));
boxes.forEach(function (box) {
box.addEventListener('click', function (ev) {
window.location.hash = '#' + this.getAttribute('data-url');
});
box.classList.add('small');
});
var sectionHeaders = [].slice.call(document.querySelectorAll('.section'));
function hideAll() {
boxes.forEach(function (box) {
box.style.display = 'none';
});
sectionHeaders.forEach(function (header) {
header.style.display = 'none';
});
}
function showAll() {
boxes.forEach(function (box) {
box.style.display = 'inline-block';
box.classList.add('small');
});
sectionHeaders.forEach(function (header) {
header.style.display = 'block';
});
}
window.addEventListener('hashchange', handleHashChange);
function handleHashChange() {
var hash = window.location.hash.slice(1);
if (!hash)
return showIndex();
showItemByUrl(hash);
}
function showIndex() {
showAll();
back.classList.remove('show');
}
function showItemByUrl(frag) {
var el = document.querySelector('*[data-url="'+frag+'"]');
if (el && el.classList.contains('small')) {
hideAll();
el.style.display = 'block';
el.classList.remove('small');
back.classList.add('show');
}
}
handleHashChange();