-
Notifications
You must be signed in to change notification settings - Fork 15
/
handler.js
45 lines (37 loc) · 1.12 KB
/
handler.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
var tabNames = ["home", "games", "engines", "learn"]
var tabContainer = {}
window.onload = function() {
tabNames.forEach(name => tabContainer[name] = document.getElementById(name))
showCorrectTab()
}
function onBurger() {
document.getElementById("burger").classList.toggle('is-active')
document.getElementById("mainNavBar").classList.toggle('is-active')
}
function swapTab(goal) {
history.pushState({}, "lets-gamedev.de", "?tab=" + goal);
showCorrectTab()
}
function showCorrectTab() {
var activeTab = getParam("tab")
if (activeTab == null) {
swapTab("home")
return
}
tabNames.forEach(name => showDomElement(tabContainer[name], activeTab === name))
}
function showDomElement(element, show) {
element.classList.remove(show ? "hide" : "show")
element.classList.add(show ? "show" : "hide")
}
function getParam(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split("=");
if (pair[0] == variable) {
return pair[1];
}
}
return null
}