Browse Source

add 'plugins' config option, new way of registering es5 plugins

Hakim El Hattab 5 năm trước cách đây
mục cha
commit
d9690462e0

+ 1 - 1
demo.html

@@ -429,7 +429,7 @@ Reveal.on( 'customevent', function() {
 				transition: 'slide', // none/fade/slide/convex/concave/zoom
 				transition: 'slide', // none/fade/slide/convex/concave/zoom
 
 
 				// More info https://github.com/hakimel/reveal.js#dependencies
 				// More info https://github.com/hakimel/reveal.js#dependencies
-				dependencies: [ Zoom, Notes, Search, Markdown, Highlight ]
+				plugins: [ Zoom, Notes, Search, Markdown, Highlight ]
 			});
 			});
 
 
 			deck.initialize();
 			deck.initialize();

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 1 - 1
dist/plugin/highlight.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist/plugin/markdown.js


+ 1 - 1
dist/plugin/math.js

@@ -1 +1 @@
-!function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";var e=function(){var e=Reveal.getConfig().math||{},t=(e.mathjax||"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js")+"?config="+(e.config||"TeX-AMS_HTML-full"),a={messageStyle:"none",tex2jax:{inlineMath:[["$","$"],["\\(","\\)"]],skipTags:["script","noscript","style","textarea","pre"]},skipStartupTypeset:!0};function n(e,t){for(var a in t)e.hasOwnProperty(a)||(e[a]=t[a])}return{id:"math",init:function(i){n(e,a),n(e.tex2jax,a.tex2jax),e.mathjax=e.config=null,function(e,t){var a=document.querySelector("head"),n=document.createElement("script");n.type="text/javascript",n.src=e;var i=function(){"function"==typeof t&&(t.call(),t=null)};n.onload=i,n.onreadystatechange=function(){"loaded"===this.readyState&&i()},a.appendChild(n)}(t,(function(){MathJax.Hub.Config(e),MathJax.Hub.Queue(["Typeset",MathJax.Hub]),MathJax.Hub.Queue(i.layout),i.on("slidechanged",(function(e){MathJax.Hub.Queue(["Typeset",MathJax.Hub,e.currentSlide])}))}))}}}();Reveal.registerPlugin(e)}));
+!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).RevealMath=t()}(this,(function(){"use strict";return function(){var e=Reveal.getConfig().math||{},t=(e.mathjax||"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js")+"?config="+(e.config||"TeX-AMS_HTML-full"),a={messageStyle:"none",tex2jax:{inlineMath:[["$","$"],["\\(","\\)"]],skipTags:["script","noscript","style","textarea","pre"]},skipStartupTypeset:!0};function n(e,t){for(var a in t)e.hasOwnProperty(a)||(e[a]=t[a])}return{id:"math",init:function(o){n(e,a),n(e.tex2jax,a.tex2jax),e.mathjax=e.config=null,function(e,t){var a=document.querySelector("head"),n=document.createElement("script");n.type="text/javascript",n.src=e;var o=function(){"function"==typeof t&&(t.call(),t=null)};n.onload=o,n.onreadystatechange=function(){"loaded"===this.readyState&&o()},a.appendChild(n)}(t,(function(){MathJax.Hub.Config(e),MathJax.Hub.Queue(["Typeset",MathJax.Hub]),MathJax.Hub.Queue(o.layout),o.on("slidechanged",(function(e){MathJax.Hub.Queue(["Typeset",MathJax.Hub,e.currentSlide])}))}))}}}()}));

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 1
dist/plugin/notes.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist/plugin/search.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 1 - 1
dist/plugin/zoom.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 1 - 1
dist/reveal.min.js


+ 7 - 6
gulpfile.js

