-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindexScript.js
186 lines (159 loc) · 4.18 KB
/
indexScript.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
function onLoading() {
hi.innerHTML = "Hello.";
setTimeout(function() {
hi.innerHTML+=".";
},500);
setTimeout(function() {
hi.innerHTML+=".";
},1000);
setTimeout(function() {
hi.innerHTML+=".";
},1500);
setTimeout(function() {
hi.innerHTML+=".";
},1700);
setTimeout(function() {
hi.innerHTML+=".";
},1800);
setTimeout(function() {
hi.innerHTML+=".";
},1900);
setTimeout(function() {
hi.innerHTML = "";
turnOn();
}, 2000);
// Top Button
document.getElementById('topButton').addEventListener("click", function() {
onOff();
});
// Back Button
document.getElementById('back').addEventListener("click", function() {
turnOff();
turnOn();
});
// TODO: fix the following
// Contact App
document.getElementById('contact').addEventListener("click", function() {
window.location.href = "contact.php";
});
// Map App
document.getElementById('map').addEventListener("click", function() {
hideObjects(apps);
drawMap();
document.getElementById('toImagesApp').style.display = 'inline';
});
// Show Info App
document.getElementById('info').addEventListener("click", function() {
turnOff();
showInfo();
});
// Images App
document.getElementById('showImages').addEventListener("click", function() {
turnOff();
showImages();
});
// Next button
document.getElementById('next').addEventListener("click", function() {
turnOff();
showImages();
});
// To Images App button
document.getElementById('toImagesApp').addEventListener("click", function() {
turnOff();
showImages();
document.getElementById('toImagesApp').style.display = 'none';
});
}
// Button array
var apps = document.getElementsByClassName('app');
var imgButtons = document.getElementsByClassName('imgButtons');
// Phone Screen (canvas element)
var c = document.getElementById("phone");
var ctx = c.getContext("2d");
// Make Map
function drawMap() {
turnOff();
onOrOff = true;
ctx.fillStyle = "#dfe";
ctx.fillRect(0,0,phone.width,phone.height);
ctx.fillStyle="rgba(100,200,230,.7)";
ctx.fillRect(0,80,140,phone.height-80);
ctx.fillRect(190, 55, phone.width-165, 70);
ctx.fillRect(0,0,150,45);
ctx.fillRect(210,10,phone.width-210,30);
ctx.fillStyle = "rgba(80,80,100,.5);";
ctx.fillRect(190,110,10,10);
ctx.fillRect(220,55,40,5);
ctx.font = "10px sans-serif";
//ctx.fillText("Stairs (Down)", 200, 135);
ctx.fillRect(40, 80, 60, 20);
//ctx.fillText("Elevator", 60, 102);
}
// Show #nomophobia info
function showInfo() {
turnOff();
onOrOff = true;
ctx.fillStyle = "#dfc";
ctx.fillRect(0,0,phone.width,phone.height);
document.getElementById('infoText').style.display = 'inline';
}
// Image Array
var nomoImages = document.getElementsByClassName('nomoImages');
var imageIndex = 0;
var prevImg = nomoImages[imageIndex];
var curImg = nomoImages[imageIndex];
// Show images
function showImages() {
onOrOff = true;
if(imageIndex == nomoImages.length)
imageIndex = 0;
try {
curImg = nomoImages[imageIndex];
ctx.drawImage(curImg, 0, 0, phone.width, phone.height);
}
catch(err) {
ctx.fillStyle = '#eee';
ctx.font = "20 px sans-serif";
ctx.fillText("No Image Available", 50, 75);
}
displayObjects(imgButtons);
prevImg = curImg;
imageIndex++;
}
// Makes using onOff possible
var onOrOff = false;
function onOff() {
if(onOrOff===false) turnOn();
else turnOff();
}
function turnOn() {
hideObjects(imgButtons);
// Shows apps and screen lit up
displayObjects(apps);
ctx.fillStyle = '#eff';
ctx.clearRect(0,0,phone.width,phone.height);
ctx.fillRect(0,0,phone.width,phone.height);
ctx.fillStyle = 'rgba(100,100,100,.1)';
ctx.fillRect(20, 5, 258, 10);
onOrOff = true;
}
function turnOff() {
hideObjects(apps);
hideObjects(imgButtons);
document.getElementById('toImagesApp').style.display = 'none';
ctx.fillStyle = '#555';
ctx.clearRect(0,0,phone.width,phone.height);
ctx.fillRect(0,0,phone.width,phone.height);
document.getElementById('infoText').style.display = 'none';
onOrOff = false;
}
function displayObjects(objectsArray) {
for(var i = 0; i < objectsArray.length; i++) {
objectsArray[i].style.display = "inline";
}
}
function hideObjects(objectsArray) {
for(var i = 0; i < objectsArray.length; i++) {
objectsArray[i].style.display = "none";
}
}