diff options
author | Hakim El Hattab <hakim.elhattab@gmail.com> | 2020-04-21 09:50:19 +0200 |
---|---|---|
committer | Hakim El Hattab <hakim.elhattab@gmail.com> | 2020-04-21 09:50:19 +0200 |
commit | 91953207a55585b85cb9b4e1c28beb839633a4ae (patch) | |
tree | f3a426fc5a41e16c4f379ad41f28a78c226ad4d5 /js | |
parent | d22c7bfad1e97f76815bd3e2b9748c00bb3696c0 (diff) | |
download | fosdem-2021-minimalism-presentation-91953207a55585b85cb9b4e1c28beb839633a4ae.tar fosdem-2021-minimalism-presentation-91953207a55585b85cb9b4e1c28beb839633a4ae.tar.gz |
simplify plugin controller
Diffstat (limited to 'js')
-rw-r--r-- | js/controllers/plugins.js | 26 | ||||
-rw-r--r-- | js/reveal.js | 9 |
2 files changed, 16 insertions, 19 deletions
diff --git a/js/controllers/plugins.js b/js/controllers/plugins.js index 2a21b7d..9a5bb79 100644 --- a/js/controllers/plugins.js +++ b/js/controllers/plugins.js @@ -20,21 +20,24 @@ export default class Plugins { } /** - * Loads reveal.js dependencies and registers plugins. + * Loads reveal.js dependencies, registers and + * initializes plugins. + * + * Plugins are direct references to a reveal.js plugin + * object that we register and initialize after any + * synchronous dependencies have loaded. * * Dependencies are defined via the 'dependencies' config * option and will be loaded prior to starting reveal.js. * Some dependencies may have an 'async' flag, if so they * will load after reveal.js has been started up. - * - * Plugins are direct references to a reveal.js plugin - * object that we register and initialize after any - * synchronous dependencies have loaded. */ - load( dependencies ) { + load( plugins, dependencies ) { this.state = 'loading'; + plugins.forEach( this.registerPlugin.bind( this ) ); + return new Promise( resolve => { let scripts = [], @@ -157,14 +160,7 @@ export default class Plugins { if( this.asyncDependencies.length ) { this.asyncDependencies.forEach( s => { - if( s.plugin ) { - this.registerPlugin( s.plugin ); - if( typeof s.plugin.init === 'function' ) s.plugin.init( this.Reveal ); - if( typeof s.callback === 'function' ) s.callback(); - } - else { - loadScript( s.src, s.callback ); - } + loadScript( s.src, s.callback ); } ); } @@ -184,7 +180,7 @@ export default class Plugins { let id = plugin.id; if( typeof id !== 'string' ) { - console.warn( 'reveal.js: plugin.id is not a string' ); + console.warn( 'Unrecognized plugin format; can\'t find plugin.id', plugin ); } else if( this.registeredPlugins[id] === undefined ) { this.registeredPlugins[id] = plugin; diff --git a/js/reveal.js b/js/reveal.js index 1b4c84f..ad47bfd 100644 --- a/js/reveal.js +++ b/js/reveal.js @@ -33,8 +33,9 @@ import { */ export default function( revealElement, options ) { - // Support initialization with only options - if( arguments.length === 1 ) { + // Support initialization with no args, one arg + // [options] or two args [revealElement, options] + if( arguments.length < 2 ) { options = arguments[0]; revealElement = document.querySelector( '.reveal' ); } @@ -136,8 +137,8 @@ export default function( revealElement, options ) { // Force a layout when the whole page, incl fonts, has loaded window.addEventListener( 'load', layout, false ); - // Load plugins then move on to #start() - plugins.load( [...config.dependencies, ...config.plugins] ).then( start ); + // Register plugins and load dependencies, then move on to #start() + plugins.load( config.plugins, config.dependencies ).then( start ); return new Promise( resolve => Reveal.on( 'ready', resolve ) ); |