Merge "Work around T87871 to avoid double-loading OOjs UI PHP styles"
[lhc/web/wiklou.git] / resources / src / startup.js
index 97b4fce..e53e5f3 100644 (file)
@@ -3,16 +3,16 @@
  * continue loading jQuery and the MediaWiki modules. This code should work on
  * even the most ancient of browsers, so be very careful when editing.
  */
+/*jshint unused: false, evil: true */
+/*globals mw, RLQ: true, NORLQ: true, $VARS, $CODE, performance */
 
-var mediaWikiLoadStart = ( new Date() ).getTime();
+var mediaWikiLoadStart = ( new Date() ).getTime(),
 
-if ( !window.performance ) {
-       window.performance = {};
-}
-if ( !performance.mark ) {
-       performance.mark = function () {};
-}
-performance.mark( 'mwLoadStart' );
+       mwPerformance = ( window.performance && performance.mark ) ? performance : {
+               mark: function () {}
+       };
+
+mwPerformance.mark( 'mwLoadStart' );
 
 /**
  * Returns false for Grade C supported browsers.
@@ -24,9 +24,6 @@ performance.mark( 'mwLoadStart' );
  * - https://www.mediawiki.org/wiki/Compatibility#Browsers
  * - https://jquery.com/browser-support/
  */
-
-/*jshint unused: false, evil: true */
-/*globals mw, RLQ: true, $VARS, $CODE */
 function isCompatible( ua ) {
        if ( ua === undefined ) {
                ua = navigator.userAgent;
@@ -34,8 +31,8 @@ function isCompatible( ua ) {
 
        // Browsers with outdated or limited JavaScript engines get the no-JS experience
        return !(
-               // Internet Explorer < 8
-               ( ua.indexOf( 'MSIE' ) !== -1 && parseFloat( ua.split( 'MSIE' )[ 1 ] ) < 8 ) ||
+               // Internet Explorer < 9
+               ( ua.indexOf( 'MSIE' ) !== -1 && parseFloat( ua.split( 'MSIE' )[ 1 ] ) < 9 ) ||
                // Firefox < 3
                ( ua.indexOf( 'Firefox/' ) !== -1 && parseFloat( ua.split( 'Firefox/' )[ 1 ] ) < 3 ) ||
                // Opera < 12
@@ -70,11 +67,29 @@ function isCompatible( ua ) {
 
 // Conditional script injection
 ( function () {
+       var NORLQ, script;
        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' );
+
+               NORLQ = window.NORLQ || [];
+               while ( NORLQ.length ) {
+                       NORLQ.shift()();
+               }
+               window.NORLQ = {
+                       push: function ( fn ) {
+                               fn();
+                       }
+               };
+
+               // Clear and disable the other queue
+               window.RLQ = {
+                       // No-op
+                       push: function () {}
+               };
+
                return;
        }
 
@@ -90,7 +105,7 @@ function isCompatible( ua ) {
 
                // 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 || [];
+               var RLQ = window.RLQ || [];
                while ( RLQ.length ) {
                        RLQ.shift()();
                }
@@ -99,9 +114,15 @@ function isCompatible( ua ) {
                                fn();
                        }
                };
+
+               // Clear and disable the other queue
+               window.NORLQ = {
+                       // No-op
+                       push: function () {}
+               };
        }
 
-       var script = document.createElement( 'script' );
+       script = document.createElement( 'script' );
        script.src = $VARS.baseModulesUri;
        script.onload = script.onreadystatechange = function () {
                if ( !script.readyState || /loaded|complete/.test( script.readyState ) ) {