initialize plugins serially
This commit is contained in:
parent
561c3ff443
commit
08f29f08a2
5 changed files with 1270 additions and 869 deletions
2
dist/plugin/markdown.js
vendored
2
dist/plugin/markdown.js
vendored
File diff suppressed because one or more lines are too long
2
dist/reveal.min.js
vendored
2
dist/reveal.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -85,7 +85,8 @@ export default class Plugins {
|
||||||
|
|
||||||
return new Promise( resolve => {
|
return new Promise( resolve => {
|
||||||
|
|
||||||
let pluginsToInitialize = Object.keys( this.registeredPlugins ).length;
|
let pluginValues = Object.values( this.registeredPlugins );
|
||||||
|
let pluginsToInitialize = pluginValues.length;
|
||||||
|
|
||||||
// If there are no plugins, skip this step
|
// If there are no plugins, skip this step
|
||||||
if( pluginsToInitialize === 0 ) {
|
if( pluginsToInitialize === 0 ) {
|
||||||
|
@ -94,23 +95,31 @@ export default class Plugins {
|
||||||
// ... otherwise initialize plugins
|
// ... otherwise initialize plugins
|
||||||
else {
|
else {
|
||||||
|
|
||||||
|
let initNextPlugin;
|
||||||
|
|
||||||
let afterPlugInitialized = () => {
|
let afterPlugInitialized = () => {
|
||||||
if( --pluginsToInitialize === 0 ) {
|
if( --pluginsToInitialize === 0 ) {
|
||||||
this.loadAsync().then( resolve );
|
this.loadAsync().then( resolve );
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
initNextPlugin();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
for( let i in this.registeredPlugins ) {
|
let i = 0;
|
||||||
|
|
||||||
let plugin = this.registeredPlugins[i];
|
// Initialize plugins serially
|
||||||
|
initNextPlugin = () => {
|
||||||
|
|
||||||
|
let plugin = pluginValues[i++];
|
||||||
|
|
||||||
// If the plugin has an 'init' method, invoke it
|
// If the plugin has an 'init' method, invoke it
|
||||||
if( typeof plugin.init === 'function' ) {
|
if( typeof plugin.init === 'function' ) {
|
||||||
let callback = plugin.init( this.Reveal );
|
let promise = plugin.init( this.Reveal );
|
||||||
|
|
||||||
// If the plugin returned a Promise, wait for it
|
// If the plugin returned a Promise, wait for it
|
||||||
if( callback && typeof callback.then === 'function' ) {
|
if( promise && typeof promise.then === 'function' ) {
|
||||||
callback.then( afterPlugInitialized );
|
promise.then( afterPlugInitialized );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
afterPlugInitialized();
|
afterPlugInitialized();
|
||||||
|
@ -122,6 +131,8 @@ export default class Plugins {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initNextPlugin();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} )
|
} )
|
||||||
|
|
2072
package-lock.json
generated
2072
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -15,13 +15,15 @@ export default {
|
||||||
* current reveal.js deck.
|
* current reveal.js deck.
|
||||||
*/
|
*/
|
||||||
init: function( deck ) {
|
init: function( deck ) {
|
||||||
if( typeof window.hljs !== 'undefined' ) {
|
// This should no longer be needed, as long as the highlight.js
|
||||||
marked.setOptions({
|
// plugin is included after the markdown plugin
|
||||||
highlight: function( code, lang ) {
|
// if( typeof window.hljs !== 'undefined' ) {
|
||||||
return window.hljs.highlightAuto( code, lang ? [lang] : null ).value;
|
// marked.setOptions({
|
||||||
}
|
// highlight: function( code, lang ) {
|
||||||
});
|
// return window.hljs.highlightAuto( code, lang ? [lang] : null ).value;
|
||||||
}
|
// }
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
// marked can be configured via reveal.js config options
|
// marked can be configured via reveal.js config options
|
||||||
var options = deck.getConfig().markdown;
|
var options = deck.getConfig().markdown;
|
||||||
|
|
Loading…
Reference in a new issue