]> Dogcows Code - chaz/talk-level-up-your-perl/blob - js/common.js
initial commit
[chaz/talk-level-up-your-perl] / js / common.js
1
2 /*
3 * Create a shortcut on a number key to jump to a named slide.
4 *
5 * Using the hotkey on the target slide will go "back" to the slide that was active before jumping
6 * to the target slide.
7 *
8 * Example: Jump to the slide named "myslide" when the "1" key is pressed.
9 * createHotkey(1, 'myslide');
10 */
11 function createHotkey(key, slideName) {
12 var targetSlide = slideshow.getSlideByName(slideName);
13 var lastSlide = -1;
14 document.addEventListener('keydown', function(e) {
15 if (e.which === key + 48) {
16 var currentNum = slideshow.getCurrentSlideIndex() + 1;
17 var targetNum = targetSlide.getSlideIndex() + 1;
18 if (currentNum !== targetNum) {
19 lastSlide = currentNum;
20 slideshow.gotoSlide(targetNum);
21 }
22 else {
23 slideshow.gotoSlide(lastSlide);
24 }
25 }
26 });
27 };
28
29 /*
30 * Set a hotkey "u" to navigate backwards in time.
31 *
32 * If you get on the wrong slide, this might be the easiest way to get back on track. This is what
33 * you might expect the browser's "Back" button to do if it worked.
34 */
35 (function() {
36 var history = [];
37 var skip = false;
38 slideshow.on('hideSlide', function(slide) {
39 if (skip) {
40 skip = false;
41 return;
42 }
43 history.push(slide.getSlideIndex() + 1);
44 });
45 document.addEventListener('keydown', function(e) {
46 if (e.which === 85 /* [u]ndo */) {
47 var lastNum = history.pop();
48 if (lastNum) {
49 skip = true;
50 slideshow.gotoSlide(lastNum);
51 }
52 }
53 });
54 })();
55
This page took 0.033512 seconds and 4 git commands to generate.