Issue #698: Non-async script callbacks are now also called before starting Reveal
authorThomas Endres <Thomas-Endres@gmx.de>
Sun, 10 Nov 2013 15:16:49 +0000 (16:16 +0100)
committerThomas Endres <Thomas-Endres@gmx.de>
Tue, 19 Nov 2013 19:56:51 +0000 (20:56 +0100)
js/reveal.js

index 410b390d77b254bc901ece6450e25818b2eb6a8d..e87a9cfaaff73ba0672a2cad2de856409416613b 100644 (file)
@@ -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() {
-
-               var scripts = [],
-                       scriptsAsync = [];
-
-               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 );
-                               }
-                               else {
-                                       scripts.push( s.src );
-                               }
-
-                               // Extension may contain callback functions
-                               if( typeof s.callback === 'function' ) {
-                                       head.ready( s.src.match( /([\w\d_\-]*)\.?js$|[^\\\/]*$/i )[0], s.callback );
-                               }
-                       }
-               }
-
-               // Called once synchronous scripts finish loading
-               function proceed() {
-                       if( scriptsAsync.length ) {
-                               // Load asynchronous scripts
-                               head.js.apply( null, scriptsAsync );
-                       }
-
-                       start();
-               }
-
-               if( scripts.length ) {
-            scripts.push(proceed);
-
-                       // Load synchronous scripts
-                       head.js.apply( null, scripts );
-               }
-               else {
-                       proceed();
-               }
-
-       }
+    /**
+     * 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;
+
+        // Called once synchronous scripts finish loading
+        function proceed() {
+            if( scriptsAsync.length ) {
+                // Load asynchronous scripts
+                head.js.apply( null, scriptsAsync );
+            }
+
+            start();
+        }
+
+        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 );
+                }
+                else {
+                    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);
+            }
+        }
+
+        if( scripts.length ) {
+            scriptsToApply = scripts.length;
+
+            // Load synchronous scripts
+            head.js.apply( null, scripts );
+        }
+        else {
+            proceed();
+        }
+
+    }
 
        /**
         * Starts up reveal.js by binding input events and navigating