From b180d94e0227558de766af47b37d96693a942b60 Mon Sep 17 00:00:00 2001 From: Hakim El Hattab Date: Thu, 14 Mar 2019 15:39:19 +0100 Subject: [PATCH] fix error when reveal.js was initialized with no plugins --- js/reveal.js | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/js/reveal.js b/js/reveal.js index 51b1ed0..387077a 100644 --- a/js/reveal.js +++ b/js/reveal.js @@ -539,30 +539,39 @@ var pluginsToInitialize = Object.keys( plugins ).length; - var afterPlugInitialized = function() { - if( --pluginsToInitialize === 0 ) { - loadAsyncDependencies(); - } - }; + // If there are no plugins, skip this step + if( pluginsToInitialize === 0 ) { + loadAsyncDependencies(); + } + // ... otherwise initialize plugins + else { - for( var i in plugins ) { + var afterPlugInitialized = function() { + if( --pluginsToInitialize === 0 ) { + loadAsyncDependencies(); + } + }; - var plugin = plugins[i]; + for( var i in plugins ) { - // If the plugin has an 'init' method, invoke it - if( typeof plugin.init === 'function' ) { - var callback = plugin.init(); + var plugin = plugins[i]; - // If the plugin returned a Promise, wait for it - if( callback && typeof callback.then === 'function' ) { - callback.then( afterPlugInitialized ); + // If the plugin has an 'init' method, invoke it + if( typeof plugin.init === 'function' ) { + var callback = plugin.init(); + + // If the plugin returned a Promise, wait for it + if( callback && typeof callback.then === 'function' ) { + callback.then( afterPlugInitialized ); + } + else { + afterPlugInitialized(); + } } else { afterPlugInitialized(); } - } - else { - afterPlugInitialized(); + } }