Files
impress.js/src/plugins/blackout/blackout.js
janis 10a585ae8d Revert "clean up"
This reverts commit 40a3766b37.
2022-12-12 08:41:23 +01:00

121 lines
3.3 KiB
JavaScript

/**
* 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 );