Page MenuHomePhabricator

mediawiki.js.patch

Authored By
bzimport
Nov 21 2014, 11:17 PM
Size
4 KB
Referenced Files
None
Subscribers
None

mediawiki.js.patch

Index: resources/mediawiki/mediawiki.js
===================================================================
--- resources/mediawiki/mediawiki.js (revision 81178)
+++ resources/mediawiki/mediawiki.js (working copy)
@@ -480,8 +480,8 @@
var jobs = [];
// Flag indicating that requests should be suspended
var suspended = true;
- // Flag inidicating that document ready has occured
- var ready = false;
+ // Flag inidicating that document is ready
+ var documentReady = false;
// Marker element for adding dynamic styles
var $marker = $( 'head meta[name=ResourceLoaderDynamicStyles]' );
@@ -518,7 +518,7 @@
pad( d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds() ), 'Z'
].join( '' );
}
-
+
/**
* Recursively resolves dependencies and detects circular references
*/
@@ -757,6 +757,35 @@
}
return sorted;
}
+
+ /**
+ * Appends a set of scripts to the dom
+ * @param url {Mixed} Array or single url string
+ * @param callback {function} function called once scripts are loaded
+ */
+ function appendScript( url, callback ){
+ if( ! url )
+ return ;
+ // Load asynchronously after document ready
+ if ( documentReady ) {
+ // Load without jQuery to avoid $.globalEval issue
+ var script = document.createElement( "script" );
+ script.setAttribute( 'src', url );
+ script.setAttribute( 'type', 'text/javascript' );
+ if( callback ){
+ script.onload = callback;
+ }
+ document.getElementsByTagName("body")[ 0 ].appendChild( script );
+ } else {
+ var script = mediaWiki.html.element( 'script',
+ { type: 'text/javascript', src: url }, '' );
+ document.write( script );
+ // document.write blocks script execution so we can directly run the callback:
+ if( callback ){
+ callback();
+ }
+ }
+ }
/* Public Methods */
@@ -821,22 +850,13 @@
// include modules which are already loaded
batch = [];
// Asynchronously append a script tag to the end of the body
- function request() {
- var html = '';
+ function getRequestUrs() {
+ var urls = [];
for ( var r = 0; r < requests.length; r++ ) {
requests[r] = sortQuery( requests[r] );
// Build out the HTML
- var src = mediaWiki.config.get( 'wgLoadScript' ) + '?' + $.param( requests[r] );
- html += mediaWiki.html.element( 'script',
- { type: 'text/javascript', src: src }, '' );
- }
- return html;
- }
- // Load asynchronously after doumument ready
- if ( ready ) {
- setTimeout( function() { $( 'body' ).append( request() ); }, 0 )
- } else {
- document.write( request() );
+ appendScript( mediaWiki.config.get( 'wgLoadScript' ) + '?' + $.param( requests[r] ) );
+ }
}
}
};
@@ -947,7 +967,7 @@
// 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' ) {
@@ -987,7 +1007,7 @@
// Validate input
if ( typeof modules !== 'object' && typeof modules !== 'string' ) {
throw new Error( 'dependencies must be a string or an array, not a ' +
- typeof dependencies )
+ typeof dependencies );
}
// Allow calling with an external script or single dependency as a string
if ( typeof modules === 'string' ) {
@@ -1001,13 +1021,7 @@
.attr( 'href', modules ) );
return true;
} else if ( type === 'text/javascript' || typeof type === 'undefined' ) {
- var script = mediaWiki.html.element( 'script',
- { type: 'text/javascript', src: modules }, '' );
- if ( ready ) {
- $( 'body' ).append( script );
- } else {
- document.write( script );
- }
+ appendScript( modules );
return true;
}
// Unknown type
@@ -1074,7 +1088,7 @@
/* Cache document ready status */
- $(document).ready( function() { ready = true; } );
+ $(document).ready( function() { documentReady = true; } );
} )();
/** HTML construction helper functions */

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
6708
Default Alt Text
mediawiki.js.patch (4 KB)

Event Timeline