-/*jslint browser: true, continue: true, white: true, forin: true*/
-/*global jQuery*/
/*
* Core MediaWiki JavaScript Library
*/
/* Private Members */
- var hasOwn = Object.prototype.hasOwnProperty;
+ var hasOwn = Object.prototype.hasOwnProperty,
+ slice = Array.prototype.slice;
+
/* Object constructors */
/**
var results, i;
if ( $.isArray( selection ) ) {
- selection = $.makeArray( selection );
+ selection = slice.call( selection );
results = {};
for ( i = 0; i < selection.length; i += 1 ) {
results[selection[i]] = this.get( selection[i], fallback );
this.format = 'plain';
this.map = map;
this.key = key;
- this.parameters = parameters === undefined ? [] : $.makeArray( parameters );
+ this.parameters = parameters === undefined ? [] : slice.call( parameters );
return this;
}
*
* This function will not be called for nonexistent messages.
*/
- parser: function() {
+ parser: function () {
var parameters = this.parameters;
return this.map.get( this.key ).replace( /\$(\d+)/g, function ( str, match ) {
var index = parseInt( match, 10 ) - 1;
*
* @return string Message as a string in the current form or <key> if key does not exist.
*/
- toString: function() {
+ toString: function () {
var text;
if ( !this.exists() ) {
*
* @return {string} String form of parsed message
*/
- parse: function() {
+ parse: function () {
this.format = 'parse';
return this.toString();
},
*
* @return {string} String form of plain message
*/
- plain: function() {
+ plain: function () {
this.format = 'plain';
return this.toString();
},
*
* @return {string} String form of html escaped message
*/
- escaped: function() {
+ escaped: function () {
this.format = 'escaped';
return this.toString();
},
*
* @return {string} String form of parsed message
*/
- exists: function() {
+ exists: function () {
return this.map.exists( this.key );
}
};
* Dummy function which in debug mode can be replaced with a function that
* emulates console.log in console-less environments.
*/
- log: function() { },
+ log: function () { },
/**
* @var constructor Make the Map constructor publicly available.
var parameters;
// Support variadic arguments
if ( parameter_1 !== undefined ) {
- parameters = $.makeArray( arguments );
+ parameters = slice.call( arguments );
parameters.shift();
} else {
parameters = [];
},
/**
- * Gets a message string, similar to wfMsg()
+ * Gets a message string, similar to wfMessage()
*
* @param key string Key of message to get
* @param parameters mixed First argument in a list of variadic arguments,
* {
* 'moduleName': {
* 'version': ############## (unix timestamp),
- * 'dependencies': ['required.foo', 'bar.also', ...], (or) function() {}
+ * 'dependencies': ['required.foo', 'bar.also', ...], (or) function () {}
* 'group': 'somegroup', (or) null,
* 'source': 'local', 'someforeignwiki', (or) null
* 'state': 'registered', 'loading', 'loaded', 'ready', 'error' or 'missing'
* }
* }
*/
- var registry = {},
+ var registry = {},
/**
* Mapping of sources, keyed by source-id, values are objects.
* Format:
queue = [],
// List of callback functions waiting for modules to be ready to be called
jobs = [],
- // Flag indicating that document ready has occured
- ready = false,
// Selector cache for the marker element. Use getMarker() to get/use the marker!
$marker = null;
- /* Cache document ready status */
-
- $(document).ready( function () {
- ready = true;
- } );
-
/* Private methods */
function getMarker() {
var console = window.console;
if ( console && console.log ) {
console.log( msg );
- // console.error triggers the proper handling of exception objects in
- // consoles that support it. Fallback to passing as plain object to log().
- if ( e ) {
- (console.error || console.log).call( console, e );
+ // If we have an exception object, log it through .error() to trigger
+ // proper stacktraces in browsers that support it. There are no (known)
+ // browsers that don't support .error(), that do support .log() and
+ // have useful exception handling through .log().
+ if ( e && console.error ) {
+ console.error( e );
}
}
}
} catch ( ex ) {
// A user-defined operation raised an exception. Swallow to protect
// our state machine!
- log( 'mw.loader::handlePending> Exception thrown by job.error()', ex );
+ log( 'Exception thrown by job.error()', ex );
}
}
}
* @param callback Function: Optional callback which will be run when the script is done
*/
function addScript( src, callback, async ) {
- var done = false, script, head;
- if ( ready || async ) {
+ /*jshint evil:true */
+ var script, head,
+ done = false;
+
+ // Using isReady directly instead of storing it locally from
+ // a $.fn.ready callback (bug 31895).
+ if ( $.isReady || async ) {
// jQuery's getScript method is NOT better than doing this the old-fashioned way
// because jQuery will eval the script's code, and errors will not have sane
// line numbers.
script.setAttribute( 'type', 'text/javascript' );
if ( $.isFunction( callback ) ) {
// Attach handlers for all browsers (based on jQuery.ajax)
- script.onload = script.onreadystatechange = function() {
+ script.onload = script.onreadystatechange = function () {
if (
!done
// scripts only start loading after the document has been rendered,
// but so be it. Opera users don't deserve faster web pages if their
// browser makes it impossible
- $( function() { document.body.appendChild( script ); } );
+ $( function () { document.body.appendChild( script ); } );
} else {
// IE-safe way of getting the <head> . document.documentElement.head doesn't
// work in scripts that run in the <head>
// Execute script
try {
script = registry[module].script;
- markModuleReady = function() {
+ markModuleReady = function () {
registry[module].state = 'ready';
handlePending( module );
};
return;
}
- addScript( arr[i], function() {
+ addScript( arr[i], function () {
nestedAddScript( arr, callback, async, i + 1 );
}, async );
};
registry[module].state = 'loading';
nestedAddScript( script, markModuleReady, registry[module].async, 0 );
} else if ( $.isFunction( script ) ) {
+ registry[module].state = 'ready';
script( $ );
- markModuleReady();
+ handlePending( module );
}
} catch ( e ) {
// This needs to NOT use mw.log because these errors are common in production mode
// Allow calling by single module name
if ( typeof dependencies === 'string' ) {
dependencies = [dependencies];
- if ( registry[dependencies[0]] !== undefined ) {
- // Cache repetitively accessed deep level object member
- regItemDeps = registry[dependencies[0]].dependencies;
- // Cache to avoid looped access to length property
- regItemDepLen = regItemDeps.length;
- for ( n = 0; n < regItemDepLen; n += 1 ) {
- dependencies[dependencies.length] = regItemDeps[n];
- }
- }
}
// Add ready and error callbacks if they were given
}
}
- if (filtered.length === 0) {
+ if ( filtered.length === 0 ) {
return;
}
// Resolve entire dependency map