Move helper functions from core to src/lib/util.js

This facilitates them being used from plugins as well as core impress.js.
This commit is contained in:
Henrik Ingo
2017-10-05 17:57:16 +03:00
parent 9b958f0e00
commit f3d193d636
6 changed files with 260 additions and 192 deletions

View File

@@ -25,12 +25,6 @@
( function( document ) {
"use strict";
var triggerEvent = function( el, eventName, detail ) {
var event = document.createEvent( "CustomEvent" );
event.initCustomEvent( eventName, true, true, detail );
el.dispatchEvent( event );
};
// Wait for impress.js to be initialized
document.addEventListener( "impress:init", function( event ) {
@@ -40,6 +34,7 @@
// need to control the presentation that was just initialized.
var api = event.detail.api;
var gc = api.lib.gc;
var util = api.lib.util;
// Supported keys are:
// [space] - quite common in presentation software to move forward
@@ -166,8 +161,9 @@
}, false );
// Add a line to the help popup
triggerEvent( document, "impress:help:add",
{ command: "Left & Right", text: "Previous & Next step", row: 1 } );
util.triggerEvent( document, "impress:help:add", { command: "Left & Right",
text: "Previous & Next step",
row: 1 } );
}, false );

View File

@@ -18,25 +18,12 @@
( function( document, window ) {
"use strict";
// Throttling function calls, by Remy Sharp
// http://remysharp.com/2010/07/21/throttling-function-calls/
var throttle = function( fn, delay ) {
var timer = null;
return function() {
var context = this, args = arguments;
window.clearTimeout( timer );
timer = window.setTimeout( function() {
fn.apply( context, args );
}, delay );
};
};
// Wait for impress.js to be initialized
document.addEventListener( "impress:init", function( event ) {
var api = event.detail.api;
// Rescale presentation when window is resized
api.lib.gc.addEventListener( window, "resize", throttle( function() {
api.lib.gc.addEventListener( window, "resize", api.lib.util.throttle( function() {
// Force going to active step again, to trigger rescaling
api.goto( document.querySelector( ".step.active" ), 500 );