-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.js
383 lines (329 loc) · 9.59 KB
/
controller.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
current_window_width = window.innerWidth;
/* Path prototype extension */
if (!("path" in Event.prototype)) {
Object.defineProperty(Event.prototype, "path", {
get: function () {
var path = [];
var currentElem = this.target;
while (currentElem) {
path.push(currentElem);
currentElem = currentElem.parentElement;
}
if (path.indexOf(window) === -1 && path.indexOf(document) === -1)
path.push(document);
if (path.indexOf(window) === -1)
path.push(window);
return path;
}
});
}
window.onload = function () {
/*
Map
*/
mapboxgl.accessToken = "pk.eyJ1IjoiY29ubm9yc3RhbXBlciIsImEiOiJjamFpeDM1bXMyMXdrMnFsZTh0dmJmanVxIn0.v2IUgOKPxfRDTlAhaswe0w";
/* Map: This represents the map on the page. */
var map = new mapboxgl.Map({
container: "map",
style: "mapbox://styles/connorstamper/cjmh7cpqx9tgg2ro6qj0ocstn",
zoom: 13,
center: [-89.40331, 43.07108]
});
var geojson = {
type: 'FeatureCollection',
features: [{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [-89.40355468309329, 43.071904256933436]
},
properties: {
title: 'MadHacks',
description: '1025 W Johnson St',
description2: 'Madison, WI 53706'
}
}]
}
// add markers to map
geojson.features.forEach(function (marker) {
// create a HTML element for each feature
var el = document.createElement('div');
el.className = 'marker';
// make a marker for each feature and add to the map
new mapboxgl.Marker(el)
.setLngLat(marker.geometry.coordinates)
.addTo(map);
new mapboxgl.Popup({ closeOnClick: false })
.setLngLat([-89.40355468309329, 43.074])
.setHTML('<h3>' + marker.properties.title + '</h3><p>' +
marker.properties.description + '<br>' + marker.properties.description2 + '</p>')
.addTo(map);
});
map.addControl(new mapboxgl.NavigationControl());
if (window.innerWidth > 801) {
/*
Window Manager
*/
numWindows = document.querySelectorAll('.framed').length;
windowZs = []
function updateZ(evt, manual) {
if (evt.data) {
elm = evt.data.sourceContainer;
}
else {
elm = evt.path[evt.path.length - 6];
}
for (i = 0; i < numWindows; i++) {
l = windowZs[i]
if (l == elm) {
windowZs.splice(i, 1)
windowZs.push(l)
}
}
for (i = numWindows - 1; i >= 0; i--) {
windowZs[i].style.zIndex = i.toString()
}
}
function MakeFrame(list_of_frames) {
var out = {}
for (var i = 0; i < list_of_frames.length; i++) {
var l = list_of_frames[i];
out[l] = {}
l.addEventListener('click', updateZ)
windowZs.push(l)
}
return out
}
frames_set = MakeFrame(document.querySelectorAll('.framed'));
const draggable = new Draggable.Draggable(document.querySelectorAll('.framed'), {
draggable: '.title_bar'
});
draggable.on('drag:start', (evt) => {
updateZ(evt)
relative_x = evt.data.sensorEvent.data.clientX - evt.data.sourceContainer.offsetLeft;
relative_y = evt.data.sensorEvent.data.clientY - evt.data.sourceContainer.offsetTop;
frames_set[evt.data.sourceContainer]['init_mouse_start'] = [relative_x, relative_y];
if (relative_x > evt.data.sourceContainer.offsetWidth - 25) {
evt.data.sourceContainer.classList.remove("active");
evt.data.sourceContainer.classList.remove("default_window");
}
else {
// About-window specific behaviour
evt.data.sourceContainer.classList.add("active")
evt.data.sourceContainer.classList.remove("default_window");
}
});
draggable.on('drag:move', (evt) => {
frame = evt.data.sourceContainer;
// About-window specific behaviour
if (evt.data.sourceContainer.classList.contains("default_window")) {
evt.data.sourceContainer.classList.add("active")
evt.data.sourceContainer.classList.remove("default_window");
}
});
draggable.on('drag:move', (evt) => {
frame = evt.data.sourceContainer;
x = evt.data.sensorEvent.data.clientX;
y = evt.data.sensorEvent.data.clientY;
x_ = frames_set[frame]['init_mouse_start'][0];
y_ = frames_set[frame]['init_mouse_start'][1];
bound_x = x + frame.offsetWidth - x_;
bound_y = y + frame.offsetHeight - y_;
anchor_x = x - x_;
anchor_y = y - y_;
frame.style.left = x - x_;
if (y - y_ > 32) {
frame.style.top = y - y_;
}
else {
frame.style.top = "32px";
}
});
draggable.on('drag:stop', (evt) => {
/* Removed to allow for smaller screen sizes
frame = evt.data.sourceContainer;
w = frame.offsetWidth;
h = frame.offsetHeight;
l = frame.offsetLeft;
t = frame.offsetTop;
if (l < 0) {
frame.style.left = 1;
}
else if (l + w > window.innerWidth) {
frame.style.left = window.innerWidth - w - 1;
}
if (t < 32) {
frame.style.top = 32;
}
else if (t + h > window.innerHeight) {
frame.style.top = window.innerHeight - h - 1;
}
*/
});
/*
Desktop Icons
*/
dicons = document.getElementsByClassName("d-icon");
for (var i = 0; i < dicons.length; i++) {
d = dicons[i]
d.addEventListener('click', (evt) => {
dicons = document.getElementsByClassName("d-icon");
for (var i = 0; i < dicons.length; i++) {
d = dicons[i]
d.classList.remove("focused");
}
evt.currentTarget.classList.add("focused");
// Fix map size
map.resize();
// Fix z ordering of frames
updateZ({ 'data': { 'sourceContainer': document.getElementsByClassName(evt.currentTarget.dataset.linkedFrame)[0] } })
evt.stopPropagation();
});
d.addEventListener('dblclick', (evt) => {
evt.currentTarget.classList.remove("focused");
//if apply icon open link in new window/tab
if (evt.currentTarget.dataset.linkedFrame === 'apply') {
openInNewTab('./application')
} else {
linked_frame = document.getElementsByClassName(evt.currentTarget.dataset.linkedFrame)[0];
linked_frame.classList.add("active");
linked_frame.classList.remove("default_window")
linked_frame.style.left = 32
linked_frame.style.top = 64
}
// Fix map size
map.resize();
evt.stopPropagation();
});
}
function openInNewTab(url) {
var win = window.open(url, '_blank');
win.focus();
}
/*
Menu Clock
*/
function startTime() {
var today = new Date();
var h = today.getHours();
var m = today.getMinutes();
dayornight = isItTheMorning(h);
m = formatMinutes(m);
h = formatHours(h);
document.getElementById('time').innerHTML =
h + ":" + m + dayornight;
var t = setTimeout(startTime, 500);
}
function formatMinutes(minutes, h) {
if (minutes < 10) { minutes = "0" + minutes }; // add zero in front of numbers < 10
return minutes;
}
function formatHours(hours) {
if (hours === 0) {
return 12
}
else if (hours > 12) {
return hours - 12
}
else {
return hours
}
}
function isItTheMorning(hours) {
if (hours < 12) {
return ' AM'
}
else {
return ' PM'
}
}
startTime();
/*
Nav bar
*/
document.addEventListener('click', () => {
ddowns = document.getElementsByClassName("dropdown-content");
for (var i = 0; i < ddowns.length; i++) {
d = ddowns[i]
d.classList.remove("show");
}
dicons = document.getElementsByClassName("d-icon");
for (var i = 0; i < dicons.length; i++) {
d = dicons[i]
d.classList.remove("focused");
}
})
}
else {
/* Mobile version code */
about = document.getElementsByClassName('default_window')[0];
about.classList.remove('default_window');
map.resize();
}
}
// Manage switching between mobile size and desktop size
window.onresize = function () {
if (window.innerWidth <= 801 && current_window_width > 801) {
window.location.reload()
}
if (window.innerWidth > 801 && current_window_width <= 801) {
window.location.reload()
}
current_window_width = window.innerWidth;
}
function drawerToggle() {
var menuToggle = document.getElementsByClassName('hamburger')[0];
menuToggle.classList.toggle('is-active');
var sideDrawer = document.getElementsByClassName('side-drawer')[0];
sideDrawer.classList.toggle('open');
}
//toggle drawer menu items
function displayToggle(target) {
element = document.getElementById(target);
element.classList.toggle('open')
}
/*
Navbar dropdown functionality
Needs to be outside window.onload for function scoping reasons
this is ugly -- fix later
*/
function ddownFunction(id, evt) {
ddowns = document.getElementsByClassName("dropdown-content");
for (var i = 0; i < ddowns.length; i++) {
d = ddowns[i];
if (d != document.getElementById(id)) {
d.classList.remove("show");
}
}
document.getElementById(id).classList.toggle("show");
evt.stopPropagation();
}
// handle sponsor buttons
function showPartners() {
partnerBtn = document.getElementById('partner-btn');
partnerBtn.classList.add('active-button');
sponsorBtn = document.getElementById('sponsor-btn');
sponsorBtn.classList.remove('active-button');
document.getElementById('partnerList').style.display = 'block';
document.getElementById('sponsorList').style.display = 'none';
}
function showSponsors() {
partnerBtn = document.getElementById('partner-btn');
partnerBtn.classList.remove('active-button');
sponsorBtn = document.getElementById('sponsor-btn');
sponsorBtn.classList.add('active-button');
document.getElementById('partnerList').style.display = 'none';
document.getElementById('sponsorList').style.display = 'block';
}
function faqButtonClick(el) {
faqButtons = document.getElementsByClassName('faq-button');
faqTarget = document.getElementById('faqTarget')
for (i = 0; i < faqButtons.length; i++) {
if (faqButtons[i] !== el) {
faqButtons[i].classList.remove('faqActive')
}
}
el.classList.add('faqActive')
var content = el.querySelector('#faqContent').innerHTML
faqTarget.innerHTML = content;
}