plugin api docs

This commit is contained in:
Hakim El Hattab 2019-04-01 15:11:51 +02:00 committed by GitHub
parent 3da09f1fef
commit 25c504c22f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 0 deletions

View File

@ -49,6 +49,7 @@ reveal.js comes with a broad range of features including [nested slides](https:/
- [Speaker Notes](#speaker-notes) - [Speaker Notes](#speaker-notes)
- [Share and Print Speaker Notes](#share-and-print-speaker-notes) - [Share and Print Speaker Notes](#share-and-print-speaker-notes)
- [Server Side Speaker Notes](#server-side-speaker-notes) - [Server Side Speaker Notes](#server-side-speaker-notes)
- [Plugins](#plugins)
- [Multiplexing](#multiplexing) - [Multiplexing](#multiplexing)
- [Master presentation](#master-presentation) - [Master presentation](#master-presentation)
- [Client presentation](#client-presentation) - [Client presentation](#client-presentation)
@ -1205,6 +1206,29 @@ Then:
3. Run `node plugin/notes-server` 3. Run `node plugin/notes-server`
## Plugins
Plugins should be registered with reveal.js by calling `Reveal.registerPlugin( 'myPluginID', MyPlugin )`. Registered plugin instances should expose an "init" function that reveal.js can call to initialize them.
When reveal.js is booted up via `Reveal.initialize()`, it will go through all registered plugins and invoke their "init" methods. If the "init" method returns a Promise, reveal.js will wait for that promise to be fullfilled before finshing the startup sequence and firing the [ready](#ready-event) event. Here's an example of a plugin that returns a promise:
```
Reveal.registerPlugin( 'myPlugin', {
init: () => {
return new Promise( resolve => setTimeout( resolve, 3000 ) );
}
} );
Reveal.addEventListener( 'ready', () => console.log( 'Three seconds later...' ) );
Reveal.initialize();
```
If the init method does _not_ return a Promise, it is considered ready right away and will not hold up the reveal.js startup sequence.
### Retrieving Plugins
If you want to check if a specific plugin is registered you can use the `Reveal.hasPlugin` method and pass in a plugin ID, for example: `Reveal.hasPlugin( 'myPlugin' )`. If you want to retrieve a plugin instance you can use `Reveal.getPlugin( 'myPlugin' )`.
## Multiplexing ## Multiplexing
The multiplex plugin allows your audience to view the slides of the presentation you are controlling on their own phone, tablet or laptop. As the master presentation navigates the slides, all client presentations will update in real time. See a demo at [https://reveal-js-multiplex-ccjbegmaii.now.sh/](https://reveal-js-multiplex-ccjbegmaii.now.sh/). The multiplex plugin allows your audience to view the slides of the presentation you are controlling on their own phone, tablet or laptop. As the master presentation navigates the slides, all client presentations will update in real time. See a demo at [https://reveal-js-multiplex-ccjbegmaii.now.sh/](https://reveal-js-multiplex-ccjbegmaii.now.sh/).