-
Notifications
You must be signed in to change notification settings - Fork 6.7k
/
Copy pathblackout.js
120 lines (98 loc) · 3.32 KB
/
blackout.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
/**
* Blackout plugin
*
* Press b or . to hide all slides, and b or . again to show them.
* Also navigating to a different slide will show them again (impress:stepleave).
*
* Copyright 2014 @Strikeskids
* Released under the MIT license.
*/
/* global document */
( function( document ) {
"use strict";
var canvas = null;
var blackedOut = false;
var util = null;
var root = null;
var api = null;
// While waiting for a shared library of utilities, copying these 2 from main impress.js
var css = function( el, props ) {
var key, pkey;
for ( key in props ) {
if ( props.hasOwnProperty( key ) ) {
pkey = pfx( key );
if ( pkey !== null ) {
el.style[ pkey ] = props[ key ];
}
}
}
return el;
};
var pfx = ( function() {
var style = document.createElement( "dummy" ).style,
prefixes = "Webkit Moz O ms Khtml".split( " " ),
memory = {};
return function( prop ) {
if ( typeof memory[ prop ] === "undefined" ) {
var ucProp = prop.charAt( 0 ).toUpperCase() + prop.substr( 1 ),
props = ( prop + " " + prefixes.join( ucProp + " " ) + ucProp ).split( " " );
memory[ prop ] = null;
for ( var i in props ) {
if ( style[ props[ i ] ] !== undefined ) {
memory[ prop ] = props[ i ];
break;
}
}
}
return memory[ prop ];
};
} )();
var removeBlackout = function() {
if ( blackedOut ) {
css( canvas, {
display: "block"
} );
blackedOut = false;
util.triggerEvent( root, "impress:autoplay:play", {} );
}
};
var blackout = function() {
if ( blackedOut ) {
removeBlackout();
} else {
css( canvas, {
display: ( blackedOut = !blackedOut ) ? "none" : "block"
} );
blackedOut = true;
util.triggerEvent( root, "impress:autoplay:pause", {} );
}
};
// Wait for impress.js to be initialized
document.addEventListener( "impress:init", function( event ) {
api = event.detail.api;
util = api.lib.util;
root = event.target;
canvas = root.firstElementChild;
var gc = api.lib.gc;
gc.addEventListener( document, "keydown", function( event ) {
// Accept b or . -> . is sent by presentation remote controllers
if ( event.keyCode === 66 || event.keyCode === 190 ) {
event.preventDefault();
if ( !blackedOut ) {
blackout();
} else {
removeBlackout();
}
}
}, false );
gc.addEventListener( document, "keyup", function( event ) {
// Accept b or . -> . is sent by presentation remote controllers
if ( event.keyCode === 66 || event.keyCode === 190 ) {
event.preventDefault();
}
}, false );
}, false );
document.addEventListener( "impress:stepleave", function() {
removeBlackout();
}, false );
} )( document );