changes to plugin api; registerPlugin only accepts plugin instance, instance exposes .id

This commit is contained in:
Hakim El Hattab committed 2020-04-08 13:05:28 +02:00
1 parent 2e8619d300
commit 9522357349
9 files changed
+85 -65

No files matched your search

+10 -8
View File
@@ -466,8 +466,7 @@ You can add your own extensions using the same syntax. The following properties
- **callback**: [optional] Function to execute when the script has loaded - **callback**: [optional] Function to execute when the script has loaded
- **condition**: [optional] Function which must return true for the script to be loaded - **condition**: [optional] Function which must return true for the script to be loaded
You can also include dependencies which are bundled/already present on the page. To include a bundled plugin. replace the `src` property with a plugin `id` and a reference to the `plugin` instance: You can also include dependencies which are bundled/already present on the page. To include a bundled plugin. replace the `src` property with a reference to a `plugin` instance:
- **id**: the id of the plugin
- **plugin**: the plugin instance (see [Plugins](#plugins)) - **plugin**: the plugin instance (see [Plugins](#plugins))
### Ready Event ### Ready Event
@@ -1403,17 +1402,20 @@ Then:
## Plugins ## Plugins
Plugins should register themselves with reveal.js by calling `Reveal.registerPlugin( 'myPluginID', MyPlugin )`. Registered plugin instances can optionally expose an "init" function that reveal.js will call to initialize them. Plugins should register themselves with reveal.js by calling `Reveal.registerPlugin( MyPlugin )`. Registered plugins _must_ expose a unique `id` property and can optionally expose an `init` function that reveal.js will call to initialize them.
When reveal.js is booted up via `Reveal.initialize()`, it will go through all registered plugins and invoke their "init" methods. If the "init" method returns a Promise, reveal.js will wait for that promise to be fulfilled before finishing the startup sequence and firing the [ready](#ready-event) event. Here's an example of a plugin that does some asynchronous work before reveal.js can proceed: When reveal.js is booted up via `initialize()`, it will go through all registered plugins and invoke their `init` methods. If the `init` method returns a Promise, reveal.js will wait for that promise to be fulfilled before finishing the startup sequence and firing the [ready](#ready-event) event. Here's an example of a plugin that does some asynchronous work before reveal.js can proceed:
```javascript ```javascript
let MyPlugin = { let MyPlugin = {
init: () => new Promise( resolve => setTimeout( resolve, 3000 ) ) id: 'myPlugin',
init: deck => new Promise( resolve => setTimeout( resolve, 3000 ) )
}; };
Reveal.registerPlugin( 'myPlugin', MyPlugin ); Reveal.initialize({
Reveal.on( 'ready', () => console.log( 'Three seconds later...' ) ); dependencies: [ { plugin: MyPlugin } ]
Reveal.initialize(); }).then( () => {
console.log( 'Three seconds later...' )
} );
``` ```
Note that reveal.js will *not* wait for init Promise fulfillment if the plugin is loaded as an [async dependency](#dependencies). If the plugin's init method does _not_ return a Promise, the plugin is considered ready right away and will not hold up the reveal.js startup sequence. Note that reveal.js will *not* wait for init Promise fulfillment if the plugin is loaded as an [async dependency](#dependencies). If the plugin's init method does _not_ return a Promise, the plugin is considered ready right away and will not hold up the reveal.js startup sequence.
+2 -2
View File
@@ -1,8 +1,8 @@
/*! /*!
* reveal.js 4.0.0-dev (Tue Apr 07 2020) * reveal.js 4.0.0-dev (Wed Apr 08 2020)
* https://revealjs.com * https://revealjs.com
* MIT licensed * MIT licensed
* *
* Copyright (C) 2020 Hakim El Hattab, https://hakim.se * Copyright (C) 2020 Hakim El Hattab, https://hakim.se
*/ */
!function(e){var t={};function n(i){if(t[i])return t[i].exports;var a=t[i]={i:i,l:!1,exports:{}};return e[i].call(a.exports,a,a.exports,n),a.l=!0,a.exports}n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)n.d(i,a,function(t){return e[t]}.bind(null,a));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){e.exports=n(1)},function(e,t,n){"use strict";n.r(t);var i=/registerPlugin|registerKeyboardShortcut|addKeyBinding|addEventListener/,a=/fade-(down|up|right|left|out|in-then-out|in-then-semi-out)|semi-fade-out|current-visible|shrink|grow/,r=function(e,t){for(var n in t)e[n]=t[n];return e},o=function(e,t){return Array.from(e.querySelectorAll(t))},s=function(e){if("string"==typeof e){if("null"===e)return null;if("true"===e)return!0;if("false"===e)return!1;if(e.match(/^-?[\d\.]+$/))return parseFloat(e)}return e},l=function(e,t){e.style.transform=t},c=function(e,t){for(var n=e.parentNode;n;){var i=n.matches||n.matchesSelector||n.msMatchesSelector;if(i&&i.call(n,t))return n;n=n.parentNode}return null},u=function(e){var t=document.createElement("style");return t.type="text/css",e&&e.length>0&&(t.styleSheet?t.styleSheet.cssText=e:t.appendChild(document.createTextNode(e))),document.head.appendChild(t),t},d=function(){var e={};for(var t in location.search.replace(/[A-Z0-9]+?=([\w\.%-]*)/gi,(function(t){e[t.split("=").shift()]=t.split("=").pop()})),e){var n=e[t];e[t]=s(unescape(n))}return void 0!==e.dependencies&&delete e.dependencies,e},h=navigator.userAgent,v=document.createElement("div"),f=/(iphone|ipod|ipad|android)/gi.test(h)||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1,g=/chrome/i.test(h)&&!/edge/i.test(h),p=/android/gi.test(h),m="zoom"in v.style&&!f&&(g||/Version\/[\d\.]+.*Safari/.test(h)),y="function"==typeof window.history.replaceState&&!/PhantomJS/.test(h);function b(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}var w=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.Reveal=t,this.startEmbeddedIframe=this.startEmbeddedIframe.bind(this)}var t,n,i;return t=e,(n=[{key:"shouldPreload",value:function(e){var t=this.Reveal.getConfig().preloadIframes;return"boolean"!=typeof t&&(t=e.hasAttribute("data-preload")),t}},{key:"load",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};e.style.display=this.Reveal.getConfig().display,o(e,"img[data-src], video[data-src], audio[data-src], iframe[data-src]").forEach((function(e){("IFRAME"!==e.tagName||t.shouldPreload(e))&&(e.setAttribute("src",e.getAttribute("data-src")),e.setAttribute("data-lazy-loaded",""),e.removeAttribute("data-src"))})),o(e,"video, audio").forEach((function(e){var t=0;o(e,"source[data-src]").forEach((function(e){e.setAttribute("src",e.getAttribute("data-src")),e.removeAttribute("data-src"),e.setAttribute("data-lazy-loaded",""),t+=1})),t>0&&e.load()}));var i=e.slideBackgroundElement;if(i){i.style.display="block";var a=e.slideBackgroundContentElement,r=e.getAttribute("data-background-iframe");if(!1===i.hasAttribute("data-loaded")){i.setAttribute("data-loaded","true");var s=e.getAttribute("data-background-image"),l=e.getAttribute("data-background-video"),c=e.hasAttribute("data-background-video-loop"),u=e.hasAttribute("data-background-video-muted");if(s)a.style.backgroundImage="url("+encodeURI(s)+")";else if(l&&!this.Reveal.isSpeakerNotes()){var d=document.createElement("video");c&&d.setAttribute("loop",""),u&&(d.muted=!0),f&&(d.muted=!0,d.autoplay=!0,d.setAttribute("playsinline","")),l.split(",").forEach((function(e){d.innerHTML+='<source src="'+e+'">'})),a.appendChild(d)}else if(r&&!0!==n.excludeIframes){var h=document.createElement("iframe");h.setAttribute("allowfullscreen",""),h.setAttribute("mozallowfullscreen",""),h.setAttribute("webkitallowfullscreen",""),h.setAttribute("allow","autoplay"),h.setAttribute("data-src",r),h.style.width="100%",h.style.height="100%",h.style.maxHeight="100%",h.style.maxWidth="100%",a.appendChild(h)}}var v=a.querySelector("iframe[data-src]");v&&this.shouldPreload(i)&&!/autoplay=(1|true|yes)/gi.test(r)&&v.getAttribute("src")!==r&&v.setAttribute("src",r)}}},{key:"unload",value:function(e){e.style.display="none";var t=this.Reveal.getSlideBackground(e);t&&(t.style.display="none",o(t,Line truncated !function(e){var t={};function n(i){if(t[i])return t[i].exports;var a=t[i]={i:i,l:!1,exports:{}};return e[i].call(a.exports,a,a.exports,n),a.l=!0,a.exports}n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)n.d(i,a,function(t){return e[t]}.bind(null,a));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){e.exports=n(1)},function(e,t,n){"use strict";n.r(t);var i=/registerPlugin|registerKeyboardShortcut|addKeyBinding|addEventListener/,a=/fade-(down|up|right|left|out|in-then-out|in-then-semi-out)|semi-fade-out|current-visible|shrink|grow/,r=function(e,t){for(var n in t)e[n]=t[n];return e},o=function(e,t){return Array.from(e.querySelectorAll(t))},s=function(e){if("string"==typeof e){if("null"===e)return null;if("true"===e)return!0;if("false"===e)return!1;if(e.match(/^-?[\d\.]+$/))return parseFloat(e)}return e},l=function(e,t){e.style.transform=t},c=function(e,t){for(var n=e.parentNode;n;){var i=n.matches||n.matchesSelector||n.msMatchesSelector;if(i&&i.call(n,t))return n;n=n.parentNode}return null},u=function(e){var t=document.createElement("style");return t.type="text/css",e&&e.length>0&&(t.styleSheet?t.styleSheet.cssText=e:t.appendChild(document.createTextNode(e))),document.head.appendChild(t),t},d=function(){var e={};for(var t in location.search.replace(/[A-Z0-9]+?=([\w\.%-]*)/gi,(function(t){e[t.split("=").shift()]=t.split("=").pop()})),e){var n=e[t];e[t]=s(unescape(n))}return void 0!==e.dependencies&&delete e.dependencies,e},h=navigator.userAgent,v=document.createElement("div"),f=/(iphone|ipod|ipad|android)/gi.test(h)||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1,g=/chrome/i.test(h)&&!/edge/i.test(h),p=/android/gi.test(h),m="zoom"in v.style&&!f&&(g||/Version\/[\d\.]+.*Safari/.test(h)),y="function"==typeof window.history.replaceState&&!/PhantomJS/.test(h);function b(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}var w=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.Reveal=t,this.startEmbeddedIframe=this.startEmbeddedIframe.bind(this)}var t,n,i;return t=e,(n=[{key:"shouldPreload",value:function(e){var t=this.Reveal.getConfig().preloadIframes;return"boolean"!=typeof t&&(t=e.hasAttribute("data-preload")),t}},{key:"load",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};e.style.display=this.Reveal.getConfig().display,o(e,"img[data-src], video[data-src], audio[data-src], iframe[data-src]").forEach((function(e){("IFRAME"!==e.tagName||t.shouldPreload(e))&&(e.setAttribute("src",e.getAttribute("data-src")),e.setAttribute("data-lazy-loaded",""),e.removeAttribute("data-src"))})),o(e,"video, audio").forEach((function(e){var t=0;o(e,"source[data-src]").forEach((function(e){e.setAttribute("src",e.getAttribute("data-src")),e.removeAttribute("data-src"),e.setAttribute("data-lazy-loaded",""),t+=1})),t>0&&e.load()}));var i=e.slideBackgroundElement;if(i){i.style.display="block";var a=e.slideBackgroundContentElement,r=e.getAttribute("data-background-iframe");if(!1===i.hasAttribute("data-loaded")){i.setAttribute("data-loaded","true");var s=e.getAttribute("data-background-image"),l=e.getAttribute("data-background-video"),c=e.hasAttribute("data-background-video-loop"),u=e.hasAttribute("data-background-video-muted");if(s)a.style.backgroundImage="url("+encodeURI(s)+")";else if(l&&!this.Reveal.isSpeakerNotes()){var d=document.createElement("video");c&&d.setAttribute("loop",""),u&&(d.muted=!0),f&&(d.muted=!0,d.autoplay=!0,d.setAttribute("playsinline","")),l.split(",").forEach((function(e){d.innerHTML+='<source src="'+e+'">'})),a.appendChild(d)}else if(r&&!0!==n.excludeIframes){var h=document.createElement("iframe");h.setAttribute("allowfullscreen",""),h.setAttribute("mozallowfullscreen",""),h.setAttribute("webkitallowfullscreen",""),h.setAttribute("allow","autoplay"),h.setAttribute("data-src",r),h.style.width="100%",h.style.height="100%",h.style.maxHeight="100%",h.style.maxWidth="100%",a.appendChild(h)}}var v=a.querySelector("iframe[data-src]");v&&this.shouldPreload(i)&&!/autoplay=(1|true|yes)/gi.test(r)&&v.getAttribute("src")!==r&&v.setAttribute("src",r)}}},{key:"unload",value:function(e){e.style.display="none";var t=this.Reveal.getSlideBackground(e);t&&(t.style.display="none",o(t,Line truncated
+17 -10
View File
@@ -5,7 +5,9 @@ import { loadScript } from '../utils/loader.js'
*/ */
export default class Plugins { export default class Plugins {
constructor() { constructor( reveal ) {
this.Reveal = reveal;
// Flags our current state (idle -> loading -> loaded) // Flags our current state (idle -> loading -> loaded)
this.state = 'idle'; this.state = 'idle';
@@ -58,8 +60,8 @@ export default class Plugins {
// Load synchronous scripts // Load synchronous scripts
scripts.forEach( s => { scripts.forEach( s => {
if( s.id ) { if( s.plugin ) {
this.registerPlugin( s.id, s.plugin ); this.registerPlugin( s.plugin );
scriptLoadedCallback( s ); scriptLoadedCallback( s );
} }
else { else {
@@ -104,7 +106,7 @@ export default class Plugins {
// If the plugin has an 'init' method, invoke it // If the plugin has an 'init' method, invoke it
if( typeof plugin.init === 'function' ) { if( typeof plugin.init === 'function' ) {
let callback = plugin.init(); let callback = plugin.init( this.Reveal );
// If the plugin returned a Promise, wait for it // If the plugin returned a Promise, wait for it
if( callback && typeof callback.then === 'function' ) { if( callback && typeof callback.then === 'function' ) {
@@ -135,9 +137,9 @@ export default class Plugins {
if( this.asyncDependencies.length ) { if( this.asyncDependencies.length ) {
this.asyncDependencies.forEach( s => { this.asyncDependencies.forEach( s => {
if( s.id ) { if( s.plugin ) {
this.registerPlugin( s.id, s.plugin ); this.registerPlugin( s.plugin );
if( typeof s.plugin.init === 'function' ) s.plugin.init(); if( typeof s.plugin.init === 'function' ) s.plugin.init( this.Reveal );
if( typeof s.callback === 'function' ) s.callback(); if( typeof s.callback === 'function' ) s.callback();
} }
else { else {
@@ -157,15 +159,20 @@ export default class Plugins {
* before considering itself ready, as long as the plugin * before considering itself ready, as long as the plugin
* is registered before calling `Reveal.initialize()`. * is registered before calling `Reveal.initialize()`.
*/ */
registerPlugin( id, plugin ) { registerPlugin( plugin ) {
if( this.registeredPlugins[id] === undefined ) { let id = plugin.id;
if( typeof id !== 'string' ) {
console.warn( 'reveal.js: plugin.id is not a string' );
}
else if( this.registeredPlugins[id] === undefined ) {
this.registeredPlugins[id] = plugin; this.registeredPlugins[id] = plugin;
// If a plugin is registered after reveal.js is loaded, // If a plugin is registered after reveal.js is loaded,
// initialize it right away // initialize it right away
if( this.state === 'loaded' && typeof plugin.init === 'function' ) { if( this.state === 'loaded' && typeof plugin.init === 'function' ) {
plugin.init(); plugin.init( this.Reveal );
} }
} }
else { else {
+6 -4
View File
@@ -69,14 +69,16 @@
var RevealHighlight = { var RevealHighlight = {
id: 'highlight',
HIGHLIGHT_STEP_DELIMITER: '|', HIGHLIGHT_STEP_DELIMITER: '|',
HIGHLIGHT_LINE_DELIMITER: ',', HIGHLIGHT_LINE_DELIMITER: ',',
HIGHLIGHT_LINE_RANGE_DELIMITER: '-', HIGHLIGHT_LINE_RANGE_DELIMITER: '-',
init: function() { init: function( deck ) {
// Read the plugin config options and provide fallbacks // Read the plugin config options and provide fallbacks
var config = Reveal.getConfig().highlight || {}; var config = deck.getConfig().highlight || {};
config.highlightOnLoad = typeof config.highlightOnLoad === 'boolean' ? config.highlightOnLoad : true; config.highlightOnLoad = typeof config.highlightOnLoad === 'boolean' ? config.highlightOnLoad : true;
config.escapeHTML = typeof config.escapeHTML === 'boolean' ? config.escapeHTML : true; config.escapeHTML = typeof config.escapeHTML === 'boolean' ? config.escapeHTML : true;
@@ -105,7 +107,7 @@
// If we're printing to PDF, scroll the code highlights of // If we're printing to PDF, scroll the code highlights of
// all blocks in the deck into view at once // all blocks in the deck into view at once
Reveal.on( 'pdf-ready', function() { deck.on( 'pdf-ready', function() {
[].slice.call( document.querySelectorAll( '.reveal pre code[data-line-numbers].current-fragment' ) ).forEach( function( block ) { [].slice.call( document.querySelectorAll( '.reveal pre code[data-line-numbers].current-fragment' ) ).forEach( function( block ) {
RevealHighlight.scrollHighlightedLineIntoView( block, {}, true ); RevealHighlight.scrollHighlightedLineIntoView( block, {}, true );
} ); } );
@@ -416,7 +418,7 @@
} }
Reveal.registerPlugin( 'highlight', RevealHighlight ); Reveal.registerPlugin( RevealHighlight );
return RevealHighlight; return RevealHighlight;
+5 -6
View File
@@ -403,14 +403,13 @@
// API // API
var RevealMarkdown = { var RevealMarkdown = {
id: 'markdown',
/** /**
* Starts processing and converting Markdown within the * Starts processing and converting Markdown within the
* current reveal.js deck. * current reveal.js deck.
*
* @param {function} callback function to invoke once
* we've finished loading and parsing Markdown
*/ */
init: function( callback ) { init: function( deck ) {
if( typeof marked === 'undefined' ) { if( typeof marked === 'undefined' ) {
throw 'The reveal.js Markdown plugin requires marked to be loaded'; throw 'The reveal.js Markdown plugin requires marked to be loaded';
@@ -425,7 +424,7 @@
} }
// marked can be configured via reveal.js config options // marked can be configured via reveal.js config options
var options = Reveal.getConfig().markdown; var options = deck.getConfig().markdown;
if( options ) { if( options ) {
marked.setOptions( options ); marked.setOptions( options );
} }
@@ -443,7 +442,7 @@
// Register our plugin so that reveal.js will call our // Register our plugin so that reveal.js will call our
// plugin 'init' method as part of the initialization // plugin 'init' method as part of the initialization
Reveal.registerPlugin( 'markdown', RevealMarkdown ); Reveal.registerPlugin( RevealMarkdown );
return RevealMarkdown; return RevealMarkdown;
+6 -4
View File
@@ -60,7 +60,9 @@ var RevealMath = window.RevealMath || (function(){
} }
return { return {
init: function() { id: 'math',
init: function( deck ) {
defaults( options, defaultOptions ); defaults( options, defaultOptions );
defaults( options.tex2jax, defaultOptions.tex2jax ); defaults( options.tex2jax, defaultOptions.tex2jax );
@@ -73,10 +75,10 @@ var RevealMath = window.RevealMath || (function(){
// Typeset followed by an immediate reveal.js layout since // Typeset followed by an immediate reveal.js layout since
// the typesetting process could affect slide height // the typesetting process could affect slide height
MathJax.Hub.Queue( [ 'Typeset', MathJax.Hub ] ); MathJax.Hub.Queue( [ 'Typeset', MathJax.Hub ] );
MathJax.Hub.Queue( Reveal.layout ); MathJax.Hub.Queue( deck.layout );
// Reprocess equations in slides when they turn visible // Reprocess equations in slides when they turn visible
Reveal.on( 'slidechanged', function( event ) { deck.on( 'slidechanged', function( event ) {
MathJax.Hub.Queue( [ 'Typeset', MathJax.Hub, event.currentSlide ] ); MathJax.Hub.Queue( [ 'Typeset', MathJax.Hub, event.currentSlide ] );
@@ -89,4 +91,4 @@ var RevealMath = window.RevealMath || (function(){
})(); })();
Reveal.registerPlugin( 'math', RevealMath ); Reveal.registerPlugin( RevealMath );
+20 -14
View File
@@ -13,6 +13,8 @@ var RevealNotes = (function() {
var notesPopup = null; var notesPopup = null;
var deck;
function openNotes( notesFilePath ) { function openNotes( notesFilePath ) {
if (notesPopup && !notesPopup.closed) { if (notesPopup && !notesPopup.closed) {
@@ -46,7 +48,7 @@ var RevealNotes = (function() {
namespace: 'reveal-notes', namespace: 'reveal-notes',
type: 'connect', type: 'connect',
url: window.location.protocol + '//' + window.location.host + window.location.pathname + window.location.search, url: window.location.protocol + '//' + window.location.host + window.location.pathname + window.location.search,
state: Reveal.getState() state: deck.getState()
} ), '*' ); } ), '*' );
}, 500 ); }, 500 );
@@ -68,7 +70,7 @@ var RevealNotes = (function() {
*/ */
function callRevealApi( methodName, methodArguments, callId ) { function callRevealApi( methodName, methodArguments, callId ) {
var result = Reveal[methodName].apply( Reveal, methodArguments ); var result = deck[methodName].apply( deck, methodArguments );
notesPopup.postMessage( JSON.stringify( { notesPopup.postMessage( JSON.stringify( {
namespace: 'reveal-notes', namespace: 'reveal-notes',
type: 'return', type: 'return',
@@ -83,7 +85,7 @@ var RevealNotes = (function() {
*/ */
function post( event ) { function post( event ) {
var slideElement = Reveal.getCurrentSlide(), var slideElement = deck.getCurrentSlide(),
notesElement = slideElement.querySelector( 'aside.notes' ), notesElement = slideElement.querySelector( 'aside.notes' ),
fragmentElement = slideElement.querySelector( '.current-fragment' ); fragmentElement = slideElement.querySelector( '.current-fragment' );
@@ -93,7 +95,7 @@ var RevealNotes = (function() {
notes: '', notes: '',
markdown: false, markdown: false,
whitespace: 'normal', whitespace: 'normal',
state: Reveal.getState() state: deck.getState()
}; };
// Look for notes defined in a slide attribute // Look for notes defined in a slide attribute
@@ -134,13 +136,13 @@ var RevealNotes = (function() {
function onConnected() { function onConnected() {
// Monitor events that trigger a change in state // Monitor events that trigger a change in state
Reveal.on( 'slidechanged', post ); deck.on( 'slidechanged', post );
Reveal.on( 'fragmentshown', post ); deck.on( 'fragmentshown', post );
Reveal.on( 'fragmenthidden', post ); deck.on( 'fragmenthidden', post );
Reveal.on( 'overviewhidden', post ); deck.on( 'overviewhidden', post );
Reveal.on( 'overviewshown', post ); deck.on( 'overviewshown', post );
Reveal.on( 'paused', post ); deck.on( 'paused', post );
Reveal.on( 'resumed', post ); deck.on( 'resumed', post );
// Post the initial state // Post the initial state
post(); post();
@@ -152,7 +154,11 @@ var RevealNotes = (function() {
} }
return { return {
init: function() { id: 'notes',
init: function( revealInstance ) {
deck = revealInstance;
if( !/receiver/i.test( window.location.search ) ) { if( !/receiver/i.test( window.location.search ) ) {
@@ -162,7 +168,7 @@ var RevealNotes = (function() {
} }
// Open the notes when the 's' key is hit // Open the notes when the 's' key is hit
Reveal.addKeyBinding({keyCode: 83, key: 'S', description: 'Speaker notes view'}, function() { deck.addKeyBinding({keyCode: 83, key: 'S', description: 'Speaker notes view'}, function() {
openNotes(); openNotes();
} ); } );
@@ -175,4 +181,4 @@ var RevealNotes = (function() {
})(); })();
Reveal.registerPlugin( 'notes', RevealNotes ); Reveal.registerPlugin( RevealNotes );
+8 -6
View File
@@ -2,15 +2,17 @@
var RevealZoom = (function(){ var RevealZoom = (function(){
return { return {
init: function() { id: 'zoom',
Reveal.getRevealElement().addEventListener( 'mousedown', function( event ) { init: function( reveal ) {
reveal.getRevealElement().addEventListener( 'mousedown', function( event ) {
var defaultModifier = /Linux/.test( window.navigator.platform ) ? 'ctrl' : 'alt'; var defaultModifier = /Linux/.test( window.navigator.platform ) ? 'ctrl' : 'alt';
var modifier = ( Reveal.getConfig().zoomKey ? Reveal.getConfig().zoomKey : defaultModifier ) + 'Key'; var modifier = ( reveal.getConfig().zoomKey ? reveal.getConfig().zoomKey : defaultModifier ) + 'Key';
var zoomLevel = ( Reveal.getConfig().zoomLevel ? Reveal.getConfig().zoomLevel : 2 ); var zoomLevel = ( reveal.getConfig().zoomLevel ? reveal.getConfig().zoomLevel : 2 );
if( event[ modifier ] && !Reveal.isOverview() ) { if( event[ modifier ] && !reveal.isOverview() ) {
event.preventDefault(); event.preventDefault();
zoom.to({ zoom.to({
@@ -27,7 +29,7 @@ var RevealZoom = (function(){
})(); })();
Reveal.registerPlugin( 'zoom', RevealZoom ); Reveal.registerPlugin( RevealZoom );
/*! /*!
* zoom.js 0.3 (modified for use with reveal.js) * zoom.js 0.3 (modified for use with reveal.js)
+11 -11
View File
@@ -34,15 +34,15 @@
var initCounter = { PluginB: 0, PluginC: 0, PluginD: 0 }; var initCounter = { PluginB: 0, PluginC: 0, PluginD: 0 };
// Plugin with no init method // Plugin with no init method
var PluginA = {}; var PluginA = { id: 'PluginA' };
// Plugin with init method // Plugin with init method
var PluginB = { init: function() { var PluginB = { id: 'PluginB', init: function() {
initCounter['PluginB'] += 1; initCounter['PluginB'] += 1;
} }; } };
// Async plugin with init method // Async plugin with init method
var PluginC = { init: function() { var PluginC = { id: 'PluginC', init: function() {
return new Promise(function( resolve ) { return new Promise(function( resolve ) {
setTimeout( () => { setTimeout( () => {
initCounter['PluginC'] += 1; initCounter['PluginC'] += 1;
@@ -52,24 +52,24 @@
} }; } };
// Plugin initialized after reveal.js is ready // Plugin initialized after reveal.js is ready
var PluginD = { init: function() { var PluginD = { id: 'PluginD', init: function() {
initCounter['PluginD'] += 1; initCounter['PluginD'] += 1;
} }; } };
var PluginE = {}; var PluginE = { id: 'PluginE' };
var reveal = new Reveal( document.querySelector( '.reveal' ) ); var reveal = new Reveal( document.querySelector( '.reveal' ) );
reveal.registerPlugin( 'PluginA', PluginA ); reveal.registerPlugin( PluginA );
reveal.registerPlugin( 'PluginB', PluginB ); reveal.registerPlugin( PluginB );
reveal.registerPlugin( 'PluginC', PluginC ); reveal.registerPlugin( PluginC );
reveal.initialize(); reveal.initialize();
QUnit.test( 'Can initialize synchronously', function( assert ) { QUnit.test( 'Can initialize synchronously', function( assert ) {
assert.strictEqual( initCounter['PluginB'], 1 ); assert.strictEqual( initCounter['PluginB'], 1 );
reveal.registerPlugin( 'PluginB', PluginB ); reveal.registerPlugin( PluginB );
assert.strictEqual( initCounter['PluginB'], 1, 'prevents duplicate registration' ); assert.strictEqual( initCounter['PluginB'], 1, 'prevents duplicate registration' );
}); });
@@ -84,7 +84,7 @@
assert.strictEqual( initCounter['PluginC'], 1, 'finsihed initializing when reveal.js dispatches "ready"' ); assert.strictEqual( initCounter['PluginC'], 1, 'finsihed initializing when reveal.js dispatches "ready"' );
done(); done();
reveal.registerPlugin( 'PluginD', PluginD ); reveal.registerPlugin( PluginD );
assert.strictEqual( initCounter['PluginD'], 1, 'plugin registered after reveal.js is ready still initiailizes' ); assert.strictEqual( initCounter['PluginD'], 1, 'plugin registered after reveal.js is ready still initiailizes' );
done(); done();
}); });
@@ -93,7 +93,7 @@
QUnit.test( 'Can check if plugin is registered', function( assert ) { QUnit.test( 'Can check if plugin is registered', function( assert ) {
assert.strictEqual( reveal.hasPlugin( 'PluginA' ), true ); assert.strictEqual( reveal.hasPlugin( 'PluginA' ), true );
assert.strictEqual( reveal.hasPlugin( 'PluginE' ), false ); assert.strictEqual( reveal.hasPlugin( 'PluginE' ), false );
reveal.registerPlugin( 'PluginE', PluginE ); reveal.registerPlugin( PluginE );
assert.strictEqual( reveal.hasPlugin( 'PluginE' ), true ); assert.strictEqual( reveal.hasPlugin( 'PluginE' ), true );
} ); } );