resourceloader: Move creation addLink() function to shared mw.loader scope
authorTimo Tijhof <krinklemail@gmail.com>
Fri, 4 Sep 2015 04:14:02 +0000 (05:14 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Mon, 7 Sep 2015 20:04:56 +0000 (21:04 +0100)
No need for this function to be re-created on each call of execute().
Also set state to "loading" earlier in runScript for clarity.

Change-Id: I46c7f850df90f8c160613dc6ffd251c7e9aee147

resources/src/mediawiki/mediawiki.js

index 93a2010..f0af12b 100644 (file)
                                } ).always( callback );
                        }
 
+                       /**
+                        * Utility function for execute()
+                        *
+                        * @ignore
+                        */
+                       function addLink( media, url ) {
+                               var el = document.createElement( 'link' );
+                               // Support: IE
+                               // Insert in document *before* setting href
+                               getMarker().before( el );
+                               el.rel = 'stylesheet';
+                               if ( media && media !== 'all' ) {
+                                       el.media = media;
+                               }
+                               // If you end up here from an IE exception "SCRIPT: Invalid property value.",
+                               // see #addEmbeddedCSS, bug 31676, and bug 47277 for details.
+                               el.href = url;
+                       }
+
                        /**
                         * Executes a loaded module, making it ready to use
                         *
                                        throw new Error( 'Module has already been executed: ' + module );
                                }
 
-                               /**
-                                * Define loop-function here for efficiency
-                                * and to avoid re-using badly scoped variables.
-                                *
-                                * @ignore
-                                */
-                               function addLink( media, url ) {
-                                       var el = document.createElement( 'link' );
-                                       // Support: IE
-                                       // Insert in document *before* setting href
-                                       getMarker().before( el );
-                                       el.rel = 'stylesheet';
-                                       if ( media && media !== 'all' ) {
-                                               el.media = media;
-                                       }
-                                       // If you end up here from an IE exception "SCRIPT: Invalid property value.",
-                                       // see #addEmbeddedCSS, bug 31676, and bug 47277 for details.
-                                       el.href = url;
-                               }
+                               // This used to be inside runScript, but since that is now fired asychronously
+                               // (after CSS is loaded) we need to set it here right away. It is crucial that
+                               // when execute() is called this is set synchronously, otherwise modules will get
+                               // executed multiple times as the registry will state that it isn't loading yet.
+                               registry[ module ].state = 'loading';
 
                                runScript = function () {
                                        var script, markModuleReady, nestedAddScript, legacyWait,
                                        }
                                };
 
-                               // This used to be inside runScript, but since that is now fired asychronously
-                               // (after CSS is loaded) we need to set it here right away. It is crucial that
-                               // when execute() is called this is set synchronously, otherwise modules will get
-                               // executed multiple times as the registry will state that it isn't loading yet.
-                               registry[ module ].state = 'loading';
-
                                // Add localizations to message system
                                if ( registry[ module ].messages ) {
                                        mw.messages.set( registry[ module ].messages );