if ( self::inDebugMode() ) {
$scripts = new XmlJsCode( "function ( $, jQuery, require, module ) {\n{$scripts->value}\n}" );
} else {
- $scripts = new XmlJsCode( 'function($,jQuery,require,module){'. $scripts->value . '}' );
+ $scripts = new XmlJsCode( 'function($,jQuery,require,module){' . $scripts->value . '}' );
}
} elseif ( !is_string( $scripts ) && !is_array( $scripts ) ) {
throw new MWException( 'Invalid scripts error. Array of URLs or string of code expected.' );
);
}
- /**
- * Returns JS code which calls the script given by $script. The script will
- * be called with local variables name, version, dependencies and group,
- * which will have values corresponding to $name, $version, $dependencies
- * and $group as supplied.
- *
- * @param string $name Module name
- * @param string $version Module version hash
- * @param array $dependencies List of module names on which this module depends
- * @param string $group Group which the module is in.
- * @param string $source Source of the module, or 'local' if not foreign.
- * @param string $script JavaScript code
- * @return string JavaScript code
- */
- 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} )",
- [ $name, $version, $dependencies, $group, $source ],
- self::inDebugMode()
- );
- }
-
private static function isEmptyObject( stdClass $obj ) {
foreach ( $obj as $key => $value ) {
return false;
* - ResourceLoader::makeLoaderSourcesScript( [ $id1 => $loadUrl, $id2 => $loadUrl, ... ] );
* Register sources with the given IDs and properties.
*
- * @param string $id Source ID
+ * @param string|array $sources Source ID
* @param string|null $loadUrl load.php url
* @return string JavaScript code
*/
- public static function makeLoaderSourcesScript( $id, $loadUrl = null ) {
- if ( is_array( $id ) ) {
- return Xml::encodeJsCall(
- 'mw.loader.addSource',
- [ $id ],
- self::inDebugMode()
- );
- } else {
- return Xml::encodeJsCall(
- 'mw.loader.addSource',
- [ $id, $loadUrl ],
- self::inDebugMode()
- );
+ public static function makeLoaderSourcesScript( $sources, $loadUrl = null ) {
+ if ( !is_array( $sources ) ) {
+ $sources = [ $sources => $loadUrl ];
}
+ return Xml::encodeJsCall(
+ 'mw.loader.addSource',
+ [ $sources ],
+ self::inDebugMode()
+ );
}
/**