-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
executable file
·256 lines (220 loc) · 7.42 KB
/
script.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
/**
* Returns the current page number of the presentation.
*/
function currentPosition() {
return parseInt(document.querySelector('.slide:not(.hidden)').id.slice(6));
}
/**
* Navigates forward n pages
* If n is negative, we will navigate in reverse
*/
function navigate(n) {
var position = currentPosition();
var numSlides = document.getElementsByClassName('slide').length;
var $fragments = document.querySelectorAll('#slide-' + position + ' .fragment');
var fragmentsFinished = false;
if ($fragments.length) {
if (n > 0) {
var $f = document.querySelectorAll('#slide-' + position + ' .fragment.hidden');
if (!$f.length) fragmentsFinished = true;
else $f[0].classList.remove('hidden');
} else {
var $f = document.querySelectorAll('#slide-' + position + ' .fragment:not(.hidden)');
if (!$f.length) fragmentsFinished = true;
else $f[$f.length - 1].classList.add('hidden');
}
} else {
fragmentsFinished = true;
}
if (fragmentsFinished) {
/* Positions are 1-indexed, so we need to add and subtract 1 */
var nextPosition = (position - 1 + n) % numSlides + 1;
/* Normalize nextPosition in-case of a negative modulo result */
nextPosition = (nextPosition - 1 + numSlides) % numSlides + 1;
document.getElementById('slide-' + position).classList.add('hidden');
document.getElementById('slide-' + nextPosition).classList.remove('hidden');
updateProgress();
updateURL();
updateTabIndex();
}
}
/**
* Updates the current URL to include a hashtag of the current page number.
*/
function updateURL() {
try {
window.history.replaceState({}, null, '#' + currentPosition());
} catch (e) {
window.location.hash = currentPosition();
}
}
/**
* Sets the progress indicator.
*/
function updateProgress() {
var progressBar = document.querySelector('.progress-bar');
if (progressBar !== null) {
var numSlides = document.getElementsByClassName('slide').length;
var position = currentPosition() - 1;
var percent = (numSlides === 1) ? 100 : 100 * position / (numSlides - 1);
progressBar.style.width = percent.toString() + '%';
}
}
/**
* Removes tabindex property from all links on the current slide, sets
* tabindex = -1 for all links on other slides. Prevents slides from appearing
* out of control.
*/
function updateTabIndex() {
var allLinks = document.querySelectorAll('.slide a');
var position = currentPosition();
var currentPageLinks = document.getElementById('slide-' + position).querySelectorAll('a');
var i;
for (i = 0; i < allLinks.length; i++) {
allLinks[i].setAttribute('tabindex', -1);
}
for (i = 0; i < currentPageLinks.length; i++) {
currentPageLinks[i].removeAttribute('tabindex');
}
}
/**
* Determines whether or not we are currently in full screen mode
*/
function isFullScreen() {
return document.fullscreenElement ||
document.mozFullScreenElement ||
document.webkitFullscreenElement ||
document.msFullscreenElement;
}
/**
* Toggle fullScreen mode on document element.
* Works on chrome (>= 15), firefox (>= 9), ie (>= 11), opera(>= 12.1), safari (>= 5).
*/
function toggleFullScreen() {
/* Convenient renames */
var docElem = document.documentElement;
var doc = document;
docElem.requestFullscreen =
docElem.requestFullscreen ||
docElem.msRequestFullscreen ||
docElem.mozRequestFullScreen ||
docElem.webkitRequestFullscreen.bind(docElem, Element.ALLOW_KEYBOARD_INPUT);
doc.exitFullscreen =
doc.exitFullscreen ||
doc.msExitFullscreen ||
doc.mozCancelFullScreen ||
doc.webkitExitFullscreen;
isFullScreen() ? doc.exitFullscreen() : docElem.requestFullscreen();
}
document.addEventListener('DOMContentLoaded', function() {
// Update the tabindex to prevent weird slide transitioning
updateTabIndex();
// If the location hash specifies a page number, go to it.
var page = window.location.hash.slice(1);
if (page) {
navigate(parseInt(page) - 1);
}
document.onkeydown = function(e) {
if(e.target.tagName.toLowerCase() === 'textarea') return;
var kc = e.keyCode;
// left, down, H, J, backspace, PgUp - BACK
// up, right, K, L, space, PgDn - FORWARD
// enter - FULLSCREEN
if (kc === 37 || kc === 40 || kc === 8 || kc === 72 || kc === 74 || kc === 33) {
navigate(-1);
} else if (kc === 38 || kc === 39 || kc === 32 || kc === 75 || kc === 76 || kc === 34) {
navigate(1);
} else if (kc === 13) {
toggleFullScreen();
} else if (kc === 27) {
toggleOverview();
}
};
if (document.querySelector('.next') && document.querySelector('.prev')) {
document.querySelector('.next').onclick = function(e) {
e.preventDefault();
navigate(1);
};
document.querySelector('.prev').onclick = function(e) {
e.preventDefault();
navigate(-1);
};
}
if (document.querySelector('.overview')) {
document.querySelector('.overview').onclick = function(e) {
toggleOverview();
}
}
var $overlays = document.querySelectorAll('.slide-overlay');
[].forEach.call($overlays, function($overlay) {
$overlay.onclick = function(event) {
navigate(parseInt(event.target.dataset.id) - currentPosition());
toggleOverview();
}
});
var $fragments = document.querySelectorAll('.fragment');
[].forEach.call($fragments, function($fragment) {
$fragment.classList.add('hidden');
});
});
function toggleOverview() {
if (window.$style !== undefined) {
window.$style.remove();
delete window.$style;
document.querySelector('.slides').classList.remove('active');
} else {
var $slides = document.querySelector('.slides');
$slides.classList.add('active');
var slidesList = document.querySelectorAll('.slide-wrapper');
var w = window,
d = document,
e = d.documentElement,
g = d.getElementsByTagName('body')[0],
x = w.innerWidth || e.clientWidth || g.clientWidth,
y = w.innerHeight || e.clientHeight || g.clientHeight;
window.$style = document.createElement('style');
window.$style.innerHTML = '.slide-wrapper {width: ' + (x * 0.25) + 'px; height: ' + (y * 0.25) + 'px; } body .slide {width: ' + x + 'px; height: ' + y + 'px; position: relative; transform: scale(0.25,0.25); transform-origin: 0 0; } .slide.hidden{display: block; }';
document.getElementsByTagName('head')[0].appendChild(window.$style);
}
}
/**
* NEW BUBBLES
*/
// var canvas = document.getElementById('bubbling');
var slide1 = document.getElementById("slide-1")
var canvas = document.createElement("canvas");
canvas.id = "bubbling";
slide1.appendChild(canvas);
var ctx = canvas.getContext('2d');
var particles = [];
var particleCount = 280;
for (var i = 0; i < particleCount; i++) {
particles.push(new particle());
}
function particle() {
this.x = Math.random() * canvas.width;
this.y = canvas.height + Math.random() * 300;
this.speed = .5 + Math.random();
this.radius = Math.random() * 3;
this.opacity = (Math.random() * 300) / 1000;
}
function loopBubbles() {
requestAnimationFrame(loopBubbles);
draw();
}
function draw() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.globalCompositeOperation = 'lighter';
for (var i = 0; i < particles.length; i++) {
var p = particles[i];
ctx.beginPath();
ctx.fillStyle = 'rgba(255,255,255,' + p.opacity + ')';
ctx.arc(p.x, p.y, p.radius, 0, Math.PI * 2, false);
ctx.fill();
p.y -= p.speed;
if (p.y <= -10)
particles[i] = new particle();
}
}
// start bubbles
loopBubbles();