Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 56 additions & 42 deletions js/index.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,72 @@
import Deck, { VERSION } from './reveal.js'
import Deck, { VERSION } from './reveal.js';

/**
* Expose the Reveal class to the window. To create a
* new instance:
* let deck = new Reveal( document.querySelector( '.reveal' ), {
* controls: false
* } );
* deck.initialize().then(() => {
* // reveal.js is ready
* });
* Expose the Reveal class as a backward-compatible singleton.
* Usage (legacy API):
* Reveal.initialize({ controls: false }).then(() => {
* // reveal.js is ready
* });
* Usage (modern API):
* let deck = new Reveal(document.querySelector('.reveal'), {
* controls: false
* });
* deck.initialize().then(() => {
* // reveal.js is ready
* });
*/
let Reveal = Deck;

let singletonInstance = null;
const enqueuedAPICalls = [];

/**
* The below is a thin shell that mimics the pre 4.0
* reveal.js API and ensures backwards compatibility.
* This API only allows for one Reveal instance per
* page, whereas the new API above lets you run many
* presentations on the same page.
*
* Reveal.initialize( { controls: false } ).then(() => {
* // reveal.js is ready
* });
*/

let enqueuedAPICalls = [];
// Compatibility wrapper for the legacy API
const Reveal = function (...args) {
// Modern API: Create a new Deck instance if called as a constructor
// This is rarely used in the legacy setting, but kept for completeness
return new Deck(...args);
};

// Attach the initialize method for legacy compatibility
Reveal.initialize = options => {
// Prevent multiple initializations
if (singletonInstance) {
return singletonInstance.initialize();
}
// Create the singleton Deck instance on the first call
singletonInstance = new Deck(document.querySelector('.reveal'), options);

// Create our singleton reveal.js instance
Object.assign( Reveal, new Deck( document.querySelector( '.reveal' ), options ) );
// Attach all Deck instance methods to Reveal for compatibility
Object.getOwnPropertyNames(Deck.prototype).forEach(method => {
if (typeof singletonInstance[method] === 'function' && !Reveal[method]) {
Reveal[method] = singletonInstance[method].bind(singletonInstance);
}
});

// Invoke any enqueued API calls
enqueuedAPICalls.map( method => method( Reveal ) );
// Invoke any queued API calls
enqueuedAPICalls.forEach(method => method(singletonInstance));

return Reveal.initialize();

}
return singletonInstance.initialize();
};

/**
* The pre 4.0 API let you add event listener before
* initializing. We maintain the same behavior by
* queuing up premature API calls and invoking all
* of them when Reveal.initialize is called.
* The pre-4.0 API let you add event listeners and call certain methods
* before Reveal was initialized. To maintain this, we queue up those
* calls and run them after initialization.
*/
[ 'configure', 'on', 'off', 'addEventListener', 'removeEventListener', 'registerPlugin' ].forEach( method => {
Reveal[method] = ( ...args ) => {
enqueuedAPICalls.push( deck => deck[method].call( null, ...args ) );
}
} );

Reveal.isReady = () => false;
[
'configure',
'on',
'off',
'addEventListener',
'removeEventListener',
'registerPlugin'
].forEach(method => {
Reveal[method] = (...args) => {
enqueuedAPICalls.push(deck => deck[method](...args));
};
});

// For legacy API compatibility
Reveal.isReady = () => !!singletonInstance && singletonInstance.isReady();
Reveal.VERSION = VERSION;

export default Reveal;
export default Reveal;