From 0ffbe8d09cbc48d750c102ddc6de13b07c7f8b59 Mon Sep 17 00:00:00 2001 From: Thomas Endres Date: Sun, 10 Nov 2013 14:48:50 +0100 Subject: [PATCH 1/3] Issue #698: Non-async scripts were not executed before Reveal started --- js/reveal.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/reveal.js b/js/reveal.js index 7b81e5c8..410b390d 100644 --- a/js/reveal.js +++ b/js/reveal.js @@ -284,7 +284,7 @@ var Reveal = (function(){ } if( scripts.length ) { - head.ready( proceed ); + scripts.push(proceed); // Load synchronous scripts head.js.apply( null, scripts ); From ffd8ccbffabdeb359ef2e32b5b1e792adfb257d4 Mon Sep 17 00:00:00 2001 From: Thomas Endres Date: Sun, 10 Nov 2013 16:16:49 +0100 Subject: [PATCH 2/3] Issue #698: Non-async script callbacks are now also called before starting Reveal --- js/reveal.js | 95 ++++++++++++++++++++++++++++------------------------ 1 file changed, 52 insertions(+), 43 deletions(-) diff --git a/js/reveal.js b/js/reveal.js index 410b390d..e87a9cfa 100644 --- a/js/reveal.js +++ b/js/reveal.js @@ -242,58 +242,67 @@ var Reveal = (function(){ } - /** - * 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() { + /** + * 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() { + var scripts = [], + scriptsAsync = [], + scriptsToApply = 0; - var scripts = [], - scriptsAsync = []; + // Called once synchronous scripts finish loading + function proceed() { + if( scriptsAsync.length ) { + // Load asynchronous scripts + head.js.apply( null, scriptsAsync ); + } - for( var i = 0, len = config.dependencies.length; i < len; i++ ) { - var s = config.dependencies[i]; + start(); + } - // Load if there's no condition or the condition is truthy - if( !s.condition || s.condition() ) { - if( s.async ) { - scriptsAsync.push( s.src ); - } - else { - scripts.push( s.src ); - } + for( var i = 0, len = config.dependencies.length; i < len; i++ ) { + var s = config.dependencies[i]; - // Extension may contain callback functions - if( typeof s.callback === 'function' ) { - head.ready( s.src.match( /([\w\d_\-]*)\.?js$|[^\\\/]*$/i )[0], s.callback ); - } - } - } + // Load if there's no condition or the condition is truthy + if( !s.condition || s.condition() ) { + if( s.async ) { + scriptsAsync.push( s.src ); + } + else { + scripts.push( s.src ); + } - // Called once synchronous scripts finish loading - function proceed() { - if( scriptsAsync.length ) { - // Load asynchronous scripts - head.js.apply( null, scriptsAsync ); - } + // Extension may contain callback functions + (function(s) { + head.ready( s.src.match( /([\w\d_\-]*)\.?js$|[^\\\/]*$/i )[0], function() { + if( typeof s.callback === 'function' ) { + s.callback.apply(this); + } - start(); - } + scriptsToApply--; + if (scriptsToApply === 0) { + proceed(); + } + }); + })(s); + } + } - if( scripts.length ) { - scripts.push(proceed); + if( scripts.length ) { + scriptsToApply = scripts.length; - // Load synchronous scripts - head.js.apply( null, scripts ); - } - else { - proceed(); - } + // Load synchronous scripts + head.js.apply( null, scripts ); + } + else { + proceed(); + } - } + } /** * Starts up reveal.js by binding input events and navigating From 08808abf0427245c210b9183fb69fc26bfa262b3 Mon Sep 17 00:00:00 2001 From: Thomas Endres Date: Tue, 19 Nov 2013 21:10:20 +0100 Subject: [PATCH 3/3] Issue #698: Fixed tests --- js/reveal.js | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/js/reveal.js b/js/reveal.js index e87a9cfa..d856c3d8 100644 --- a/js/reveal.js +++ b/js/reveal.js @@ -242,6 +242,7 @@ var Reveal = (function(){ } + /** * Loads the dependencies of reveal.js. Dependencies are * defined via the configuration option 'dependencies' @@ -264,6 +265,20 @@ var Reveal = (function(){ start(); } + function loadDependency(s) { + head.ready( s.src.match( /([\w\d_\-]*)\.?js$|[^\\\/]*$/i )[0], function() { + // Extension may contain callback functions + if( typeof s.callback === 'function' ) { + s.callback.apply(this); + } + + scriptsToApply--; + if (scriptsToApply === 0) { + proceed(); + } + }); + } + for( var i = 0, len = config.dependencies.length; i < len; i++ ) { var s = config.dependencies[i]; @@ -276,19 +291,7 @@ var Reveal = (function(){ scripts.push( s.src ); } - // Extension may contain callback functions - (function(s) { - head.ready( s.src.match( /([\w\d_\-]*)\.?js$|[^\\\/]*$/i )[0], function() { - if( typeof s.callback === 'function' ) { - s.callback.apply(this); - } - - scriptsToApply--; - if (scriptsToApply === 0) { - proceed(); - } - }); - })(s); + loadDependency(s); } }