[RL] Comment mod and other minor changes

_ Add comment about why it casts to (object)
- Modify function comment
- Whitespace (start the function body on a new line in debug mode. In production mode this is trimmed away afterwards)
- Remove the jQuery->$ passage from loader. There is already a global alias for $ by jQuery, and aside from that every module has it's own (function(){}) wrapper that aliases it from jQuery (not from $), so there is no performance gain either by having it locally here since it doesn't use that.
This commit is contained in:
Krinkle 2012-02-13 15:17:15 +00:00
parent d956040d08
commit 5bf04171dc
2 changed files with 12 additions and 6 deletions

View file

@ -354,6 +354,7 @@ class ResourceLoader {
* @return Array
*/
public function getTestModuleNames( $framework = 'all' ) {
/// @TODO: api siteinfo prop testmodulenames modulenames
if ( $framework == 'all' ) {
return $this->testModuleNames;
} elseif ( isset( $this->testModuleNames[$framework] ) && is_array( $this->testModuleNames[$framework] ) ) {
@ -797,7 +798,7 @@ class ResourceLoader {
*
* @param $name string Module name
* @param $scripts Mixed: List of URLs to JavaScript files or String of JavaScript code
* @param $styles Mixed: List of CSS strings keyed by media type, or list of lists of URLs to
* @param $styles Mixed: Array of CSS strings keyed by media type, or an array of lists of URLs to
* CSS files keyed by media type
* @param $messages Mixed: List of messages associated with this module. May either be an
* associative array mapping message key to value, or a JSON-encoded message blob containing
@ -807,7 +808,7 @@ class ResourceLoader {
*/
public static function makeLoaderImplementScript( $name, $scripts, $styles, $messages ) {
if ( is_string( $scripts ) ) {
$scripts = new XmlJsCode( "function( $ ) {{$scripts}}" );
$scripts = new XmlJsCode( "function () {\n{$scripts}\n}" );
} elseif ( !is_array( $scripts ) ) {
throw new MWException( 'Invalid scripts error. Array of URLs or string of code expected.' );
}
@ -816,6 +817,11 @@ class ResourceLoader {
array(
$name,
$scripts,
// Force objects. mw.loader.implement requires them to be javascript objects.
// Although these variables are associative arrays, which become javascript
// objects through json_encode. In many cases they will be empty arrays, and
// PHP/json_encode() consider empty arrays to be numerical arrays and
// output javascript "[]" instead of "{}". This fixes that.
(object)$styles,
(object)$messages
) );
@ -901,7 +907,7 @@ class ResourceLoader {
public static function makeCustomLoaderScript( $name, $version, $dependencies, $group, $source, $script ) {
$script = str_replace( "\n", "\n\t", trim( $script ) );
return Xml::encodeJsCall(
"( function( name, version, dependencies, group, source ) {\n\t$script\n} )",
"( function ( name, version, dependencies, group, source ) {\n\t$script\n} )",
array( $name, $version, $dependencies, $group, $source ) );
}

View file

@ -315,7 +315,7 @@ var mw = ( function ( $, undefined ) {
/**
* Client-side module loader which integrates with the MediaWiki ResourceLoader
*/
loader: ( function() {
loader: ( function () {
/* Private Members */
@ -756,7 +756,7 @@ var mw = ( function ( $, undefined ) {
registry[module].state = 'loading';
nestedAddScript( script, markModuleReady, registry[module].blocking, 0 );
} else if ( $.isFunction( script ) ) {
script( $ );
script();
markModuleReady();
}
} catch ( e ) {
@ -1418,7 +1418,7 @@ var mw = ( function ( $, undefined ) {
return s;
}
};
})()
}() )
};
})( jQuery );