* 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
( plugins, dependencies )
| 33 | * will load after reveal.js has been started up. |
| 34 | */ |
| 35 | load( plugins, dependencies ) { |
| 36 | |
| 37 | this.state = 'loading'; |
| 38 | |
| 39 | plugins.forEach( this.registerPlugin.bind( this ) ); |
| 40 | |
| 41 | return new Promise( resolve => { |
| 42 | |
| 43 | let scripts = [], |
| 44 | scriptsToLoad = 0; |
| 45 | |
| 46 | dependencies.forEach( s => { |
| 47 | // Load if there's no condition or the condition is truthy |
| 48 | if( !s.condition || s.condition() ) { |
| 49 | if( s.async ) { |
| 50 | this.asyncDependencies.push( s ); |
| 51 | } |
| 52 | else { |
| 53 | scripts.push( s ); |
| 54 | } |
| 55 | } |
| 56 | } ); |
| 57 | |
| 58 | if( scripts.length ) { |
| 59 | scriptsToLoad = scripts.length; |
| 60 | |
| 61 | const scriptLoadedCallback = (s) => { |
| 62 | if( s && typeof s.callback === 'function' ) s.callback(); |
| 63 | |
| 64 | if( --scriptsToLoad === 0 ) { |
| 65 | this.initPlugins().then( resolve ); |
| 66 | } |
| 67 | }; |
| 68 | |
| 69 | // Load synchronous scripts |
| 70 | scripts.forEach( s => { |
| 71 | if( typeof s.id === 'string' ) { |
| 72 | this.registerPlugin( s ); |
| 73 | scriptLoadedCallback( s ); |
| 74 | } |
| 75 | else if( typeof s.src === 'string' ) { |
| 76 | loadScript( s.src, () => scriptLoadedCallback(s) ); |
| 77 | } |
| 78 | else { |
| 79 | console.warn( 'Unrecognized plugin format', s ); |
| 80 | scriptLoadedCallback(); |
| 81 | } |
| 82 | } ); |
| 83 | } |
| 84 | else { |
| 85 | this.initPlugins().then( resolve ); |
| 86 | } |
| 87 | |
| 88 | } ); |
| 89 | |
| 90 | } |
| 91 | |
| 92 | /** |
no test coverage detected