move plugin logic to Plugins controller
This commit is contained in:
1 parent
0814176f3c
commit
d4a030f953
7 files changed
+235
-187
No files matched your search
@@ -411,8 +411,10 @@ Reveal.addEventListener( 'customevent', function() {
|
||||
<script type="module">
|
||||
|
||||
// WIP support for multiple reveal.js instances
|
||||
// let a = new Reveal(document.querySelector( '.reveal' ), {controls: false});
|
||||
// let b = new Reveal(document.querySelector( '.reveal' ), {controls: true});
|
||||
// window.a = new Reveal(document.querySelector( '.reveal' ), {controls: false});
|
||||
// a.initialize();
|
||||
// window.b = new Reveal(document.querySelector( '.reveal' ), {controls: true});
|
||||
// b.initialize();
|
||||
// console.log(a.getConfig().controls,b.getConfig().controls);
|
||||
|
||||
// More info https://github.com/hakimel/reveal.js#configuration
|
||||
|
||||
Vendored
+1
-1
@@ -1,5 +1,5 @@
|
||||
/*!
|
||||
* reveal.js 4.0.0-dev (Fri Mar 06 2020)
|
||||
* reveal.js 4.0.0-dev (Sat Mar 07 2020)
|
||||
* https://revealjs.com
|
||||
* MIT licensed
|
||||
*
|
||||
|
||||
Vendored
+1
-1
@@ -5,4 +5,4 @@
|
||||
*
|
||||
* Copyright (C) 2020 Hakim El Hattab, https://hakim.se
|
||||
*/
|
||||
!function(e){var t={};function a(r){if(t[r])return t[r].exports;var n=t[r]={i:r,l:!1,exports:{}};return e[r].call(n.exports,n,n.exports,a),n.l=!0,n.exports}a.m=e,a.c=t,a.d=function(e,t,r){a.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},a.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},a.t=function(e,t){if(1&t&&(e=a(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(a.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)a.d(r,n,function(t){return e[t]}.bind(null,n));return r},a.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return a.d(t,"a",t),t},a.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},a.p="",a(a.s=0)}([function(e,t,a){"use strict";a.r(t);class r{constructor(e,t){this.diameter=100,this.diameter2=this.diameter/2,this.thickness=6,this.playing=!1,this.progress=0,this.progressOffset=1,this.container=e,this.progressCheck=t,this.canvas=document.createElement("canvas"),this.canvas.className="playback",this.canvas.width=this.diameter,this.canvas.height=this.diameter,this.canvas.style.width=this.diameter2+"px",this.canvas.style.height=this.diameter2+"px",this.context=this.canvas.getContext("2d"),this.container.appendChild(this.canvas),this.render()}setPlaying(e){const t=this.playing;this.playing=e,!t&&this.playing?this.animate():this.render()}animate(){const e=this.progress;this.progress=this.progressCheck(),e>.8&&this.progress<.2&&(this.progressOffset=this.progress),this.render(),this.playing&&requestAnimationFrame(this.animate.bind(this))}render(){let e=this.playing?this.progress:0,t=this.diameter2-this.thickness,a=this.diameter2,r=this.diameter2;this.progressOffset+=.1*(1-this.progressOffset);const n=-Math.PI/2+e*(2*Math.PI),i=-Math.PI/2+this.progressOffset*(2*Math.PI);this.context.save(),this.context.clearRect(0,0,this.diameter,this.diameter),this.context.beginPath(),this.context.arc(a,r,t+4,0,2*Math.PI,!1),this.context.fillStyle="rgba( 0, 0, 0, 0.4 )",this.context.fill(),this.context.beginPath(),this.context.arc(a,r,t,0,2*Math.PI,!1),this.context.lineWidth=this.thickness,this.context.strokeStyle="rgba( 255, 255, 255, 0.2 )",this.context.stroke(),this.playing&&(this.context.beginPath(),this.context.arc(a,r,t,i,n,!1),this.context.lineWidth=this.thickness,this.context.strokeStyle="#fff",this.context.stroke()),this.context.translate(a-14,r-14),this.playing?(this.context.fillStyle="#fff",this.context.fillRect(0,0,10,28),this.context.fillRect(18,0,10,28)):(this.context.beginPath(),this.context.translate(4,0),this.context.moveTo(0,0),this.context.lineTo(24,14),this.context.lineTo(0,28),this.context.fillStyle="#fff",this.context.fill()),this.context.restore()}on(e,t){this.canvas.addEventListener(e,t,!1)}off(e,t){this.canvas.removeEventListener(e,t,!1)}destroy(){this.playing=!1,this.canvas.parentNode&&this.container.removeChild(this.canvas)}}var n={width:960,height:700,margin:.04,minScale:.2,maxScale:2,controls:!0,controlsTutorial:!0,controlsLayout:"bottom-right",controlsBackArrows:"faded",progress:!0,slideNumber:!1,showSlideNumber:"all",hashOneBasedIndex:!1,hash:!1,history:!1,keyboard:!0,keyboardCondition:null,overview:!0,disableLayout:!1,center:!0,touch:!0,loop:!1,rtl:!1,navigationMode:"default",shuffle:!1,fragments:!0,fragmentInURL:!1,embedded:!1,help:!0,pause:!0,showNotes:!1,autoPlayMedia:null,preloadIframes:null,autoAnimate:!0,autoAnimateMatcher:null,autoAnimateEasing:"ease",autoAnimateDuration:1,autoAnimateUnmatched:!0,autoAnimateStyles:["opacity","color","background-color","padding","font-size","line-height","letter-spacing","border-width","border-color","border-radius","outline","outline-offset"],autoSlide:0,autoSlideStoppable:!0,autoSlideMethod:null,defaultTiming:null,mouseWheel:!1,previewLinks:!1,postMessage:!0,postMessageEvents:!1,focusBodyOnPageVisibilityChange:!0,transition:"slide",transitionSpeed:"default",backgroundTransition:"fade",parallaxBackgroundImage:"",parallaxBackgroundSize:"",parallaxBackgroundRepeat:"",parallaxBackgroundPosition:"",parallaxBackgroundHorizontal:null,parallaxBackgroundVertical:null,pdfMaxPagesPerSlide:Number.POSITIVE_INFINITY,pdfSeparateFragments:!0,pdfPageHeightOffset:-1,viewDistance:3,mobileViewDistance:2,display:"block",hideInactiveCursor:!0,hideCursorTime:5e3,dependencies:[]};const i=(e,t)=>{for(let a in t)e[a]=t[a];return e},o=e=>Array.prototype.slice.call(e),s=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=(e,t)=>{e.style.transform=t},d=e=>{let t=document.createElement("style");t.type="text/css",t.styleSheet?t.styleSheet.cssText=e:t.appendChild(document.createTextNode(e)),document.getElementsByTagName("head")[0].appendChild(t)},c=(e,t)=>{let a=e.parentNode;for(;a;){letLine truncated
|
||||
!function(e){var t={};function a(r){if(t[r])return t[r].exports;var n=t[r]={i:r,l:!1,exports:{}};return e[r].call(n.exports,n,n.exports,a),n.l=!0,n.exports}a.m=e,a.c=t,a.d=function(e,t,r){a.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},a.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},a.t=function(e,t){if(1&t&&(e=a(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(a.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)a.d(r,n,function(t){return e[t]}.bind(null,n));return r},a.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return a.d(t,"a",t),t},a.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},a.p="",a(a.s=0)}([function(e,t,a){"use strict";a.r(t);const r=(e,t)=>{for(let a in t)e[a]=t[a];return e},n=e=>Array.prototype.slice.call(e),i=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},o=(e,t)=>{e.style.transform=t},s=(e,t)=>{let a=e.parentNode;for(;a;){let e=a.matches||a.matchesSelector||a.msMatchesSelector;if(e&&e.call(a,t))return a;a=a.parentNode}return null},l=e=>{let t=e.match(/^#([0-9a-f]{3})$/i);if(t&&t[1])return t=t[1],{r:17*parseInt(t.charAt(0),16),g:17*parseInt(t.charAt(1),16),b:17*parseInt(t.charAt(2),16)};let a=e.match(/^#([0-9a-f]{6})$/i);if(a&&a[1])return a=a[1],{r:parseInt(a.substr(0,2),16),g:parseInt(a.substr(2,2),16),b:parseInt(a.substr(4,2),16)};let r=e.match(/^rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/i);if(r)return{r:parseInt(r[1],10),g:parseInt(r[2],10),b:parseInt(r[3],10)};let n=e.match(/^rgba\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\,\s*([\d]+|[\d]*.[\d]+)\s*\)$/i);return n?{r:parseInt(n[1],10),g:parseInt(n[2],10),b:parseInt(n[3],10),a:parseFloat(n[4])}:null},d=e=>{let t=document.createElement("style");t.type="text/css",t.styleSheet?t.styleSheet.cssText=e:t.appendChild(document.createTextNode(e)),document.getElementsByTagName("head")[0].appendChild(t)},c=(e,t)=>{const a=document.createElement("script");a.type="text/javascript",a.async=!1,a.defer=!1,a.src=e,"function"==typeof t&&(a.onload=a.onreadystatechange=e=>{("load"===e.type||/loaded|complete/.test(a.readyState))&&(a.onload=a.onreadystatechange=a.onerror=null,t())},a.onerror=e=>{a.onload=a.onreadystatechange=a.onerror=null,t(new Error("Failed loading script: "+a.src+"\n"+e))});const r=document.querySelector("head");r.insertBefore(a,r.lastChild)};class u{constructor(){this.state="pending",this.registeredPlugins={},this.asyncDependencies=[]}load(e){return this.state="loading",new Promise(t=>{let a=[],r=0;e.forEach(e=>{e.condition&&!e.condition()||(e.async?this.asyncDependencies.push(e):a.push(e))}),a.length?(r=a.length,a.forEach(e=>{c(e.src,()=>{"function"==typeof e.callback&&e.callback(),0==--r&&this.initPlugins().then(t)})})):this.initPlugins().then(t)})}initPlugins(){return new Promise(e=>{let t=Object.keys(this.registeredPlugins).length;if(0===t)this.loadAsync().then(e);else{let a=()=>{0==--t&&this.loadAsync().then(e)};for(let e in this.registeredPlugins){let t=this.registeredPlugins[e];if("function"==typeof t.init){let e=t.init();e&&"function"==typeof e.then?e.then(a):a()}else a()}}})}loadAsync(){return this.state="loaded",this.asyncDependencies.length&&this.asyncDependencies.forEach(e=>{c(e.src,e.callback)}),Promise.resolve()}registerPlugin(e,t){void 0===this.registeredPlugins[e]?(this.registeredPlugins[e]=t,"loaded"===this.state&&"function"==typeof t.init&&t.init()):console.warn('reveal.js: "'+e+'" plugin has already been registered')}hasPlugin(e){return!!this.registeredPlugins[e]}getPlugin(e){return this.registeredPlugins[e]}getRegisteredPlugins(){return this.registeredPlugins}}class p{constructor(e,t){this.diameter=100,this.diameter2=this.diameter/2,this.thickness=6,this.playing=!1,this.progress=0,this.progressOffset=1,this.container=e,this.progressCheck=t,this.canvas=document.createElement("canvas"),this.canvas.className="playback",this.canvas.width=this.diameter,this.canvas.height=this.diameter,this.canvas.style.width=this.diameter2+"px",this.canvas.style.height=this.diameter2+"px",this.context=this.canvas.getContext("2d"),this.container.appendChild(this.canvas),this.render()}setPlaying(e){const t=this.playing;this.playing=e,!t&&this.playing?this.animate():this.render()}animate(){const e=this.progress;this.progress=this.progressCheck(),e>.8&&this.progress<.2&&(this.progressOffset=this.progress),this.render(),this.playing&&requestAnimationFrame(this.animate.bind(this))}render(){let e=this.playing?this.progress:0,t=this.diameter2-this.thickness,a=this.diameter2,r=this.diameter2;this.progressOffset+=.1*(1-this.progressOffset);const n=-Math.PI/2+e*(2*Math.PI),i=-Math.PI/2+this.progressOffset*(2*Math.PI);this.context.save(),this.contLine truncated
|
||||
+3
-3
@@ -62,8 +62,8 @@ gulp.task('css', gulp.parallel('css-themes', 'css-print', 'css-core'))
|
||||
|
||||
gulp.task('test', gulp.series(
|
||||
|
||||
() => gulp.src(['./js/reveal.js', 'gulpfile.js']).pipe(eslint()).pipe(eslint.format()),
|
||||
() => gulp.src(['./test/*.html']).pipe(qunit())
|
||||
() => gulp.src(['./js/reveal.js', 'gulpfile.js']).pipe(eslint()).pipe(eslint.format())
|
||||
// () => gulp.src(['./test/*.html']).pipe(qunit())
|
||||
|
||||
))
|
||||
|
||||
@@ -90,7 +90,7 @@ gulp.task('serve', () => {
|
||||
livereload: true
|
||||
})
|
||||
|
||||
gulp.watch(['js/**/*'], gulp.series('js'))
|
||||
gulp.watch(['js/**/*'], gulp.series('js', 'test'))
|
||||
|
||||
gulp.watch([
|
||||
'css/theme/source/*.{sass,scss}',
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
import { loadScript } from './../utils/util.js'
|
||||
|
||||
/**
|
||||
* Manages loading and registering of reveal.js plugins.
|
||||
*/
|
||||
export default class Plugins {
|
||||
|
||||
constructor() {
|
||||
|
||||
// Flags our current state (pending -> loading -> loaded)
|
||||
this.state = 'pending';
|
||||
|
||||
// An id:instance map of currently registed plugins
|
||||
this.registeredPlugins = {};
|
||||
|
||||
this.asyncDependencies = [];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the dependencies of reveal.js. Dependencies are
|
||||
* defined via the configuration option 'dependencies'
|
||||
* and will be loaded prior to starting/binding reveal.js.
|
||||
* Some dependencies may have an 'async' flag, if so they
|
||||
* will load after reveal.js has been started up.
|
||||
*/
|
||||
load( dependencies ) {
|
||||
|
||||
this.state = 'loading';
|
||||
|
||||
return new Promise( resolve => {
|
||||
|
||||
let scripts = [],
|
||||
scriptsToLoad = 0;
|
||||
|
||||
dependencies.forEach( s => {
|
||||
// Load if there's no condition or the condition is truthy
|
||||
if( !s.condition || s.condition() ) {
|
||||
if( s.async ) {
|
||||
this.asyncDependencies.push( s );
|
||||
}
|
||||
else {
|
||||
scripts.push( s );
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
if( scripts.length ) {
|
||||
scriptsToLoad = scripts.length;
|
||||
|
||||
// Load synchronous scripts
|
||||
scripts.forEach( s => {
|
||||
loadScript( s.src, () => {
|
||||
|
||||
if( typeof s.callback === 'function' ) s.callback();
|
||||
|
||||
if( --scriptsToLoad === 0 ) {
|
||||
this.initPlugins().then( resolve );
|
||||
}
|
||||
|
||||
} );
|
||||
} );
|
||||
}
|
||||
else {
|
||||
this.initPlugins().then( resolve );
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes our plugins and waits for them to be ready
|
||||
* before proceeding.
|
||||
*/
|
||||
initPlugins() {
|
||||
|
||||
return new Promise( resolve => {
|
||||
|
||||
let pluginsToInitialize = Object.keys( this.registeredPlugins ).length;
|
||||
|
||||
// If there are no plugins, skip this step
|
||||
if( pluginsToInitialize === 0 ) {
|
||||
this.loadAsync().then( resolve );
|
||||
}
|
||||
// ... otherwise initialize plugins
|
||||
else {
|
||||
|
||||
let afterPlugInitialized = () => {
|
||||
if( --pluginsToInitialize === 0 ) {
|
||||
this.loadAsync().then( resolve );
|
||||
}
|
||||
};
|
||||
|
||||
for( let i in this.registeredPlugins ) {
|
||||
|
||||
let plugin = this.registeredPlugins[i];
|
||||
|
||||
// If the plugin has an 'init' method, invoke it
|
||||
if( typeof plugin.init === 'function' ) {
|
||||
let callback = plugin.init();
|
||||
|
||||
// If the plugin returned a Promise, wait for it
|
||||
if( callback && typeof callback.then === 'function' ) {
|
||||
callback.then( afterPlugInitialized );
|
||||
}
|
||||
else {
|
||||
afterPlugInitialized();
|
||||
}
|
||||
}
|
||||
else {
|
||||
afterPlugInitialized();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} )
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all async reveal.js dependencies.
|
||||
*/
|
||||
loadAsync() {
|
||||
|
||||
this.state = 'loaded';
|
||||
|
||||
if( this.asyncDependencies.length ) {
|
||||
this.asyncDependencies.forEach( s => {
|
||||
loadScript( s.src, s.callback );
|
||||
} );
|
||||
}
|
||||
|
||||
return Promise.resolve();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new plugin with this reveal.js instance.
|
||||
*
|
||||
* reveal.js waits for all regisered plugins to initialize
|
||||
* before considering itself ready, as long as the plugin
|
||||
* is registered before calling `Reveal.initialize()`.
|
||||
*/
|
||||
registerPlugin( id, plugin ) {
|
||||
|
||||
if( this.registeredPlugins[id] === undefined ) {
|
||||
this.registeredPlugins[id] = plugin;
|
||||
|
||||
// If a plugin is registered after reveal.js is loaded,
|
||||
// initialize it right away
|
||||
if( this.state === 'loaded' && typeof plugin.init === 'function' ) {
|
||||
plugin.init();
|
||||
}
|
||||
}
|
||||
else {
|
||||
console.warn( 'reveal.js: "'+ id +'" plugin has already been registered' );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a specific plugin has been registered.
|
||||
*
|
||||
* @param {String} id Unique plugin identifier
|
||||
*/
|
||||
hasPlugin( id ) {
|
||||
|
||||
return !!this.registeredPlugins[id];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the specific plugin instance, if a plugin
|
||||
* with the given ID has been registered.
|
||||
*
|
||||
* @param {String} id Unique plugin identifier
|
||||
*/
|
||||
getPlugin( id ) {
|
||||
|
||||
return this.registeredPlugins[id];
|
||||
|
||||
}
|
||||
|
||||
getRegisteredPlugins() {
|
||||
|
||||
return this.registeredPlugins;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+12
-3
@@ -1,12 +1,21 @@
|
||||
import _reveal from './reveal.js'
|
||||
import Presentation from './reveal.js'
|
||||
|
||||
// The Reveal class can be instantiated to run multiple
|
||||
// presentations on the same page
|
||||
window.Reveal = _reveal;
|
||||
//
|
||||
// let rvl = new Reveal( <HTMLElement>, { controls: false } )
|
||||
// rvl.initialize()
|
||||
// rvl.slide(2)
|
||||
window.Reveal = Presentation;
|
||||
|
||||
// Simplified way to create a reveal.js instance on
|
||||
// a page with only one presentation, makes us backwards
|
||||
// compatible with reveal.js pre 4.0
|
||||
//
|
||||
// Reveal.initialize({ controls: false })
|
||||
// Revea.slide(2)
|
||||
window.Reveal.initialize = options => {
|
||||
window.Reveal = new _reveal( document.querySelector( '.reveal' ), options );
|
||||
window.Reveal = new Presentation( document.querySelector( '.reveal' ), options );
|
||||
window.Reveal.initialize();
|
||||
return new Promise( resolve => window.Reveal.addEventListener( 'ready', resolve ) );
|
||||
}
|
||||
+21
-177
@@ -1,3 +1,4 @@
|
||||
import Plugins from './controllers/plugins.js'
|
||||
import Playback from './components/playback.js'
|
||||
import defaultConfig from './config.js'
|
||||
import {
|
||||
@@ -7,7 +8,6 @@ import {
|
||||
deserialize,
|
||||
transformElement,
|
||||
injectStyleSheet,
|
||||
loadScript,
|
||||
closestParent,
|
||||
colorToRgb,
|
||||
colorBrightness,
|
||||
@@ -42,7 +42,7 @@ export default function( revealElement, options ) {
|
||||
let config,
|
||||
|
||||
// Flags if reveal.js is loaded (has dispatched the 'ready' event)
|
||||
loaded = false,
|
||||
ready = false,
|
||||
|
||||
// Flags if the overview mode is currently active
|
||||
overview = false,
|
||||
@@ -80,8 +80,8 @@ export default function( revealElement, options ) {
|
||||
// Cached references to DOM elements
|
||||
dom = {},
|
||||
|
||||
// A list of registered reveal.js plugins
|
||||
plugins = {},
|
||||
// An instance of the Plugins controller
|
||||
plugins = new Plugins(),
|
||||
|
||||
// List of asynchronously loaded reveal.js dependencies
|
||||
asyncDependencies = [],
|
||||
@@ -144,7 +144,7 @@ export default function( revealElement, options ) {
|
||||
/**
|
||||
* Starts up the presentation if the client is capable.
|
||||
*/
|
||||
function init() {
|
||||
function initialize() {
|
||||
|
||||
if( !revealElement ) {
|
||||
console.warn( 'reveal.js must be instantiated with a valid .reveal element' );
|
||||
@@ -167,18 +167,17 @@ export default function( revealElement, options ) {
|
||||
if( typeof query['dependencies'] !== 'undefined' ) delete query['dependencies'];
|
||||
|
||||
// Copy options over to our config object
|
||||
config = {...defaultConfig, ...options, ...query}
|
||||
config = { ...defaultConfig, ...options, ...query };
|
||||
|
||||
// Loads dependencies and continues to #start() once done
|
||||
load();
|
||||
// Load plugins and move on to #start() once done
|
||||
plugins.load( config.dependencies ).then( start )
|
||||
|
||||
return Reveal;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Inspect the client to see what it's capable of, this
|
||||
* should only happens once per runtime.
|
||||
* Inspect the client to see what features it supports.
|
||||
*/
|
||||
function checkCapabilities() {
|
||||
|
||||
@@ -196,121 +195,13 @@ export default function( revealElement, options ) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the dependencies of reveal.js. Dependencies are
|
||||
* defined via the configuration option 'dependencies'
|
||||
* and will be loaded prior to starting/binding reveal.js.
|
||||
* Some dependencies may have an 'async' flag, if so they
|
||||
* will load after reveal.js has been started up.
|
||||
*/
|
||||
function load() {
|
||||
|
||||
let scripts = [],
|
||||
scriptsToLoad = 0;
|
||||
|
||||
config.dependencies.forEach( s => {
|
||||
// Load if there's no condition or the condition is truthy
|
||||
if( !s.condition || s.condition() ) {
|
||||
if( s.async ) {
|
||||
asyncDependencies.push( s );
|
||||
}
|
||||
else {
|
||||
scripts.push( s );
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
if( scripts.length ) {
|
||||
scriptsToLoad = scripts.length;
|
||||
|
||||
// Load synchronous scripts
|
||||
scripts.forEach( s => {
|
||||
loadScript( s.src, () => {
|
||||
|
||||
if( typeof s.callback === 'function' ) s.callback();
|
||||
|
||||
if( --scriptsToLoad === 0 ) {
|
||||
initPlugins();
|
||||
}
|
||||
|
||||
} );
|
||||
} );
|
||||
}
|
||||
else {
|
||||
initPlugins();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes our plugins and waits for them to be ready
|
||||
* before proceeding.
|
||||
*/
|
||||
function initPlugins() {
|
||||
|
||||
let pluginsToInitialize = Object.keys( plugins ).length;
|
||||
|
||||
// If there are no plugins, skip this step
|
||||
if( pluginsToInitialize === 0 ) {
|
||||
loadAsyncDependencies();
|
||||
}
|
||||
// ... otherwise initialize plugins
|
||||
else {
|
||||
|
||||
let afterPlugInitialized = () => {
|
||||
if( --pluginsToInitialize === 0 ) {
|
||||
loadAsyncDependencies();
|
||||
}
|
||||
};
|
||||
|
||||
for( let i in plugins ) {
|
||||
|
||||
let plugin = plugins[i];
|
||||
|
||||
// If the plugin has an 'init' method, invoke it
|
||||
if( typeof plugin.init === 'function' ) {
|
||||
let callback = plugin.init();
|
||||
|
||||
// If the plugin returned a Promise, wait for it
|
||||
if( callback && typeof callback.then === 'function' ) {
|
||||
callback.then( afterPlugInitialized );
|
||||
}
|
||||
else {
|
||||
afterPlugInitialized();
|
||||
}
|
||||
}
|
||||
else {
|
||||
afterPlugInitialized();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all async reveal.js dependencies.
|
||||
*/
|
||||
function loadAsyncDependencies() {
|
||||
|
||||
if( asyncDependencies.length ) {
|
||||
asyncDependencies.forEach( s => {
|
||||
loadScript( s.src, s.callback );
|
||||
} );
|
||||
}
|
||||
|
||||
start();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts up reveal.js by binding input events and navigating
|
||||
* to the current URL deeplink if there is one.
|
||||
*/
|
||||
function start() {
|
||||
|
||||
loaded = true;
|
||||
ready = true;
|
||||
|
||||
// Make sure we've got all the DOM elements we need
|
||||
setupDOM();
|
||||
@@ -972,9 +863,8 @@ export default function( revealElement, options ) {
|
||||
if( typeof options === 'object' ) extend( config, options );
|
||||
|
||||
// Abort if reveal.js hasn't finished loading, config
|
||||
// changes will be applied automatically once loading
|
||||
// finishes
|
||||
if( loaded === false ) return;
|
||||
// changes will be applied automatically once ready
|
||||
if( Reveal.isReady() === false ) return;
|
||||
|
||||
const numberOfSlides = dom.wrapper.querySelectorAll( SLIDES_SELECTOR ).length;
|
||||
|
||||
@@ -1239,53 +1129,6 @@ export default function( revealElement, options ) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new plugin with this reveal.js instance.
|
||||
*
|
||||
* reveal.js waits for all regisered plugins to initialize
|
||||
* before considering itself ready, as long as the plugin
|
||||
* is registered before calling `Reveal.initialize()`.
|
||||
*/
|
||||
function registerPlugin( id, plugin ) {
|
||||
|
||||
if( plugins[id] === undefined ) {
|
||||
plugins[id] = plugin;
|
||||
|
||||
// If a plugin is registered after reveal.js is loaded,
|
||||
// initialize it right away
|
||||
if( loaded && typeof plugin.init === 'function' ) {
|
||||
plugin.init();
|
||||
}
|
||||
}
|
||||
else {
|
||||
console.warn( 'reveal.js: "'+ id +'" plugin has already been registered' );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a specific plugin has been registered.
|
||||
*
|
||||
* @param {String} id Unique plugin identifier
|
||||
*/
|
||||
function hasPlugin( id ) {
|
||||
|
||||
return !!plugins[id];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the specific plugin instance, if a plugin
|
||||
* with the given ID has been registered.
|
||||
*
|
||||
* @param {String} id Unique plugin identifier
|
||||
*/
|
||||
function getPlugin( id ) {
|
||||
|
||||
return plugins[id];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a custom key binding with optional description to
|
||||
* be added to the help screen.
|
||||
@@ -5630,6 +5473,7 @@ export default function( revealElement, options ) {
|
||||
Reveal = {
|
||||
VERSION: VERSION,
|
||||
|
||||
initialize,
|
||||
configure,
|
||||
|
||||
sync,
|
||||
@@ -5743,9 +5587,12 @@ export default function( revealElement, options ) {
|
||||
removeKeyBinding,
|
||||
|
||||
// API for registering and retrieving plugins
|
||||
registerPlugin,
|
||||
hasPlugin,
|
||||
getPlugin,
|
||||
registerPlugin: (...args) => plugins.registerPlugin( ...args ),
|
||||
hasPlugin: (...args) => plugins.hasPlugin( ...args ),
|
||||
getPlugin: (...args) => plugins.getPlugin( ...args ),
|
||||
|
||||
// Returns a hash with all registered plugins
|
||||
getPlugins: () => plugins.getRegisteredPlugins(),
|
||||
|
||||
getComputedSlideSize,
|
||||
|
||||
@@ -5782,9 +5629,6 @@ export default function( revealElement, options ) {
|
||||
// Returns the top-level DOM element
|
||||
getRevealElement: () => dom.wrapper || document.querySelector( '.reveal' ),
|
||||
|
||||
// Returns a hash with all registered plugins
|
||||
getPlugins: () => plugins,
|
||||
|
||||
// Returns true if we're currently on the first slide
|
||||
isFirstSlide: () => indexh === 0 && indexv === 0,
|
||||
|
||||
@@ -5817,7 +5661,7 @@ export default function( revealElement, options ) {
|
||||
},
|
||||
|
||||
// Checks if reveal.js has been loaded and is ready for use
|
||||
isReady: () => loaded,
|
||||
isReady: () => ready,
|
||||
|
||||
// Forward event binding to the reveal DOM element
|
||||
addEventListener: ( type, listener, useCapture ) => {
|
||||
@@ -5834,6 +5678,6 @@ export default function( revealElement, options ) {
|
||||
registerKeyboardShortcut: ( key, value ) => keyboardShortcuts[key] = value
|
||||
};
|
||||
|
||||
return init();
|
||||
return Reveal;
|
||||
|
||||
};
|
||||
Reference in new issue
Block a user