Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F7173
mediawiki.js.patch
Public
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
•
bzimport
Nov 21 2014, 11:17 PM
2014-11-21 23:17:21 (UTC+0)
Size
4 KB
Referenced Files
None
Subscribers
None
mediawiki.js.patch
View Options
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
Details
Attached
Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
6708
Default Alt Text
mediawiki.js.patch (4 KB)
Attached To
Mode
T29023: After the document is ready mw.loader is broken (calls callback before module is parsed)
Attached
Detach File
Event Timeline
Log In to Comment