index.ts 1.6 KB

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