diff options
Diffstat (limited to 'js/reveal.js')
-rw-r--r-- | js/reveal.js | 120 |
1 files changed, 94 insertions, 26 deletions
diff --git a/js/reveal.js b/js/reveal.js index 3c31b97..ca2a9a0 100644 --- a/js/reveal.js +++ b/js/reveal.js @@ -436,41 +436,28 @@ scriptsToPreload = 0; // Called once synchronous scripts finish loading - function proceed() { + function afterSynchronousScriptsLoaded() { + // Load asynchronous scripts if( scriptsAsync.length ) { - // Load asynchronous scripts - head.js.apply( null, scriptsAsync ); + scriptsAsync.forEach( function( s ) { + loadScript( s.src, s.callback ); + } ); } start(); } - function loadScript( s ) { - head.ready( s.src.match( /([\w\d_\-]*)\.?js(\?[\w\d.=&]*)?$|[^\\\/]*$/i )[0], function() { - // Extension may contain callback functions - if( typeof s.callback === 'function' ) { - s.callback.apply( this ); - } - - if( --scriptsToPreload === 0 ) { - proceed(); - } - }); - } - for( var i = 0, len = config.dependencies.length; i < len; i++ ) { var s = config.dependencies[i]; // Load if there's no condition or the condition is truthy if( !s.condition || s.condition() ) { if( s.async ) { - scriptsAsync.push( s.src ); + scriptsAsync.push( s ); } else { - scripts.push( s.src ); + scripts.push( s ); } - - loadScript( s ); } } @@ -478,15 +465,74 @@ scriptsToPreload = scripts.length; // Load synchronous scripts - head.js.apply( null, scripts ); + scripts.forEach( function( s ) { + loadScript( s.src, function() { + + if( typeof s.callback === 'function' ) s.callback(); + + if( --scriptsToPreload === 0 ) { + + afterSynchronousScriptsLoaded(); + + } + + } ); + } ); } else { - proceed(); + afterSynchronousScriptsLoaded(); } } /** + * Loads a JavaScript file from the given URL and executes it. + * + * @param {string} url Address of the .js file to load + * @param {function} callback Method to invoke when the script + * has loaded and executed + */ + function loadScript( url, callback ) { + + var script = document.createElement( 'script' ); + script.type = 'text/javascript'; + script.async = false; + script.defer = false; + script.src = url; + + if( callback ) { + + // Success callback + script.onload = script.onreadystatechange = function( event ) { + if( event.type === "load" || (/loaded|complete/.test( script.readyState ) ) ) { + + // Kill event listeners + script.onload = script.onreadystatechange = script.onerror = null; + + callback(); + + } + }; + + // Error callback + script.onerror = function( err ) { + + // Kill event listeners + script.onload = script.onreadystatechange = script.onerror = null; + + callback( new Error( 'Failed loading script: ' + script.src + '\n' + err) ); + + }; + + } + + // Append the script at the end of <head> + var head = document.querySelector( 'head' ); + head.insertBefore( script, head.lastChild ); + + } + + /** * Starts up reveal.js by binding input events and navigating * to the current URL deeplink if there is one. */ @@ -593,8 +639,7 @@ dom.speakerNotes.setAttribute( 'tabindex', '0' ); // Overlay graphic which is displayed during the paused mode - dom.pauseOverlay = createSingletonNode( dom.wrapper, 'div', 'pause-overlay', '<button class="resume-button">Resume presentation</button>' ); - dom.resumeButton = dom.pauseOverlay.querySelector( '.resume-button' ); + dom.pauseOverlay = createSingletonNode( dom.wrapper, 'div', 'pause-overlay', config.controls ? '<button class="resume-button">Resume presentation</button>' : null ); dom.wrapper.setAttribute( 'role', 'application' ); @@ -1299,7 +1344,7 @@ dom.progress.addEventListener( 'click', onProgressClicked, false ); } - dom.resumeButton.addEventListener( 'click', resume, false ); + dom.pauseOverlay.addEventListener( 'click', resume, false ); if( config.focusBodyOnPageVisibilityChange ) { var visibilityChange; @@ -1364,7 +1409,7 @@ dom.wrapper.removeEventListener( 'touchmove', onTouchMove, false ); dom.wrapper.removeEventListener( 'touchend', onTouchEnd, false ); - dom.resumeButton.removeEventListener( 'click', resume, false ); + dom.pauseOverlay.removeEventListener( 'click', resume, false ); if ( config.progress && dom.progress ) { dom.progress.removeEventListener( 'click', onProgressClicked, false ); @@ -4100,6 +4145,25 @@ } /** + * Returns an array of objects where each object represents the + * attributes on its respective slide. + */ + function getSlidesAttributes() { + + return getSlides().map( function( slide ) { + + var attributes = {}; + for( var i = 0; i < slide.attributes.length; i++ ) { + var attribute = slide.attributes[ i ]; + attributes[ attribute.name ] = attribute.value; + } + return attributes; + + } ); + + } + + /** * Retrieves the total number of slides in this presentation. * * @return {number} @@ -5455,6 +5519,10 @@ // Returns an Array of all slides getSlides: getSlides, + // Returns an Array of objects representing the attributes on + // the slides + getSlidesAttributes: getSlidesAttributes, + // Returns the total number of slides getTotalSlides: getTotalSlides, |