blob: 57be501ef1f9bf544d5cc4ec78225ebe6dcc36be [file] [log] [blame]
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +02001import Deck, { VERSION } from './reveal.js'
2
3/**
4 * Expose the Reveal class to the window. To create a
5 * new instance:
6 * let deck = new Reveal( document.querySelector( '.reveal' ), {
7 * controls: false
8 * } );
9 * deck.initialize().then(() => {
10 * // reveal.js is ready
11 * });
12 */
13let Reveal = Deck;
14
15
16/**
17 * The below is a thin shell that mimics the pre 4.0
18 * reveal.js API and ensures backwards compatibility.
19 * This API only allows for one Reveal instance per
20 * page, whereas the new API above lets you run many
21 * presentations on the same page.
22 *
23 * Reveal.initialize( { controls: false } ).then(() => {
24 * // reveal.js is ready
25 * });
26 */
27
28let enqueuedAPICalls = [];
29
30Reveal.initialize = options => {
31
32 // Create our singleton reveal.js instance
33 Object.assign( Reveal, new Deck( document.querySelector( '.reveal' ), options ) );
34
35 // Invoke any enqueued API calls
36 enqueuedAPICalls.map( method => method( Reveal ) );
37
38 return Reveal.initialize();
39
40}
41
42/**
43 * The pre 4.0 API let you add event listener before
44 * initializing. We maintain the same behavior by
45 * queuing up premature API calls and invoking all
46 * of them when Reveal.initialize is called.
47 */
48[ 'configure', 'on', 'off', 'addEventListener', 'removeEventListener', 'registerPlugin' ].forEach( method => {
49 Reveal[method] = ( ...args ) => {
50 enqueuedAPICalls.push( deck => deck[method].call( null, ...args ) );
51 }
52} );
53
54Reveal.isReady = () => false;
55
56Reveal.VERSION = VERSION;
57
58export default Reveal;