index.js 1.4 KB

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