-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjavascript.js
127 lines (102 loc) · 4.23 KB
/
javascript.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// ---------------------------------------- SLIDER ----------------------------------------
var inputRange = document.getElementsByClassName('pullee')[0],
maxValue = 150, // the higher the smoother when dragging
speed = 12, // thanks to @pixelass for this
currValue, rafID;
// set min/max value
inputRange.min = 0;
inputRange.max = maxValue;
// listen for unlock
function unlockStartHandler() {
// clear raf if trying again
window.cancelAnimationFrame(rafID);
// set to desired value
currValue = +this.value;
}
function unlockEndHandler() {
// store current value
currValue = +this.value;
// determine if we have reached success or not
if(currValue >= maxValue) {
successHandler();
}
else {
rafID = window.requestAnimationFrame(animateHandler);
}
}
// handle range animation
function animateHandler() {
// update input range
inputRange.value = currValue;
// determine if we need to continue
if(currValue > -1) {
window.requestAnimationFrame(animateHandler);
}
// decrement value
currValue = currValue - speed;
}
// handle successful unlock
function successHandler() {
var name = window.prompt("What is your name?");
alert('You have passed the test. Welcome to Aurore Vihalla, ' + name + '! ' + 'Where aspiring wizards learn how to interact, play, and tame magical creatures.');
document.getElementById("index").style.display="block";
document.getElementById("land").style.display="none";
// reset input range
inputRange.value = 0;
};
// bind events
inputRange.addEventListener('mousedown', unlockStartHandler, false);
inputRange.addEventListener('mousestart', unlockStartHandler, false);
inputRange.addEventListener('mouseup', unlockEndHandler, false);
inputRange.addEventListener('touchend', unlockEndHandler, false);
// ---------------------------------------- END OF SLIDER ----------------------------------------
// ---------------------------------------- THEME ----------------------------------------
const themeMap = {
dark: "light",
light: "solar",
solar: "dark"
};
const theme = localStorage.getItem('theme')
|| (tmp = Object.keys(themeMap)[0],
localStorage.setItem('theme', tmp),
tmp);
const bodyClass = document.body.classList;
bodyClass.add(theme);
function toggleTheme() {
const current = localStorage.getItem('theme');
const next = themeMap[current];
bodyClass.replace(current, next);
localStorage.setItem('theme', next);
}
document.getElementById('themeButton').onclick = toggleTheme;
// ---------------------------------------- END OF THEME ----------------------------------------
// ---------------------------------------- FUNCTIONALITIES ----------------------------------------
function appearAbout() {
document.getElementById("appearAbout").style.display="block";
document.getElementById("appearWho").style.display="none";
document.getElementById("appearGame").style.display="none";
document.getElementById("home").style.display="none";
document.getElementById("bgpic").style.display="none";
}
function appearWho() {
document.getElementById("appearWho").style.display="block";
document.getElementById("appearAbout").style.display="none";
document.getElementById("appearGame").style.display="none";
document.getElementById("home").style.display="none";
document.getElementById("bgpic").style.display="none";
}
function appearGame() {
document.getElementById("appearGame").style.display="block";
document.getElementById("appearAbout").style.display="none";
document.getElementById("appearWho").style.display="none";
document.getElementById("home").style.display="none";
document.getElementById("bgpic").style.display="none";
}
function home() {
document.getElementById("home").style.display="block";
document.getElementById("appearWho").style.display="none";
document.getElementById("appearAbout").style.display="none";
document.getElementById("appearGame").style.display="none";
document.getElementById("bgpic").style.display="block";
}
// ---------------------------------------- END OF FUNCTIONALITIES ----------------------------------------