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

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

View File

@ -69,14 +69,16 @@
var RevealHighlight = {
id: 'highlight',
HIGHLIGHT_STEP_DELIMITER: '|',
HIGHLIGHT_LINE_DELIMITER: ',',
HIGHLIGHT_LINE_RANGE_DELIMITER: '-',
init: function() {
init: function( deck ) {
// 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.escapeHTML = typeof config.escapeHTML === 'boolean' ? config.escapeHTML : true;
@ -105,7 +107,7 @@
// If we're printing to PDF, scroll the code highlights of
// 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 ) {
RevealHighlight.scrollHighlightedLineIntoView( block, {}, true );
} );
@ -416,7 +418,7 @@
}
Reveal.registerPlugin( 'highlight', RevealHighlight );
Reveal.registerPlugin( RevealHighlight );
return RevealHighlight;

View File

@ -403,14 +403,13 @@
// API
var RevealMarkdown = {
id: 'markdown',
/**
* Starts processing and converting Markdown within the
* 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' ) {
throw 'The reveal.js Markdown plugin requires marked to be loaded';
@ -425,7 +424,7 @@
}
// marked can be configured via reveal.js config options
var options = Reveal.getConfig().markdown;
var options = deck.getConfig().markdown;
if( options ) {
marked.setOptions( options );
}
@ -443,7 +442,7 @@
// Register our plugin so that reveal.js will call our
// plugin 'init' method as part of the initialization
Reveal.registerPlugin( 'markdown', RevealMarkdown );
Reveal.registerPlugin( RevealMarkdown );
return RevealMarkdown;

View File

@ -60,7 +60,9 @@ var RevealMath = window.RevealMath || (function(){
}
return {
init: function() {
id: 'math',
init: function( deck ) {
defaults( options, defaultOptions );
defaults( options.tex2jax, defaultOptions.tex2jax );
@ -73,10 +75,10 @@ var RevealMath = window.RevealMath || (function(){
// Typeset followed by an immediate reveal.js layout since
// the typesetting process could affect slide height
MathJax.Hub.Queue( [ 'Typeset', MathJax.Hub ] );
MathJax.Hub.Queue( Reveal.layout );
MathJax.Hub.Queue( deck.layout );
// 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 ] );
@ -89,4 +91,4 @@ var RevealMath = window.RevealMath || (function(){
})();
Reveal.registerPlugin( 'math', RevealMath );
Reveal.registerPlugin( RevealMath );

View File

@ -13,6 +13,8 @@ var RevealNotes = (function() {
var notesPopup = null;
var deck;
function openNotes( notesFilePath ) {
if (notesPopup && !notesPopup.closed) {
@ -46,7 +48,7 @@ var RevealNotes = (function() {
namespace: 'reveal-notes',
type: 'connect',
url: window.location.protocol + '//' + window.location.host + window.location.pathname + window.location.search,
state: Reveal.getState()
state: deck.getState()
} ), '*' );
}, 500 );
@ -68,7 +70,7 @@ var RevealNotes = (function() {
*/
function callRevealApi( methodName, methodArguments, callId ) {
var result = Reveal[methodName].apply( Reveal, methodArguments );
var result = deck[methodName].apply( deck, methodArguments );
notesPopup.postMessage( JSON.stringify( {
namespace: 'reveal-notes',
type: 'return',
@ -83,7 +85,7 @@ var RevealNotes = (function() {
*/
function post( event ) {
var slideElement = Reveal.getCurrentSlide(),
var slideElement = deck.getCurrentSlide(),
notesElement = slideElement.querySelector( 'aside.notes' ),
fragmentElement = slideElement.querySelector( '.current-fragment' );
@ -93,7 +95,7 @@ var RevealNotes = (function() {
notes: '',
markdown: false,
whitespace: 'normal',
state: Reveal.getState()
state: deck.getState()
};
// Look for notes defined in a slide attribute
@ -134,13 +136,13 @@ var RevealNotes = (function() {
function onConnected() {
// Monitor events that trigger a change in state
Reveal.on( 'slidechanged', post );
Reveal.on( 'fragmentshown', post );
Reveal.on( 'fragmenthidden', post );
Reveal.on( 'overviewhidden', post );
Reveal.on( 'overviewshown', post );
Reveal.on( 'paused', post );
Reveal.on( 'resumed', post );
deck.on( 'slidechanged', post );
deck.on( 'fragmentshown', post );
deck.on( 'fragmenthidden', post );
deck.on( 'overviewhidden', post );
deck.on( 'overviewshown', post );
deck.on( 'paused', post );
deck.on( 'resumed', post );
// Post the initial state
post();
@ -152,7 +154,11 @@ var RevealNotes = (function() {
}
return {
init: function() {
id: 'notes',
init: function( revealInstance ) {
deck = revealInstance;
if( !/receiver/i.test( window.location.search ) ) {
@ -162,7 +168,7 @@ var RevealNotes = (function() {
}
// 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();
} );
@ -175,4 +181,4 @@ var RevealNotes = (function() {
})();
Reveal.registerPlugin( 'notes', RevealNotes );
Reveal.registerPlugin( RevealNotes );

View File

@ -2,15 +2,17 @@
var RevealZoom = (function(){
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 modifier = ( Reveal.getConfig().zoomKey ? Reveal.getConfig().zoomKey : defaultModifier ) + 'Key';
var zoomLevel = ( Reveal.getConfig().zoomLevel ? Reveal.getConfig().zoomLevel : 2 );
var modifier = ( reveal.getConfig().zoomKey ? reveal.getConfig().zoomKey : defaultModifier ) + 'Key';
var zoomLevel = ( reveal.getConfig().zoomLevel ? reveal.getConfig().zoomLevel : 2 );
if( event[ modifier ] && !Reveal.isOverview() ) {
if( event[ modifier ] && !reveal.isOverview() ) {
event.preventDefault();
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)