From 6410ed15aa5ce2bdfc1f7f02c818a562ec8a1fc4 Mon Sep 17 00:00:00 2001 From: Hakim El Hattab Date: Thu, 14 Mar 2019 14:52:59 +0100 Subject: [PATCH] support for plugins where the init method doesn't return a Promise --- js/reveal.js | 29 +++++++++++++++++------------ plugin/highlight/highlight.js | 2 -- plugin/math/math.js | 2 -- plugin/notes/notes.js | 2 -- plugin/zoom-js/zoom.js | 2 -- 5 files changed, 17 insertions(+), 20 deletions(-) diff --git a/js/reveal.js b/js/reveal.js index 1ef10aab..51b1ed03 100644 --- a/js/reveal.js +++ b/js/reveal.js @@ -539,29 +539,34 @@ var pluginsToInitialize = Object.keys( plugins ).length; + var afterPlugInitialized = function() { + if( --pluginsToInitialize === 0 ) { + loadAsyncDependencies(); + } + }; + for( var i in plugins ) { var plugin = plugins[i]; - // If the plugin has an 'init' method, initialize and - // wait for the callback + // If the plugin has an 'init' method, invoke it if( typeof plugin.init === 'function' ) { - plugin.init().then( function() { - if( --pluginsToInitialize === 0 ) { - loadAsyncDependencies(); - } - } ); + 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 { - pluginsToInitialize -= 1; + afterPlugInitialized(); } } - if( pluginsToInitialize === 0 ) { - loadAsyncDependencies(); - } - } /** diff --git a/plugin/highlight/highlight.js b/plugin/highlight/highlight.js index 6d6910b9..b3599e88 100644 --- a/plugin/highlight/highlight.js +++ b/plugin/highlight/highlight.js @@ -97,8 +97,6 @@ c:[{cN:"comment",b:/\(\*/,e:/\*\)/},e.ASM,e.QSM,e.CNM,{b:/\{/,e:/\}/,i:/:/}]}}); } } ); - return Promise.resolve(); - }, /** diff --git a/plugin/math/math.js b/plugin/math/math.js index b78d1209..d76c9dda 100755 --- a/plugin/math/math.js +++ b/plugin/math/math.js @@ -84,8 +84,6 @@ var RevealMath = window.RevealMath || (function(){ } ); - return Promise.resolve(); - } } diff --git a/plugin/notes/notes.js b/plugin/notes/notes.js index 54dcf314..3d5eac4b 100644 --- a/plugin/notes/notes.js +++ b/plugin/notes/notes.js @@ -168,8 +168,6 @@ var RevealNotes = (function() { } - return Promise.resolve(); - }, open: openNotes diff --git a/plugin/zoom-js/zoom.js b/plugin/zoom-js/zoom.js index 031514d9..92c3ba5b 100644 --- a/plugin/zoom-js/zoom.js +++ b/plugin/zoom-js/zoom.js @@ -22,8 +22,6 @@ var RevealZoom = (function(){ } } ); - return Promise.resolve(); - } }