*/
var registry = {},
//
- // Mapping of sources, keyed by source-id, values are objects.
+ // Mapping of sources, keyed by source-id, values are strings.
// Format:
// {
- // 'sourceId': {
- // 'loadScript': 'http://foo.bar/w/load.php'
- // }
+ // 'sourceId': 'http://foo.bar/w/load.php'
// }
//
sources = {},
for ( source in splits ) {
- sourceLoadScript = sources[source].loadScript;
+ sourceLoadScript = sources[source];
for ( group in splits[source] ) {
for ( i = 0; i < modules.length; i += 1 ) {
// Determine how many bytes this module would add to the query string
lastDotIndex = modules[i].lastIndexOf( '.' );
- // Note that these substr() calls work even if lastDotIndex == -1
+
+ // If lastDotIndex is -1, substr() returns an empty string
prefix = modules[i].substr( 0, lastDotIndex );
- suffix = modules[i].substr( lastDotIndex + 1 );
+ suffix = modules[i].slice( lastDotIndex + 1 );
+
bytesAdded = moduleMap[prefix] !== undefined
? suffix.length + 3 // '%2C'.length == 3
: modules[i].length + 3; // '%7C'.length == 3
*
* The #work method will use this information to split up requests by source.
*
- * mw.loader.addSource( 'mediawikiwiki', { loadScript: '//www.mediawiki.org/w/load.php' } );
+ * mw.loader.addSource( 'mediawikiwiki', '//www.mediawiki.org/w/load.php' );
*
* @param {string} id Short string representing a source wiki, used internally for
* registered modules to indicate where they should be loaded from (usually lowercase a-z).
- * @param {Object} props
- * @param {string} props.loadScript Url to the load.php entry point of the source wiki.
+ * @param {Object|string} loadUrl load.php url, may be an object for backwards-compatability
* @return {boolean}
*/
- addSource: function ( id, props ) {
+ addSource: function ( id, loadUrl ) {
var source;
// Allow multiple additions
if ( typeof id === 'object' ) {
throw new Error( 'source already registered: ' + id );
}
- sources[id] = props;
+ if ( typeof loadUrl === 'object' ) {
+ loadUrl = loadUrl.loadScript;
+ }
+
+ sources[id] = loadUrl;
return true;
},
*
* @param {string|Array} modules Either the name of a module, array of modules,
* or a URL of an external script or style
- * @param {string} [type='text/javascript'] mime-type to use if calling with a URL of an
+ * @param {string} [type='text/javascript'] MIME type to use if calling with a URL of an
* external script or style; acceptable values are "text/css" and
* "text/javascript"; if no type is provided, text/javascript is assumed.
* @param {boolean} [async] Whether to load modules asynchronously.
}
for ( key in mw.loader.store.items ) {
- module = key.substring( 0, key.indexOf( '@' ) );
+ module = key.slice( 0, key.indexOf( '@' ) );
if ( mw.loader.store.getModuleKey( module ) !== key ) {
mw.loader.store.stats.expired++;
delete mw.loader.store.items[key];