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

This commit is contained in:
Hakim El Hattab 2020-04-17 09:47:03 +02:00
parent 08f29f08a2
commit d9690462e0
20 changed files with 44 additions and 72 deletions

View File

@ -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();

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2
dist/plugin/math.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

6
dist/plugin/zoom.js vendored

File diff suppressed because one or more lines are too long

4
dist/reveal.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -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' }, { name: 'RevealHighlight', input: './plugin/highlight/highlight.js', output: './dist/plugin/highlight.js' },
{ input: './plugin/markdown/markdown.es5', output: './dist/plugin/markdown.js' }, { name: 'RevealMarkdown', input: './plugin/markdown/markdown.js', output: './dist/plugin/markdown.js' },
{ input: './plugin/search/search.es5', output: './dist/plugin/search.js' }, { name: 'RevealSearch', input: './plugin/search/search.js', output: './dist/plugin/search.js' },
{ input: './plugin/notes/notes.es5', output: './dist/plugin/notes.js' }, { name: 'RevealNotes', input: './plugin/notes/notes.js', output: './dist/plugin/notes.js' },
{ input: './plugin/zoom/zoom.es5', output: './dist/plugin/zoom.js' }, { name: 'RevealZoom', input: './plugin/zoom/zoom.js', output: './dist/plugin/zoom.js' },
{ input: './plugin/math/math.es5', output: './dist/plugin/math.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'
}) })
}); });

View File

@ -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: [ plugins: [ RevealMarkdown, RevealHighlight, RevealNotes ]
{ src: 'dist/plugin/markdown.js' },
{ src: 'dist/plugin/highlight.js' },
{ src: 'dist/plugin/notes.js' }
]
}); });
</script> </script>
</body> </body>

View File

@ -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: []
} }

View File

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

View File

@ -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 ) );

View File

@ -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 );

View File

@ -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 );

View File

@ -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 );

View File

@ -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 );

View File

@ -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 );

View File

@ -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.
* *

View File

@ -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 );