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

@@ -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 );