bgneal@12
|
1 function main() {
|
bgneal@12
|
2 // Since we don't have the fallback of attachEvent and
|
bgneal@12
|
3 // other IE only stuff we won't try to run JS for IE.
|
bgneal@12
|
4 // It will run though when using Google Chrome Frame
|
bgneal@12
|
5 if (document.all) { return; }
|
bgneal@12
|
6
|
bgneal@12
|
7 var currentSlideNo;
|
bgneal@12
|
8 var notesOn = false;
|
bgneal@12
|
9 var expanded = false;
|
bgneal@12
|
10 var hiddenContext = false;
|
bgneal@12
|
11 var blanked = false;
|
bgneal@12
|
12 var slides = document.getElementsByClassName('slide');
|
bgneal@12
|
13 var touchStartX = 0;
|
bgneal@12
|
14 var spaces = /\s+/, a1 = [''];
|
bgneal@12
|
15 var tocOpened = false;
|
bgneal@12
|
16 var helpOpened = false;
|
bgneal@12
|
17 var overviewActive = false;
|
bgneal@12
|
18 var modifierKeyDown = false;
|
bgneal@12
|
19 var scale = 1;
|
bgneal@12
|
20 var showingPresenterView = false;
|
bgneal@12
|
21 var presenterViewWin = null;
|
bgneal@12
|
22 var isPresenterView = false;
|
bgneal@12
|
23
|
bgneal@12
|
24 var str2array = function(s) {
|
bgneal@12
|
25 if (typeof s == 'string' || s instanceof String) {
|
bgneal@12
|
26 if (s.indexOf(' ') < 0) {
|
bgneal@12
|
27 a1[0] = s;
|
bgneal@12
|
28 return a1;
|
bgneal@12
|
29 } else {
|
bgneal@12
|
30 return s.split(spaces);
|
bgneal@12
|
31 }
|
bgneal@12
|
32 }
|
bgneal@12
|
33 return s;
|
bgneal@12
|
34 };
|
bgneal@12
|
35
|
bgneal@12
|
36 var trim = function(str) {
|
bgneal@12
|
37 return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
|
bgneal@12
|
38 };
|
bgneal@12
|
39
|
bgneal@12
|
40 var addClass = function(node, classStr) {
|
bgneal@12
|
41 classStr = str2array(classStr);
|
bgneal@12
|
42 var cls = ' ' + node.className + ' ';
|
bgneal@12
|
43 for (var i = 0, len = classStr.length, c; i < len; ++i) {
|
bgneal@12
|
44 c = classStr[i];
|
bgneal@12
|
45 if (c && cls.indexOf(' ' + c + ' ') < 0) {
|
bgneal@12
|
46 cls += c + ' ';
|
bgneal@12
|
47 }
|
bgneal@12
|
48 }
|
bgneal@12
|
49 node.className = trim(cls);
|
bgneal@12
|
50 };
|
bgneal@12
|
51
|
bgneal@12
|
52 var removeClass = function(node, classStr) {
|
bgneal@12
|
53 var cls;
|
bgneal@12
|
54 if (!node) {
|
bgneal@12
|
55 throw 'no node provided';
|
bgneal@12
|
56 }
|
bgneal@12
|
57 if (classStr !== undefined) {
|
bgneal@12
|
58 classStr = str2array(classStr);
|
bgneal@12
|
59 cls = ' ' + node.className + ' ';
|
bgneal@12
|
60 for (var i = 0, len = classStr.length; i < len; ++i) {
|
bgneal@12
|
61 cls = cls.replace(' ' + classStr[i] + ' ', ' ');
|
bgneal@12
|
62 }
|
bgneal@12
|
63 cls = trim(cls);
|
bgneal@12
|
64 } else {
|
bgneal@12
|
65 cls = '';
|
bgneal@12
|
66 }
|
bgneal@12
|
67 if (node.className != cls) {
|
bgneal@12
|
68 node.className = cls;
|
bgneal@12
|
69 }
|
bgneal@12
|
70 };
|
bgneal@12
|
71
|
bgneal@12
|
72 var getSlideEl = function(slideNo) {
|
bgneal@12
|
73 if (slideNo > 0) {
|
bgneal@12
|
74 return slides[slideNo - 1];
|
bgneal@12
|
75 } else {
|
bgneal@12
|
76 return null;
|
bgneal@12
|
77 }
|
bgneal@12
|
78 };
|
bgneal@12
|
79
|
bgneal@12
|
80 var getSlideTitle = function(slideNo) {
|
bgneal@12
|
81 var el = getSlideEl(slideNo);
|
bgneal@12
|
82 if (el) {
|
bgneal@12
|
83 var headers = el.getElementsByTagName('header');
|
bgneal@12
|
84 if (headers.length > 0) {
|
bgneal@12
|
85 return el.getElementsByTagName('header')[0].innerText;
|
bgneal@12
|
86 }
|
bgneal@12
|
87 }
|
bgneal@12
|
88 return null;
|
bgneal@12
|
89 };
|
bgneal@12
|
90
|
bgneal@12
|
91 var getSlidePresenterNote = function(slideNo) {
|
bgneal@12
|
92 var el = getSlideEl(slideNo);
|
bgneal@12
|
93 if (el) {
|
bgneal@12
|
94 var n = el.getElementsByClassName('presenter_notes');
|
bgneal@12
|
95 if (n.length > 0) {
|
bgneal@12
|
96 return n[0];
|
bgneal@12
|
97 }
|
bgneal@12
|
98 }
|
bgneal@12
|
99 return null;
|
bgneal@12
|
100 };
|
bgneal@12
|
101
|
bgneal@12
|
102 var changeSlideElClass = function(slideNo, className) {
|
bgneal@12
|
103 var el = getSlideEl(slideNo);
|
bgneal@12
|
104 if (el) {
|
bgneal@12
|
105 removeClass(el, 'far-past past current future far-future');
|
bgneal@12
|
106 addClass(el, className);
|
bgneal@12
|
107 }
|
bgneal@12
|
108 };
|
bgneal@12
|
109
|
bgneal@12
|
110 var updateSlideClasses = function(updateOther) {
|
bgneal@12
|
111 window.location.hash = (isPresenterView ? "presenter" : "slide") + currentSlideNo;
|
bgneal@12
|
112
|
bgneal@12
|
113 for (var i=1; i<currentSlideNo-1; i++) {
|
bgneal@12
|
114 changeSlideElClass(i, 'far-past');
|
bgneal@12
|
115 }
|
bgneal@12
|
116
|
bgneal@12
|
117 changeSlideElClass(currentSlideNo - 1, 'past');
|
bgneal@12
|
118 changeSlideElClass(currentSlideNo, 'current');
|
bgneal@12
|
119 changeSlideElClass(currentSlideNo + 1, 'future');
|
bgneal@12
|
120
|
bgneal@12
|
121 for (i=currentSlideNo+2; i<slides.length+1; i++) {
|
bgneal@12
|
122 changeSlideElClass(i, 'far-future');
|
bgneal@12
|
123 }
|
bgneal@12
|
124
|
bgneal@12
|
125 highlightCurrentTocLink();
|
bgneal@12
|
126
|
bgneal@12
|
127 processContext();
|
bgneal@12
|
128
|
bgneal@12
|
129 document.getElementsByTagName('title')[0].innerText = getSlideTitle(currentSlideNo);
|
bgneal@12
|
130
|
bgneal@12
|
131 updatePresenterNotes();
|
bgneal@12
|
132
|
bgneal@12
|
133 if (updateOther) { updateOtherPage(); }
|
bgneal@12
|
134 };
|
bgneal@12
|
135
|
bgneal@12
|
136 var updatePresenterNotes = function() {
|
bgneal@12
|
137 if (!isPresenterView) { return; }
|
bgneal@12
|
138
|
bgneal@12
|
139 var existingNote = document.getElementById('current_presenter_notes');
|
bgneal@12
|
140 var currentNote = getSlidePresenterNote(currentSlideNo).cloneNode(true);
|
bgneal@12
|
141 currentNote.setAttribute('id', 'presenter_note');
|
bgneal@12
|
142
|
bgneal@12
|
143 existingNote.replaceChild(currentNote, document.getElementById('presenter_note'));
|
bgneal@12
|
144 };
|
bgneal@12
|
145
|
bgneal@12
|
146 var highlightCurrentTocLink = function() {
|
bgneal@12
|
147 var toc = document.getElementById('toc');
|
bgneal@12
|
148
|
bgneal@12
|
149 if (toc) {
|
bgneal@12
|
150 var tocRows = toc.getElementsByTagName('tr');
|
bgneal@12
|
151 for (var i=0; i<tocRows.length; i++) {
|
bgneal@12
|
152 removeClass(tocRows.item(i), 'active');
|
bgneal@12
|
153 }
|
bgneal@12
|
154
|
bgneal@12
|
155 var currentTocRow = document.getElementById('toc-row-' + currentSlideNo);
|
bgneal@12
|
156 if (currentTocRow) {
|
bgneal@12
|
157 addClass(currentTocRow, 'active');
|
bgneal@12
|
158 }
|
bgneal@12
|
159 }
|
bgneal@12
|
160 };
|
bgneal@12
|
161
|
bgneal@12
|
162 var updateOtherPage = function() {
|
bgneal@12
|
163 if (!showingPresenterView) { return; }
|
bgneal@12
|
164
|
bgneal@12
|
165 var w = isPresenterView ? window.opener : presenterViewWin;
|
bgneal@12
|
166 w.postMessage('slide#' + currentSlideNo, '*');
|
bgneal@12
|
167 };
|
bgneal@12
|
168
|
bgneal@12
|
169 var nextSlide = function() {
|
bgneal@12
|
170 if (currentSlideNo < slides.length) {
|
bgneal@12
|
171 currentSlideNo++;
|
bgneal@12
|
172 }
|
bgneal@12
|
173 updateSlideClasses(true);
|
bgneal@12
|
174 };
|
bgneal@12
|
175
|
bgneal@12
|
176 var prevSlide = function() {
|
bgneal@12
|
177 if (currentSlideNo > 1) {
|
bgneal@12
|
178 currentSlideNo--;
|
bgneal@12
|
179 }
|
bgneal@12
|
180 updateSlideClasses(true);
|
bgneal@12
|
181 };
|
bgneal@12
|
182
|
bgneal@12
|
183 var showNotes = function() {
|
bgneal@12
|
184 var notes = getSlideEl(currentSlideNo).getElementsByClassName('notes');
|
bgneal@12
|
185 for (var i = 0, len = notes.length; i < len; i++) {
|
bgneal@12
|
186 notes.item(i).style.display = (notesOn) ? 'none':'block';
|
bgneal@12
|
187 }
|
bgneal@12
|
188 notesOn = !notesOn;
|
bgneal@12
|
189 };
|
bgneal@12
|
190
|
bgneal@12
|
191 var showSlideNumbers = function() {
|
bgneal@12
|
192 var asides = document.getElementsByClassName('page_number');
|
bgneal@12
|
193 var hidden = asides[0].style.display != 'block';
|
bgneal@12
|
194 for (var i = 0; i < asides.length; i++) {
|
bgneal@12
|
195 asides.item(i).style.display = hidden ? 'block' : 'none';
|
bgneal@12
|
196 }
|
bgneal@12
|
197 };
|
bgneal@12
|
198
|
bgneal@12
|
199 var showSlideSources = function() {
|
bgneal@12
|
200 var asides = document.getElementsByClassName('source');
|
bgneal@12
|
201 var hidden = asides[0].style.display != 'block';
|
bgneal@12
|
202 for (var i = 0; i < asides.length; i++) {
|
bgneal@12
|
203 asides.item(i).style.display = hidden ? 'block' : 'none';
|
bgneal@12
|
204 }
|
bgneal@12
|
205 };
|
bgneal@12
|
206
|
bgneal@12
|
207 var showToc = function() {
|
bgneal@12
|
208 if (helpOpened) {
|
bgneal@12
|
209 showHelp();
|
bgneal@12
|
210 }
|
bgneal@12
|
211 var toc = document.getElementById('toc');
|
bgneal@12
|
212 if (toc) {
|
bgneal@12
|
213 toc.style.marginLeft = tocOpened ? '-' + (toc.clientWidth + 20) + 'px' : '0px';
|
bgneal@12
|
214 tocOpened = !tocOpened;
|
bgneal@12
|
215 }
|
bgneal@12
|
216 updateOverview();
|
bgneal@12
|
217 };
|
bgneal@12
|
218
|
bgneal@12
|
219 var showHelp = function() {
|
bgneal@12
|
220 if (tocOpened) {
|
bgneal@12
|
221 showToc();
|
bgneal@12
|
222 }
|
bgneal@12
|
223
|
bgneal@12
|
224 var help = document.getElementById('help');
|
bgneal@12
|
225
|
bgneal@12
|
226 if (help) {
|
bgneal@12
|
227 help.style.marginLeft = helpOpened ? '-' + (help.clientWidth + 20) + 'px' : '0px';
|
bgneal@12
|
228 helpOpened = !helpOpened;
|
bgneal@12
|
229 }
|
bgneal@12
|
230 };
|
bgneal@12
|
231
|
bgneal@12
|
232 var showPresenterView = function() {
|
bgneal@12
|
233 if (isPresenterView) { return; }
|
bgneal@12
|
234
|
bgneal@12
|
235 if (showingPresenterView) {
|
bgneal@12
|
236 presenterViewWin.close();
|
bgneal@12
|
237 presenterViewWin = null;
|
bgneal@12
|
238 showingPresenterView = false;
|
bgneal@12
|
239 } else {
|
bgneal@12
|
240 presenterViewWin = open(window.location.pathname + "#presenter" + currentSlideNo, 'presenter_notes',
|
bgneal@12
|
241 'directories=no,location=no,toolbar=no,menubar=no,copyhistory=no');
|
bgneal@12
|
242 showingPresenterView = true;
|
bgneal@12
|
243 }
|
bgneal@12
|
244 };
|
bgneal@12
|
245
|
bgneal@12
|
246 var switch3D = function() {
|
bgneal@12
|
247 if (document.body.className.indexOf('three-d') == -1) {
|
bgneal@12
|
248 document.getElementsByClassName('presentation')[0].style.webkitPerspective = '1000px';
|
bgneal@12
|
249 document.body.className += ' three-d';
|
bgneal@12
|
250 } else {
|
bgneal@12
|
251 window.setTimeout('document.getElementsByClassName(\'presentation\')[0].style.webkitPerspective = \'0\';', 2000);
|
bgneal@12
|
252 document.body.className = document.body.className.replace(/three-d/, '');
|
bgneal@12
|
253 }
|
bgneal@12
|
254 };
|
bgneal@12
|
255
|
bgneal@12
|
256 var toggleOverview = function() {
|
bgneal@12
|
257 if (!overviewActive) {
|
bgneal@12
|
258 addClass(document.body, 'expose');
|
bgneal@12
|
259 overviewActive = true;
|
bgneal@12
|
260 setScale(1);
|
bgneal@12
|
261 } else {
|
bgneal@12
|
262 removeClass(document.body, 'expose');
|
bgneal@12
|
263 overviewActive = false;
|
bgneal@12
|
264 if (expanded) {
|
bgneal@12
|
265 setScale(scale); // restore scale
|
bgneal@12
|
266 }
|
bgneal@12
|
267 }
|
bgneal@12
|
268 processContext();
|
bgneal@12
|
269 updateOverview();
|
bgneal@12
|
270 };
|
bgneal@12
|
271
|
bgneal@12
|
272 var updateOverview = function() {
|
bgneal@12
|
273 try {
|
bgneal@12
|
274 var presentation = document.getElementsByClassName('presentation')[0];
|
bgneal@12
|
275 } catch (e) {
|
bgneal@12
|
276 return;
|
bgneal@12
|
277 }
|
bgneal@12
|
278
|
bgneal@12
|
279 if (isPresenterView) {
|
bgneal@12
|
280 var action = overviewActive ? removeClass : addClass;
|
bgneal@12
|
281 action(document.body, 'presenter_view');
|
bgneal@12
|
282 }
|
bgneal@12
|
283
|
bgneal@12
|
284 var toc = document.getElementById('toc');
|
bgneal@12
|
285
|
bgneal@12
|
286 if (!toc) {
|
bgneal@12
|
287 return;
|
bgneal@12
|
288 }
|
bgneal@12
|
289
|
bgneal@12
|
290 if (!tocOpened || !overviewActive) {
|
bgneal@12
|
291 presentation.style.marginLeft = '0px';
|
bgneal@12
|
292 presentation.style.width = '100%';
|
bgneal@12
|
293 } else {
|
bgneal@12
|
294 presentation.style.marginLeft = toc.clientWidth + 'px';
|
bgneal@12
|
295 presentation.style.width = (presentation.clientWidth - toc.clientWidth) + 'px';
|
bgneal@12
|
296 }
|
bgneal@12
|
297 };
|
bgneal@12
|
298
|
bgneal@12
|
299 var computeScale = function() {
|
bgneal@12
|
300 var cSlide = document.getElementsByClassName('current')[0];
|
bgneal@12
|
301 var sx = cSlide.clientWidth / window.innerWidth;
|
bgneal@12
|
302 var sy = cSlide.clientHeight / window.innerHeight;
|
bgneal@12
|
303 return 1 / Math.max(sx, sy);
|
bgneal@12
|
304 };
|
bgneal@12
|
305
|
bgneal@12
|
306 var setScale = function(scale) {
|
bgneal@12
|
307 var presentation = document.getElementsByClassName('slides')[0];
|
bgneal@12
|
308 var transform = 'scale(' + scale + ')';
|
bgneal@12
|
309 presentation.style.MozTransform = transform;
|
bgneal@12
|
310 presentation.style.WebkitTransform = transform;
|
bgneal@12
|
311 presentation.style.OTransform = transform;
|
bgneal@12
|
312 presentation.style.msTransform = transform;
|
bgneal@12
|
313 presentation.style.transform = transform;
|
bgneal@12
|
314 };
|
bgneal@12
|
315
|
bgneal@12
|
316 var expandSlides = function() {
|
bgneal@12
|
317 if (overviewActive) {
|
bgneal@12
|
318 return;
|
bgneal@12
|
319 }
|
bgneal@12
|
320 if (expanded) {
|
bgneal@12
|
321 setScale(1);
|
bgneal@12
|
322 expanded = false;
|
bgneal@12
|
323 } else {
|
bgneal@12
|
324 scale = computeScale();
|
bgneal@12
|
325 setScale(scale);
|
bgneal@12
|
326 expanded = true;
|
bgneal@12
|
327 }
|
bgneal@12
|
328 };
|
bgneal@12
|
329
|
bgneal@12
|
330 var showContext = function() {
|
bgneal@12
|
331 try {
|
bgneal@12
|
332 var presentation = document.getElementsByClassName('slides')[0];
|
bgneal@12
|
333 removeClass(presentation, 'nocontext');
|
bgneal@12
|
334 } catch (e) {}
|
bgneal@12
|
335 };
|
bgneal@12
|
336
|
bgneal@12
|
337 var hideContext = function() {
|
bgneal@12
|
338 try {
|
bgneal@12
|
339 var presentation = document.getElementsByClassName('slides')[0];
|
bgneal@12
|
340 addClass(presentation, 'nocontext');
|
bgneal@12
|
341 } catch (e) {}
|
bgneal@12
|
342 };
|
bgneal@12
|
343
|
bgneal@12
|
344 var processContext = function() {
|
bgneal@12
|
345 if (hiddenContext) {
|
bgneal@12
|
346 hideContext();
|
bgneal@12
|
347 } else {
|
bgneal@12
|
348 showContext();
|
bgneal@12
|
349 }
|
bgneal@12
|
350 };
|
bgneal@12
|
351
|
bgneal@12
|
352 var toggleContext = function() {
|
bgneal@12
|
353 hiddenContext = !hiddenContext;
|
bgneal@12
|
354 processContext();
|
bgneal@12
|
355 };
|
bgneal@12
|
356
|
bgneal@12
|
357 var toggleBlank = function() {
|
bgneal@12
|
358 blank_elem = document.getElementById('blank');
|
bgneal@12
|
359
|
bgneal@12
|
360 blank_elem.style.display = blanked ? 'none' : 'block';
|
bgneal@12
|
361
|
bgneal@12
|
362 blanked = !blanked;
|
bgneal@12
|
363 };
|
bgneal@12
|
364
|
bgneal@12
|
365 var isModifierKey = function(keyCode) {
|
bgneal@12
|
366 switch (keyCode) {
|
bgneal@12
|
367 case 16: // shift
|
bgneal@12
|
368 case 17: // ctrl
|
bgneal@12
|
369 case 18: // alt
|
bgneal@12
|
370 case 91: // command
|
bgneal@12
|
371 return true;
|
bgneal@12
|
372 break;
|
bgneal@12
|
373 default:
|
bgneal@12
|
374 return false;
|
bgneal@12
|
375 break;
|
bgneal@12
|
376 }
|
bgneal@12
|
377 };
|
bgneal@12
|
378
|
bgneal@12
|
379 var checkModifierKeyUp = function(event) {
|
bgneal@12
|
380 if (isModifierKey(event.keyCode)) {
|
bgneal@12
|
381 modifierKeyDown = false;
|
bgneal@12
|
382 }
|
bgneal@12
|
383 };
|
bgneal@12
|
384
|
bgneal@12
|
385 var checkModifierKeyDown = function(event) {
|
bgneal@12
|
386 if (isModifierKey(event.keyCode)) {
|
bgneal@12
|
387 modifierKeyDown = true;
|
bgneal@12
|
388 }
|
bgneal@12
|
389 };
|
bgneal@12
|
390
|
bgneal@12
|
391 var handleBodyKeyDown = function(event) {
|
bgneal@12
|
392 switch (event.keyCode) {
|
bgneal@12
|
393 case 13: // Enter
|
bgneal@12
|
394 if (overviewActive) {
|
bgneal@12
|
395 toggleOverview();
|
bgneal@12
|
396 }
|
bgneal@12
|
397 break;
|
bgneal@12
|
398 case 27: // ESC
|
bgneal@12
|
399 toggleOverview();
|
bgneal@12
|
400 break;
|
bgneal@12
|
401 case 37: // left arrow
|
bgneal@12
|
402 case 33: // page up
|
bgneal@16
|
403 event.preventDefault();
|
bgneal@12
|
404 prevSlide();
|
bgneal@12
|
405 break;
|
bgneal@12
|
406 case 39: // right arrow
|
bgneal@12
|
407 case 32: // space
|
bgneal@12
|
408 case 34: // page down
|
bgneal@16
|
409 event.preventDefault();
|
bgneal@12
|
410 nextSlide();
|
bgneal@12
|
411 break;
|
bgneal@12
|
412 case 50: // 2
|
bgneal@12
|
413 if (!modifierKeyDown) {
|
bgneal@12
|
414 showNotes();
|
bgneal@12
|
415 }
|
bgneal@12
|
416 break;
|
bgneal@12
|
417 case 51: // 3
|
bgneal@12
|
418 if (!modifierKeyDown && !overviewActive) {
|
bgneal@12
|
419 switch3D();
|
bgneal@12
|
420 }
|
bgneal@12
|
421 break;
|
bgneal@12
|
422 case 190: // .
|
bgneal@12
|
423 case 48: // 0
|
bgneal@12
|
424 case 66: // b
|
bgneal@12
|
425 if (!modifierKeyDown && !overviewActive) {
|
bgneal@12
|
426 toggleBlank();
|
bgneal@12
|
427 }
|
bgneal@12
|
428 break;
|
bgneal@12
|
429 case 67: // c
|
bgneal@12
|
430 if (!modifierKeyDown && !overviewActive) {
|
bgneal@12
|
431 toggleContext();
|
bgneal@12
|
432 }
|
bgneal@12
|
433 break;
|
bgneal@12
|
434 case 69: // e
|
bgneal@12
|
435 if (!modifierKeyDown && !overviewActive) {
|
bgneal@12
|
436 expandSlides();
|
bgneal@12
|
437 }
|
bgneal@12
|
438 break;
|
bgneal@12
|
439 case 72: // h
|
bgneal@12
|
440 showHelp();
|
bgneal@12
|
441 break;
|
bgneal@12
|
442 case 78: // n
|
bgneal@12
|
443 if (!modifierKeyDown && !overviewActive) {
|
bgneal@12
|
444 showSlideNumbers();
|
bgneal@12
|
445 }
|
bgneal@12
|
446 break;
|
bgneal@12
|
447 case 80: // p
|
bgneal@12
|
448 if (!modifierKeyDown && !overviewActive) {
|
bgneal@12
|
449 showPresenterView();
|
bgneal@12
|
450 }
|
bgneal@12
|
451 break;
|
bgneal@12
|
452 case 83: // s
|
bgneal@12
|
453 if (!modifierKeyDown && !overviewActive) {
|
bgneal@12
|
454 showSlideSources();
|
bgneal@12
|
455 }
|
bgneal@12
|
456 break;
|
bgneal@12
|
457 case 84: // t
|
bgneal@12
|
458 showToc();
|
bgneal@12
|
459 break;
|
bgneal@12
|
460 }
|
bgneal@12
|
461 };
|
bgneal@12
|
462
|
bgneal@12
|
463 var handleWheel = function(event) {
|
bgneal@12
|
464 if (tocOpened || helpOpened || overviewActive) {
|
bgneal@12
|
465 return;
|
bgneal@12
|
466 }
|
bgneal@12
|
467
|
bgneal@12
|
468 var delta = 0;
|
bgneal@12
|
469
|
bgneal@12
|
470 if (!event) {
|
bgneal@12
|
471 event = window.event;
|
bgneal@12
|
472 }
|
bgneal@12
|
473
|
bgneal@12
|
474 if (event.wheelDelta) {
|
bgneal@12
|
475 delta = event.wheelDelta/120;
|
bgneal@12
|
476 if (window.opera) delta = -delta;
|
bgneal@12
|
477 } else if (event.detail) {
|
bgneal@12
|
478 delta = -event.detail/3;
|
bgneal@12
|
479 }
|
bgneal@12
|
480
|
bgneal@12
|
481 if (delta && delta <0) {
|
bgneal@12
|
482 nextSlide();
|
bgneal@12
|
483 } else if (delta) {
|
bgneal@12
|
484 prevSlide();
|
bgneal@12
|
485 }
|
bgneal@12
|
486 };
|
bgneal@12
|
487
|
bgneal@12
|
488 var addSlideClickListeners = function() {
|
bgneal@12
|
489 for (var i=0; i < slides.length; i++) {
|
bgneal@12
|
490 var slide = slides.item(i);
|
bgneal@12
|
491 slide.num = i + 1;
|
bgneal@12
|
492 slide.addEventListener('click', function(e) {
|
bgneal@12
|
493 if (overviewActive) {
|
bgneal@12
|
494 currentSlideNo = this.num;
|
bgneal@12
|
495 toggleOverview();
|
bgneal@12
|
496 updateSlideClasses(true);
|
bgneal@12
|
497 e.preventDefault();
|
bgneal@12
|
498 }
|
bgneal@12
|
499 return false;
|
bgneal@12
|
500 }, true);
|
bgneal@12
|
501 }
|
bgneal@12
|
502 };
|
bgneal@12
|
503
|
bgneal@12
|
504 var addRemoteWindowControls = function() {
|
bgneal@12
|
505 window.addEventListener("message", function(e) {
|
bgneal@12
|
506 if (e.data.indexOf("slide#") != -1) {
|
bgneal@12
|
507 currentSlideNo = Number(e.data.replace('slide#', ''));
|
bgneal@12
|
508 updateSlideClasses(false);
|
bgneal@12
|
509 }
|
bgneal@12
|
510 }, false);
|
bgneal@12
|
511 };
|
bgneal@12
|
512
|
bgneal@12
|
513 var addTouchListeners = function() {
|
bgneal@12
|
514 document.addEventListener('touchstart', function(e) {
|
bgneal@12
|
515 touchStartX = e.touches[0].pageX;
|
bgneal@12
|
516 }, false);
|
bgneal@12
|
517 document.addEventListener('touchend', function(e) {
|
bgneal@12
|
518 var pixelsMoved = touchStartX - e.changedTouches[0].pageX;
|
bgneal@12
|
519 var SWIPE_SIZE = 150;
|
bgneal@12
|
520 if (pixelsMoved > SWIPE_SIZE) {
|
bgneal@12
|
521 nextSlide();
|
bgneal@12
|
522 }
|
bgneal@12
|
523 else if (pixelsMoved < -SWIPE_SIZE) {
|
bgneal@12
|
524 prevSlide();
|
bgneal@12
|
525 }
|
bgneal@12
|
526 }, false);
|
bgneal@12
|
527 };
|
bgneal@12
|
528
|
bgneal@12
|
529 var addTocLinksListeners = function() {
|
bgneal@12
|
530 var toc = document.getElementById('toc');
|
bgneal@12
|
531 if (toc) {
|
bgneal@12
|
532 var tocLinks = toc.getElementsByTagName('a');
|
bgneal@12
|
533 for (var i=0; i < tocLinks.length; i++) {
|
bgneal@12
|
534 tocLinks.item(i).addEventListener('click', function(e) {
|
bgneal@12
|
535 currentSlideNo = Number(this.attributes['href'].value.replace('#slide', ''));
|
bgneal@12
|
536 updateSlideClasses(true);
|
bgneal@12
|
537 e.preventDefault();
|
bgneal@12
|
538 }, true);
|
bgneal@12
|
539 }
|
bgneal@12
|
540 }
|
bgneal@12
|
541 };
|
bgneal@12
|
542
|
bgneal@12
|
543 // initialize
|
bgneal@12
|
544
|
bgneal@12
|
545 (function() {
|
bgneal@12
|
546 if (window.location.hash == "") {
|
bgneal@12
|
547 currentSlideNo = 1;
|
bgneal@12
|
548 } else if (window.location.hash.indexOf("#presenter") != -1) {
|
bgneal@12
|
549 currentSlideNo = Number(window.location.hash.replace('#presenter', ''));
|
bgneal@12
|
550 isPresenterView = true;
|
bgneal@12
|
551 showingPresenterView = true;
|
bgneal@12
|
552 presenterViewWin = window;
|
bgneal@12
|
553 addClass(document.body, 'presenter_view');
|
bgneal@12
|
554 } else {
|
bgneal@12
|
555 currentSlideNo = Number(window.location.hash.replace('#slide', ''));
|
bgneal@12
|
556 }
|
bgneal@12
|
557
|
bgneal@12
|
558 document.addEventListener('keyup', checkModifierKeyUp, false);
|
bgneal@12
|
559 document.addEventListener('keydown', handleBodyKeyDown, false);
|
bgneal@12
|
560 document.addEventListener('keydown', checkModifierKeyDown, false);
|
bgneal@12
|
561 document.addEventListener('DOMMouseScroll', handleWheel, false);
|
bgneal@12
|
562
|
bgneal@12
|
563 window.onmousewheel = document.onmousewheel = handleWheel;
|
bgneal@12
|
564 window.onresize = expandSlides;
|
bgneal@12
|
565
|
bgneal@12
|
566 for (var i = 0, el; el = slides[i]; i++) {
|
bgneal@12
|
567 addClass(el, 'slide far-future');
|
bgneal@12
|
568 }
|
bgneal@12
|
569 updateSlideClasses(false);
|
bgneal@12
|
570
|
bgneal@12
|
571 // add support for finger events (filter it by property detection?)
|
bgneal@12
|
572 addTouchListeners();
|
bgneal@12
|
573
|
bgneal@12
|
574 addTocLinksListeners();
|
bgneal@12
|
575
|
bgneal@12
|
576 addSlideClickListeners();
|
bgneal@12
|
577
|
bgneal@12
|
578 addRemoteWindowControls();
|
bgneal@12
|
579 })();
|
bgneal@12
|
580 }
|