-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscripts.js
287 lines (228 loc) · 9.11 KB
/
scripts.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
"use strict";
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
var slideCount = document.querySelectorAll('section').length;
var controls = function controls(event) {
var isCover = window.location.hash === '' || window.location.hash === '#start';
if (isCover) {
start(event);
} else {
navigate(event);
}
};
var start = function start(event) {
if (event.code === 'Space' || event.code === 'ArrowRight' || event.code === 'Period') {
window.location.hash = '#slide1';
}
};
var navigate = function navigate(event) {
var isFirstSlide = window.location.hash === '#slide1';
var isLastSlide = window.location.hash === '#slide' + (slideCount - 1);
var activeSlide = document.querySelector('[id^="slide"]:target');
var slideNum = parseInt(activeSlide.getAttribute('id').substring(5));
if (activeSlide && !isLastSlide && (event.code === 'Space' || event.code === 'ArrowRight' || event.code === 'PageDown')) {
window.location.hash = 'slide' + (slideNum + 1);
}
if (!isFirstSlide && (event.code === 'ArrowLeft' || event.code === 'PageUp')) {
window.location.hash = 'slide' + (slideNum - 1);
}
if (isLastSlide && event.code === 'KeyR') {
window.location.hash = '#start';
}
if (activeSlide && event.code === 'Period') {
var winHash = window.location.hash;
var activeList = document.querySelector(winHash + ' .revealable');
if (activeList) {
var listArray = _toConsumableArray(document.querySelectorAll(winHash + ' .revealable .fragment'));
if (listArray[0]) {
listArray[0].classList.remove('fragment');
}
}
}
if (activeSlide && event.code === 'Comma') {
var _winHash = window.location.hash;
var _activeList = document.querySelector(_winHash + ' .revealable');
if (_activeList) {
var _listArray = _toConsumableArray(document.querySelectorAll(_winHash + ' .revealable li'));
var hideList = _listArray.forEach(function (list) {
list.classList.add('fragment');
});
return hideList;
}
}
};
(function () {
var chrisHeads = document.getElementsByClassName('jsChris');
var nonsense = document.getElementById('nonsense');
var lastActiveHead = null;
function headAppear() {
nonsense.style.setProperty('--tx', Math.floor(Math.random() * 100) + 0 + 'vw');
nonsense.style.setProperty('--ty', Math.floor(Math.random() * 100) + 0 + 'vh');
if (lastActiveHead) lastActiveHead.classList.toggle('active');
var random = Math.floor(Math.random() * (chrisHeads.length - 1)) + 0;
var randomHead = chrisHeads[random];
randomHead.classList.toggle('active');
lastActiveHead = randomHead;
setTimeout(headAppear, 20000);
}
headAppear();
})();
var launchFullscreen = function launchFullscreen(element) {
if (element.requestFullscreen) {
element.requestFullscreen();
} else if (element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if (element.webkitRequestFullscreen) {
element.webkitRequestFullscreen();
} else if (element.msRequestFullscreen) {
element.msRequestFullscreen();
}
};
var toggleFullScreen = function toggleFullScreen(event) {
if (event.code === 'KeyF') {
launchFullscreen(document.documentElement);
}
};
document.body.addEventListener('keydown', controls, false);
document.addEventListener('keydown', toggleFullScreen, false);
"use strict";
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
var gamepadConnected = ('ongamepadconnected' in window);
var controllers = {};
var gamepadLand;
var buttonsCache = [];
var buttonsStatus = []; // Mapping is subject to change
// Turn on debugger function to check
var leftJoyConMapping = {
0: 'Left',
1: 'Down',
2: 'Up',
3: 'Right',
4: 'LSL',
5: 'LSR',
8: 'Minus',
10: 'LStick',
13: 'Capture',
14: 'L',
15: 'ZL'
};
if (!gamepadConnected) {
setInterval(pollGamepads, 500);
}
var pollGamepads = function pollGamepads() {
var gamepads = navigator.getGamepads ? navigator.getGamepads() : navigator.webkitGetGamepads ? navigator.webkitGetGamepads() : [];
for (var i = 0; i < gamepads.length; i++) {
if (gamepads[i]) {
if (gamepads[i].index in controllers) {
controllers[gamepads[i].index] = gamepads[i];
} else {
addGamepad(gamepads[i]);
}
}
}
};
var addGamepad = function addGamepad(gamepad) {
console.log(gamepad);
window.location.hash = '#start';
controllers[gamepad.index] = gamepad;
var d = document.createElement('aside');
d.className = 'controllers';
var p = document.createElement('span');
p.innerHTML = '🕹';
p.setAttribute('id', 'controller' + gamepad.index);
d.appendChild(p);
document.body.appendChild(d);
gamepadLand = requestAnimationFrame(updateStatus);
};
var updateStatus = function updateStatus() {
if (!gamepadConnected) {
pollGamepads();
}
for (var j in controllers) {
var controller = controllers[j];
var buttonsArray = controller.buttons;
for (var i = 0; i < buttonsArray.length; i++) {
if (buttonPressed(buttonsArray[i])) {
mappingDebugger(i);
var isCover = window.location.hash === '' || window.location.hash === '#start';
var isFirstSlide = window.location.hash === '#slide1';
var isLastSlide = window.location.hash === '#slide' + (slideCount - 1);
if (isCover) {
window.location.hash = '#slide1';
} else {
var activeSlide = document.querySelector('[id^="slide"]:target');
var slideNum = parseInt(activeSlide.getAttribute('id').substring(5));
switch (leftJoyConMapping[i]) {
case 'Left':
if (!isFirstSlide) {
window.location.hash = 'slide' + (slideNum - 1);
}
break;
case 'Right':
if (activeSlide && !isLastSlide) {
console.log(slideNum);
window.location.hash = 'slide' + (slideNum + 1);
}
break;
case 'Up':
break;
case 'Down':
break;
case 'Minus':
if (isLastSlide) {
window.location.hash = '#slide1';
}
break;
case 'L':
launchFullscreen(document.documentElement);
break;
case 'ZL':
exitFullscreen();
break;
default:
console.log('The mapping is probably off. Turn on debugger to check. ¯\\\_(ツ)_/¯');
}
}
}
}
}
gamepadLand = setTimeout(function () {
return requestAnimationFrame(updateStatus);
}, 200);
};
var buttonPressed = function buttonPressed(key) {
if (_typeof(key) == 'object') {
return key.pressed;
}
return false;
};
var mappingDebugger = function mappingDebugger(index) {
console.log('Did you press ' + leftJoyConMapping[index] + '? If you see "Undefined", the mapping is off. Index position of pressed button is ' + index);
};
var connectHandler = function connectHandler(event) {
addGamepad(event.gamepad);
};
var disconnectHandler = function disconnectHandler(event) {
removeGamepad(event.gamepad);
};
var removeGamepad = function removeGamepad(gamepad) {
var d = document.getElementById('controller' + gamepad.index);
document.body.removeChild(d);
delete controllers[gamepad.index];
cancelAnimationFrame(gamepadLand);
};
var exitFullscreen = function exitFullscreen() {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
}
};
window.addEventListener("gamepadconnected", connectHandler);
window.addEventListener("gamepaddisconnected", disconnectHandler);