r88073 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88072‎ | r88073 | r88074 >
Date:13:14, 14 May 2011
Author:tparscal
Status:ok
Tags:
Comment:
Improves on r88053 - added code basically lifted from jQuery.getScript which ensures that onreadystatechange is handled properly - only executing the callback when the state is changed to the correct state, and only calling it one time. Thanks John Resig!
Modified paths:
  • /trunk/phase3/resources/mediawiki/mediawiki.js (modified) (history)

Diff [purge]

Index: trunk/phase3/resources/mediawiki/mediawiki.js
@@ -933,7 +933,26 @@
934934 script.setAttribute( 'src', src );
935935 script.setAttribute( 'type', 'text/javascript' );
936936 if ( $.isFunction( callback ) ) {
937 - script.onload = script.onreadystatechange = callback;
 937+ var done = false;
 938+ // Attach handlers for all browsers -- this is based on jQuery.getScript
 939+ script.onload = script.onreadystatechange = function() {
 940+ if (
 941+ !done
 942+ && (
 943+ !this.readyState
 944+ || this.readyState === "loaded"
 945+ || this.readyState === "complete"
 946+ )
 947+ ) {
 948+ done = true;
 949+ callback();
 950+ // Handle memory leak in IE
 951+ script.onload = script.onreadystatechange = null;
 952+ if ( script.parentNode ) {
 953+ script.parentNode.removeChild( script );
 954+ }
 955+ }
 956+ };
938957 }
939958 document.body.appendChild( script );
940959 } else {

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r88053Added direct file loading functionality to debug mode for both scripts and st...tparscal12:15, 14 May 2011

Status & tagging log