@@ -67,12 +67,12 @@ gulp.task('js', () => {
 
 
 gulp.task('plugins', () => {
 gulp.task('plugins', () => {
     return Promise.all([
     return Promise.all([
-        { input: './plugin/highlight/highlight.es5', output: './dist/plugin/highlight.js' },
-        { input: './plugin/markdown/markdown.es5', output: './dist/plugin/markdown.js' },
-        { input: './plugin/search/search.es5', output: './dist/plugin/search.js' },
-        { input: './plugin/notes/notes.es5', output: './dist/plugin/notes.js' },
-        { input: './plugin/zoom/zoom.es5', output: './dist/plugin/zoom.js' },
-        { input: './plugin/math/math.es5', output: './dist/plugin/math.js' }
+        { name: 'RevealHighlight', input: './plugin/highlight/highlight.js', output: './dist/plugin/highlight.js' },
+        { name: 'RevealMarkdown', input: './plugin/markdown/markdown.js', output: './dist/plugin/markdown.js' },
+        { name: 'RevealSearch', input: './plugin/search/search.js', output: './dist/plugin/search.js' },
+        { name: 'RevealNotes', input: './plugin/notes/notes.js', output: './dist/plugin/notes.js' },
+        { name: 'RevealZoom', input: './plugin/zoom/zoom.js', output: './dist/plugin/zoom.js' },
+        { name: 'RevealMath', input: './plugin/math/math.js', output: './dist/plugin/math.js' }
     ].map( plugin => {
     ].map( plugin => {
         return rollup({
         return rollup({
                 input: plugin.input,
                 input: plugin.input,
@@ -80,6 +80,7 @@ gulp.task('plugins', () => {
             }).then( bundle => {
             }).then( bundle => {
                 return bundle.write({
                 return bundle.write({
                     file: plugin.output,
                     file: plugin.output,
+                    name: plugin.name,
                     format: 'umd'
                     format: 'umd'
                 })
                 })
             });
             });

+ 4 - 5
index.html

@@ -22,17 +22,16 @@
 		</div>
 		</div>
 
 
 		<script src="dist/reveal.min.js"></script>
 		<script src="dist/reveal.min.js"></script>
+		<script src="dist/plugin/markdown.js"></script>
+		<script src="dist/plugin/highlight.js"></script>
+		<script src="dist/plugin/notes.js"></script>
 		<script>
 		<script>
 			// More info about config & dependencies:
 			// More info about config & dependencies:
 			// - https://github.com/hakimel/reveal.js#configuration
 			// - https://github.com/hakimel/reveal.js#configuration
 			// - https://github.com/hakimel/reveal.js#dependencies
 			// - https://github.com/hakimel/reveal.js#dependencies
 			Reveal.initialize({
 			Reveal.initialize({
 				hash: true,
 				hash: true,
-				dependencies: [
-					{ src: 'dist/plugin/markdown.js' },
-					{ src: 'dist/plugin/highlight.js' },
-					{ src: 'dist/plugin/notes.js' }
-				]
+				plugins: [ RevealMarkdown, RevealHighlight, RevealNotes ]
 			});
 			});
 		</script>
 		</script>
 	</body>
 	</body>

+ 4 - 1
js/config.js

@@ -276,6 +276,9 @@ export default {
 	hideCursorTime: 5000,
 	hideCursorTime: 5000,
 
 
 	// Script dependencies to load
 	// Script dependencies to load
-	dependencies: []
+	dependencies: [],
+
+	// Plugin objects to register and use for this presentation
+	plugins: []
 
 
 }
 }

+ 8 - 3
js/controllers/plugins.js

@@ -20,11 +20,16 @@ export default class Plugins {
 	}
 	}
 
 
 	/**
 	/**
-	 * Loads the dependencies of reveal.js. Dependencies are
-	 * defined via the configuration option 'dependencies'
-	 * and will be loaded prior to starting/binding reveal.js.
+	 * Loads reveal.js dependencies and registers plugins.
+	 *
+	 * 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
 	 * 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( dependencies ) {
 
 

+ 1 - 1
js/reveal.js

@@ -145,7 +145,7 @@ export default function( revealElement, options ) {
 		window.addEventListener( 'load', layout, false );
 		window.addEventListener( 'load', layout, false );
 
 
 		// Load plugins then move on to #start()
 		// Load plugins then move on to #start()
-		plugins.load( config.dependencies ).then( start );
+		plugins.load( [...config.dependencies, ...config.plugins] ).then( start );
 
 
 		return new Promise( resolve => Reveal.on( 'ready', resolve ) );
 		return new Promise( resolve => Reveal.on( 'ready', resolve ) );
 
 

+ 0 - 7
plugin/highlight/highlight.es5

@@ -1,7 +0,0 @@
-/**
- * This is used to compile a self-registering
- * es5 compatible version of the plugin.
- */
-
-import plugin from './highlight.js'
-Reveal.registerPlugin( plugin );

+ 0 - 7
plugin/markdown/markdown.es5

@@ -1,7 +0,0 @@
-/**
- * This is used to compile a self-registering
- * es5 compatible version of the plugin.
- */
-
-import plugin from './markdown.js'
-Reveal.registerPlugin( plugin );

+ 0 - 7
plugin/math/math.es5

@@ -1,7 +0,0 @@
-/**
- * This is used to compile a self-registering
- * es5 compatible version of the plugin.
- */
-
-import plugin from './math.js'
-Reveal.registerPlugin( plugin );

+ 0 - 7
plugin/notes/notes.es5

@@ -1,7 +0,0 @@
-/**
- * This is used to compile a self-registering
- * es5 compatible version of the plugin.
- */
-
-import plugin from './notes.js'
-Reveal.registerPlugin( plugin );

+ 0 - 7
plugin/search/search.es5

@@ -1,7 +0,0 @@
-/**
- * This is used to compile a self-registering
- * es5 compatible version of the plugin.
- */
-
-import plugin from './search.js'
-Reveal.registerPlugin( plugin );

+ 1 - 1
plugin/search/search.js

@@ -1,4 +1,4 @@
-/*
+/*!
  * Handles finding a text string anywhere in the slides and showing the next occurrence to the user
  * Handles finding a text string anywhere in the slides and showing the next occurrence to the user
  * by navigatating to that slide and highlighting it.
  * by navigatating to that slide and highlighting it.
  *
  *

+ 0 - 7
plugin/zoom/zoom.es5

@@ -1,7 +0,0 @@
-/**
- * This is used to compile a self-registering
- * es5 compatible version of the plugin.
- */
-
-import plugin from './zoom.js'
-Reveal.registerPlugin( plugin );

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác