Skip to content

Commit

Permalink
support for plugins where the init method doesn't return a Promise
Browse files Browse the repository at this point in the history
  • Loading branch information
hakimel committed Mar 14, 2019
1 parent 5301a9e commit 6410ed1
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 20 deletions.
29 changes: 17 additions & 12 deletions js/reveal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}

/**
Expand Down
2 changes: 0 additions & 2 deletions plugin/highlight/highlight.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions plugin/math/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ var RevealMath = window.RevealMath || (function(){

} );

return Promise.resolve();

}
}

Expand Down
2 changes: 0 additions & 2 deletions plugin/notes/notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,6 @@ var RevealNotes = (function() {

}

return Promise.resolve();

},

open: openNotes
Expand Down
2 changes: 0 additions & 2 deletions plugin/zoom-js/zoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ var RevealZoom = (function(){
}
} );

return Promise.resolve();

}
}

Expand Down

0 comments on commit 6410ed1

Please sign in to comment.