From: Timo Tijhof Date: Fri, 4 Sep 2015 04:14:02 +0000 (+0100) Subject: resourceloader: Move creation addLink() function to shared mw.loader scope X-Git-Tag: 1.31.0-rc.0~10114^2 X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=commitdiff_plain;h=27a88a84506f190a68ef4b7f63e19bc5027e57e9;p=lhc%2Fweb%2Fwiklou.git resourceloader: Move creation addLink() function to shared mw.loader scope 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 --- diff --git a/resources/src/mediawiki/mediawiki.js b/resources/src/mediawiki/mediawiki.js index 93a2010870..f0af12bfd9 100644 --- a/resources/src/mediawiki/mediawiki.js +++ b/resources/src/mediawiki/mediawiki.js @@ -1160,6 +1160,25 @@ } ).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 * @@ -1183,25 +1202,11 @@ 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, @@ -1266,12 +1271,6 @@ } }; - // 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 );