-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
46 lines (37 loc) · 1.08 KB
/
script.js
File metadata and controls
46 lines (37 loc) · 1.08 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
const navbar = document.getElementById('navbar');
/*
* Events
*/
document.getElementById('navbar-toggle').addEventListener('click', function() {
navbar.classList.toggle('shown');
});
navbar.addEventListener('click', function(event) {
// delegate clicks from <li>s to <nav>
const elem = event.target;
if (elem.nodeName != 'LI') return;
const id = elem.dataset.id;
displayData(id, elem.textContent);
navbar.classList.remove('shown');
});
document.getElementById('btn-go').addEventListener('click', function() {
window.open(currentPage);
})
/*
* Functionality
*/
let currentPage = 'home';
function displayData(id, title) {
if (id == currentPage) return;
const section = document.getElementById(id);
if (section) {
if (id == 'home') {
document.getElementById('btn-go').classList.remove('shown');
} else {
document.getElementById('btn-go').classList.add('shown');
}
document.getElementById(currentPage).classList.remove('shown');
document.getElementById(id).classList.add('shown');
document.getElementById('page-title').textContent = title;
currentPage = id;
}
}