resourceloader: Remove global startUp() callback
authorTimo Tijhof <krinklemail@gmail.com>
Fri, 28 Aug 2015 22:20:53 +0000 (00:20 +0200)
committerKrinkle <krinklemail@gmail.com>
Mon, 31 Aug 2015 15:44:04 +0000 (15:44 +0000)
Instead of a hardcoded JSONP-style global callback, use script
load handlers. This uses the same logic as jQuery uses internally
(ajax/script.js), which we call inside mediawiki.js. Inline those
two lines here since this the code is what loads jQuery itself.

Bug: T39894
Change-Id: I02b0d16a6ec3081dc551bfd9c3ae652707b7edcf

resources/Resources.php
resources/src/mediawiki/mediawiki.startUp.js [deleted file]
resources/src/startup.js

index 7794911..e21deb9 100644 (file)
@@ -827,7 +827,6 @@ return array(
                        'resources/lib/phpjs-sha1/sha1.js',
                        'resources/src/mediawiki/mediawiki.js',
                        'resources/src/mediawiki/mediawiki.errorLogger.js',
-                       'resources/src/mediawiki/mediawiki.startUp.js',
                ),
                'debugScripts' => 'resources/src/mediawiki/mediawiki.log.js',
                'targets' => array( 'desktop', 'mobile' ),
diff --git a/resources/src/mediawiki/mediawiki.startUp.js b/resources/src/mediawiki/mediawiki.startUp.js
deleted file mode 100644 (file)
index 028784c..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-/*!
- * Auto-register from pre-loaded startup scripts
- */
-( function ( $ ) {
-       'use strict';
-
-       if ( $.isFunction( window.startUp ) ) {
-               window.startUp();
-               window.startUp = undefined;
-       }
-}( jQuery ) );
index 3b79bd3..eb4dc9f 100644 (file)
@@ -68,39 +68,48 @@ function isCompatible( ua ) {
        );
 }
 
-/**
- * The $CODE and $VARS placeholders are substituted in ResourceLoaderStartUpModule.php.
- */
-function startUp() {
-       mw.config = new mw.Map( $VARS.wgLegacyJavaScriptGlobals );
+// Conditional script injection
+( function () {
+       if ( !isCompatible() ) {
+               // Undo class swapping in case of an unsupported browser.
+               // See OutputPage::getHeadScripts().
+               document.documentElement.className = document.documentElement.className
+                       .replace( /(^|\s)client-js(\s|$)/, '$1client-nojs$2' );
+       }
+
+       /**
+        * The $CODE and $VARS placeholders are substituted in ResourceLoaderStartUpModule.php.
+        */
+       function startUp() {
+               mw.config = new mw.Map( $VARS.wgLegacyJavaScriptGlobals );
 
-       $CODE.registrations();
+               $CODE.registrations();
 
-       mw.config.set( $VARS.configuration );
+               mw.config.set( $VARS.configuration );
 
-       // Must be after mw.config.set because these callbacks may use mw.loader which
-       // needs to have values 'skin', 'debug' etc. from mw.config.
-       window.RLQ = window.RLQ || [];
-       while ( RLQ.length ) {
-               RLQ.shift()();
+               // Must be after mw.config.set because these callbacks may use mw.loader which
+               // needs to have values 'skin', 'debug' etc. from mw.config.
+               window.RLQ = window.RLQ || [];
+               while ( RLQ.length ) {
+                       RLQ.shift()();
+               }
+               window.RLQ = {
+                       push: function ( fn ) {
+                               fn();
+                       }
+               };
        }
-       window.RLQ = {
-               push: function ( fn ) {
-                       fn();
+
+       var script = document.createElement( 'script' );
+       script.src = $VARS.baseModulesUri;
+       script.onload = script.onreadystatechange = function () {
+               if ( !script.readyState || /loaded|complete/.test( script.readyState ) ) {
+                       // Clean up
+                       script.onload = script.onreadystatechange = null;
+                       script = null;
+                       // Callback
+                       startUp();
                }
        };
-}
-
-// Conditional script injection
-if ( isCompatible() ) {
-       ( function () {
-               var script = document.createElement( 'script' );
-               script.src = $VARS.baseModulesUri;
-               document.getElementsByTagName( 'head' )[0].appendChild( script );
-       }() );
-} else {
-       // Undo class swapping in case of an unsupported browser.
-       // See OutputPage::getHeadScripts().
-       document.documentElement.className = document.documentElement.className
-               .replace( /(^|\s)client-js(\s|$)/, '$1client-nojs$2' );
-}
+       document.getElementsByTagName( 'head' )[0].appendChild( script );
+}() );