aboutsummaryrefslogtreecommitdiff
path: root/js/index.js
diff options
context:
space:
mode:
authorHakim El Hattab <hakim.elhattab@gmail.com>2020-04-07 09:40:11 +0200
committerHakim El Hattab <hakim.elhattab@gmail.com>2020-04-07 09:40:11 +0200
commit1081bbfc03c36a393c5722de3f770b091f869157 (patch)
treea57d0fb78c71816350170900c2bb7c2f96fc38c9 /js/index.js
parent855cc82d7680bd9d2d99f1d8af9930087bac1326 (diff)
downloadfosdem-2021-minimalism-presentation-1081bbfc03c36a393c5722de3f770b091f869157.tar
fosdem-2021-minimalism-presentation-1081bbfc03c36a393c5722de3f770b091f869157.tar.gz
improvements to legacy API
Diffstat (limited to 'js/index.js')
-rw-r--r--js/index.js52
1 files changed, 45 insertions, 7 deletions
diff --git a/js/index.js b/js/index.js
index 05beb20..99f7028 100644
--- a/js/index.js
+++ b/js/index.js
@@ -1,14 +1,52 @@
import Presentation 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
+ * });
+ */
window.Reveal = Presentation;
-// Provides a backwards compatible way to initialize
-// reveal.js when there is only one presentation on
-// the page.
-//
-// Reveal.initialize({ controls: false })
-// Reveal.slide(2)
+
+/**
+ * The below is a thin shell that mimics the pre 4.0
+ * reveal.js API and ensures backwards compatibility.
+ * This API only allows for once 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 = [];
+
window.Reveal.initialize = options => {
+
+ // Create our singleton reveal.js instance
window.Reveal = new Presentation( document.querySelector( '.reveal' ), options );
+
+ // Invoke any enqueued API calls
+ enqueuedAPICalls.map( method => method( window.Reveal ) );
+
return window.Reveal.initialize();
-} \ No newline at end of file
+
+}
+
+/**
+ * The pre 4.0 API let you add event listener before
+ * initializing. We maintain the same behavior by
+ * queuing up early API calls and invoking all of them
+ * when Reveal.initialize is called.
+ */
+[ 'on', 'off', 'addEventListener', 'removeEventListener' ].forEach( method => {
+ window.Reveal[method] = ( ...args ) => {
+ enqueuedAPICalls.push( deck => deck[method].call( null, ...args ) );
+ }
+} ); \ No newline at end of file