* @return {string} JavaScript code for $context
*/
public function getScript( ResourceLoaderContext $context ) {
- global $wgScriptPath;
+ global $wgServer, $wgScriptPath;
$files = array_merge(
$this->scripts,
if ( $context->getDebug() ) {
$files = array_merge( $files, $this->debugScripts );
if ( $this->debugRaw ) {
- $tags = '';
+ $script = '';
foreach ( $files as $file ) {
- $tags .= "<script type=\"text/javascript\" src=\"$wgScriptPath/$file\"></script>";
+ $path = FormatJson::encode( "$wgServer$wgScriptPath/$file" );
+ $script .= "\n\tmediaWiki.loader.load( $path );";
}
- return "\n\tdocument.write( " . FormatJson::encode( $tags ) . ' );';
+ return $script;
}
}
return self::readScriptFiles( $files );
// Support adding arbitrary external scripts
if ( modules.substr( 0, 7 ) == 'http://' || modules.substr( 0, 8 ) == 'https://' ) {
if ( type === 'text/css' ) {
- setTimeout( function() {
- $( 'head' ).append( '<link rel="stylesheet" type="text/css" />' ).attr( 'href', modules );
- }, 0 );
+ $( 'head' ).append( $( '<link rel="stylesheet" type="text/css" />' ).attr( 'href', modules ) );
return true;
} else if ( type === 'text/javascript' || typeof type === 'undefined' ) {
- setTimeout( function() {
- $( 'body' ).append( '<script type="text/javascript"></script>' ).attr( 'src', modules )
- }, 0 );
+ var script = '<script type="text/javascript" src="' + modules + '"></script>';
+ if ( ready ) {
+ $( 'body' ).append( script );
+ } else {
+ document.write( script );
+ }
return true;
}
// Unknown type