reveal.js plugin flow now uses promises, refactor markdown plugin to use promises

This commit is contained in:
Hakim El Hattab
2019-03-04 14:11:21 +01:00
parent 46f8f86fa1
commit d780352b7f
3 changed files with 110 additions and 86 deletions

View File

@ -546,7 +546,7 @@
// If the plugin has an 'init' method, initialize and
// wait for the callback
if( typeof plugin.init === 'function' ) {
plugin.init( function() {
plugin.init().then( function() {
if( --pluginsToInitialize === 0 ) {
loadAsyncDependencies();
}
@ -1551,11 +1551,21 @@
/**
* Registers a new plugin with this reveal.js instance.
*
* reveal.js waits for all regisered plugins to initialize
* before considering itself ready, as long as the plugin
* is registered before calling `Reveal.initialize()`.
*/
function registerPlugin( id, plugin ) {
plugins[id] = plugin;
// If a plugin is registered after reveal.js is loaded,
// initialize it right away
if( loaded && typeof plugin.init === 'function' ) {
plugin.init();
}
}
/**
@ -5841,6 +5851,11 @@
return dom.wrapper || document.querySelector( '.reveal' );
},
// Returns a hash with all registered plugins
getPlugins: function() {
return plugins;
},
// Returns true if we're currently on the first slide
isFirstSlide: function() {
return ( indexh === 0 && indexv === 0 );