jQuery.extend({
trimLeft : function( str ) {
- return str == null ? '' : str.toString().replace( /^\s+/, '' );
+ return str === null ? '' : str.toString().replace( /^\s+/, '' );
},
trimRight : function( str ) {
- return str == null ?
+ return str === null ?
'' : str.toString().replace( /\s+$/, '' );
},
ucFirst : function( str ) {
Message.prototype.escaped = function() {
this.format = 'escaped';
return this.toString();
- }
+ };
/**
* Checks if message exists
*/
this.sessionId = function () {
var sessionId = $.cookie( 'mediaWiki.user.sessionId' );
- if ( typeof sessionId == 'undefined' || sessionId == null ) {
+ if ( typeof sessionId == 'undefined' || sessionId === null ) {
sessionId = generateId();
$.cookie( 'mediaWiki.user.sessionId', sessionId, { 'expires': null, 'path': '/' } );
}
return name;
}
var id = $.cookie( 'mediaWiki.user.id' );
- if ( typeof id == 'undefined' || id == null ) {
+ if ( typeof id == 'undefined' || id === null ) {
id = generateId();
}
// Set cookie if not set, or renew it if already set
* mediawiki.
*
* Format:
- * {
- * 'moduleName': {
- * 'dependencies': ['required module', 'required module', ...], (or) function() {}
- * 'state': 'registered', 'loading', 'loaded', 'ready', or 'error'
- * 'script': function() {},
- * 'style': 'css code string',
- * 'messages': { 'key': 'value' },
- * 'version': ############## (unix timestamp)
- * }
- * }
+ * {
+ * 'moduleName': {
+ * 'dependencies': ['required module', 'required module', ...], (or) function() {}
+ * 'state': 'registered', 'loading', 'loaded', 'ready', or 'error'
+ * 'script': function() {},
+ * 'style': 'css code string',
+ * 'messages': { 'key': 'value' },
+ * 'version': ############## (unix timestamp)
+ * }
+ * }
*/
var registry = {};
// List of modules which will be loaded as when ready
throw new Error( 'Unknown dependency: ' + module );
}
// Resolves dynamic loader function and replaces it with its own results
- if ( typeof registry[module].dependencies === 'function' ) {
+ if ( $.isFunction( registry[module].dependencies ) ) {
registry[module].dependencies = registry[module].dependencies();
// Ensures the module's dependencies are always in an array
if ( typeof registry[module].dependencies !== 'object' ) {
states = [states];
}
// If called without a list of modules, build and use a list of all modules
- var list = [];
+ var list = [], module;
if ( typeof modules === 'undefined' ) {
modules = [];
for ( module in registry ) {
* @param module string module name to execute
*/
function execute( module ) {
+ var _method = 'mw.loader::execute';
if ( typeof registry[module] === 'undefined' ) {
throw new Error( 'Module has not been registered yet: ' + module );
} else if ( registry[module].state === 'registered' ) {
new mediaWiki.html.Cdata( registry[module].style )
) );
} else if ( typeof registry[module].style === 'object'
- && !( registry[module].style instanceof Array ) )
+ && !( $.isArray( registry[module].style ) ) )
{
for ( var media in registry[module].style ) {
$marker.before( mediaWiki.html.element( 'style',
// Execute script
try {
registry[module].script( jQuery );
+ mw.log( 'State ready: ' + module, _method )
registry[module].state = 'ready';
// Run jobs who's dependencies have just been met
for ( var j = 0; j < jobs.length; j++ ) {
filter( 'ready', jobs[j].dependencies ),
jobs[j].dependencies ) )
{
- if ( typeof jobs[j].ready === 'function' ) {
+ if ( $.isFunction( jobs[j].ready ) ) {
jobs[j].ready();
}
jobs.splice( j, 1 );
}
}
// Execute modules who's dependencies have just been met
- for ( r in registry ) {
+ for ( var r in registry ) {
if ( registry[r].state == 'loaded' ) {
if ( compare(
filter( ['ready'], registry[r].dependencies ),
}
}
} catch ( e ) {
- mediaWiki.log( 'Exception thrown by ' + module + ': ' + e.message );
+ mediaWiki.log( 'Exception thrown by ' + module + ': ' + e.message, _method );
mediaWiki.log( e );
registry[module].state = 'error';
// Run error callbacks of jobs affected by this condition
for ( var j = 0; j < jobs.length; j++ ) {
if ( $.inArray( module, jobs[j].dependencies ) !== -1 ) {
- if ( typeof jobs[j].error === 'function' ) {
+ if ( $.isFunction( jobs[j].error ) ) {
jobs[j].error();
}
jobs.splice( j, 1 );
}
// Load asynchronously after documument ready
if ( ready ) {
- setTimeout( function() { $( 'body' ).append( request() ); }, 0 )
+ setTimeout( function() { $( 'body' ).append( request() ); }, 0 );
} else {
document.write( request() );
}
'state': 'registered',
'group': typeof group === 'string' ? group : null,
'dependencies': [],
- 'version': typeof version !== 'undefined' ? parseInt( version ) : 0
+ 'version': typeof version !== 'undefined' ? parseInt( version, 10 ) : 0
};
if ( typeof dependencies === 'string' ) {
// Allow dependencies to be given as a single module name
registry[module].dependencies = [dependencies];
- } else if ( typeof dependencies === 'object' || typeof dependencies === 'function' ) {
+ } else if ( typeof dependencies === 'object' || $.isFunction( dependencies ) ) {
// Allow dependencies to be given as an array of module names
// or a function which returns an array
registry[module].dependencies = dependencies;
mediaWiki.loader.register( module );
}
// Validate input
- if ( typeof script !== 'function' ) {
+ if ( !$.isFunction( script ) ) {
throw new Error( 'script must be a function, not a ' + typeof script );
}
if ( typeof style !== 'undefined'
// Validate input
if ( typeof dependencies !== 'object' && typeof dependencies !== 'string' ) {
throw new Error( 'dependencies must be a string or an array, not a ' +
- typeof dependencies )
+ typeof dependencies );
}
// Allow calling with a single dependency as a string
if ( typeof dependencies === 'string' ) {
dependencies = resolve( dependencies );
// If all dependencies are met, execute ready immediately
if ( compare( filter( ['ready'], dependencies ), dependencies ) ) {
- if ( typeof ready === 'function' ) {
+ if ( $.isFunction( ready ) ) {
ready();
}
}
// If any dependencies have errors execute error immediately
else if ( filter( ['error'], dependencies ).length ) {
- if ( typeof error === 'function' ) {
+ if ( $.isFunction( error ) ) {
error();
}
}
// Validate input
if ( typeof modules !== 'object' && typeof modules !== 'string' ) {
throw new Error( 'modules must be a string or an array, not a ' +
- typeof modules )
+ typeof modules );
}
// Allow calling with an external script or single dependency as a string
if ( typeof modules === 'string' ) {
/* Auto-register from pre-loaded startup scripts */
-if ( typeof startUp === 'function' ) {
+if ( $.isFunction( startUp ) ) {
startUp();
delete startUp;
}