浏览代码

simplify plugin controller

Hakim El Hattab 5 年之前
父节点
当前提交
91953207a5
共有 6 个文件被更改,包括 16 次插入19 次删除
  1. 0 0
      dist/reveal.es5.js
  2. 0 0
      dist/reveal.es5.js.map
  3. 0 0
      dist/reveal.js
  4. 0 0
      dist/reveal.js.map
  5. 11 15
      js/controllers/plugins.js
  6. 5 4
      js/reveal.js

文件差异内容过多而无法显示
+ 0 - 0
dist/reveal.es5.js


文件差异内容过多而无法显示
+ 0 - 0
dist/reveal.es5.js.map


文件差异内容过多而无法显示
+ 0 - 0
dist/reveal.js


文件差异内容过多而无法显示
+ 0 - 0
dist/reveal.js.map


+ 11 - 15
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
 	 * Dependencies are defined via the 'dependencies' config
 	 * option and will be loaded prior to starting reveal.js.
 	 * option and will be loaded prior to starting reveal.js.
 	 * Some dependencies may have an 'async' flag, if so they
 	 * Some dependencies may have an 'async' flag, if so they
 	 * will load after reveal.js has been started up.
 	 * 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';
 		this.state = 'loading';
 
 
+		plugins.forEach( this.registerPlugin.bind( this ) );
+
 		return new Promise( resolve => {
 		return new Promise( resolve => {
 
 
 			let scripts = [],
 			let scripts = [],
@@ -157,14 +160,7 @@ export default class Plugins {
 
 
 		if( this.asyncDependencies.length ) {
 		if( this.asyncDependencies.length ) {
 			this.asyncDependencies.forEach( s => {
 			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;
 		let id = plugin.id;
 
 
 		if( typeof id !== 'string' ) {
 		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 ) {
 		else if( this.registeredPlugins[id] === undefined ) {
 			this.registeredPlugins[id] = plugin;
 			this.registeredPlugins[id] = plugin;

+ 5 - 4
js/reveal.js

@@ -33,8 +33,9 @@ import {
  */
  */
 export default function( revealElement, options ) {
 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];
 		options = arguments[0];
 		revealElement = document.querySelector( '.reveal' );
 		revealElement = document.querySelector( '.reveal' );
 	}
 	}
@@ -136,8 +137,8 @@ export default function( revealElement, options ) {
 		// Force a layout when the whole page, incl fonts, has loaded
 		// Force a layout when the whole page, incl fonts, has loaded
 		window.addEventListener( 'load', layout, false );
 		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 ) );
 		return new Promise( resolve => Reveal.on( 'ready', resolve ) );
 
 

部分文件因为文件数量过多而无法显示