*
* - Beware: This file MUST parse without errors on even the most ancient of browsers!
*/
-
+/* eslint-disable vars-on-top, no-unmodified-loop-condition */
/* global mw, isCompatible, $VARS, $CODE */
/**
);
};
-// Conditional script injection
( function () {
var NORLQ, script;
+ // Handle Grade C
if ( !isCompatible() ) {
- // Undo class swapping in case of an unsupported browser.
- // See ResourceLoaderClientHtml::getDocumentAttributes().
+ // Undo speculative Grade A <html> class. See ResourceLoaderClientHtml::getDocumentAttributes().
document.documentElement.className = document.documentElement.className
.replace( /(^|\s)client-js(\s|$)/, '$1client-nojs$2' );
- NORLQ = window.NORLQ || [];
- while ( NORLQ.length ) {
+ // Process any callbacks for Grade C
+ NORLQ = window.NORLQ;
+ while ( NORLQ && NORLQ[ 0 ] ) {
NORLQ.shift()();
}
window.NORLQ = {
}
};
- // Clear and disable the other queue
+ // Clear and disable the Grade A queue
window.RLQ = {
- // No-op
push: function () {}
};
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.
- // eslint-disable-next-line vars-on-top
- var RLQ = window.RLQ || [];
- while ( RLQ.length ) {
- RLQ.shift()();
- }
+ // Process callbacks for Grade A
+ // Must be after registrations and mw.config.set, which mw.loader depends on.
+ var queue = window.RLQ;
window.RLQ = {
push: function ( fn ) {
- fn();
+ if ( typeof fn === 'function' ) {
+ fn();
+ } else {
+ // This callback has a requirement.
+ mw.loader.using( fn[ 0 ], fn[ 1 ] );
+ }
}
};
+ while ( queue && queue[ 0 ] ) {
+ // Re-use our push()
+ window.RLQ.push( queue.shift() );
+ }
- // Clear and disable the other queue
+ // Clear and disable the Grade C queue
window.NORLQ = {
- // No-op
push: function () {}
};
}
);
} );
+ QUnit.test( 'RLQ.push', function ( assert ) {
+ /* global RLQ */
+ var loaded = 0,
+ done = assert.async();
+ mw.loader.testCallback = function () {
+ loaded++;
+ delete mw.loader.testCallback;
+ };
+ mw.loader.implement( 'test.rlq-push', [ QUnit.fixurl( mw.config.get( 'wgScriptPath' ) + '/tests/qunit/data/mwLoaderTestCallback.js' ) ] );
+
+ RLQ.push( [ 'test.rlq-push', function () {
+ assert.strictEqual( loaded, 1, 'Load the required module' );
+ done();
+ } ] );
+ } );
+
}( mediaWiki ) );