More mediawiki.js cleanup (addScript AJAX)
authorKrinkle <krinkle@users.mediawiki.org>
Sun, 24 Jul 2011 20:38:49 +0000 (20:38 +0000)
committerKrinkle <krinkle@users.mediawiki.org>
Sun, 24 Jul 2011 20:38:49 +0000 (20:38 +0000)
- Update and merge in jQuery fixes:
-- Dereference script (added)
-- Order of actions
-- Regex instead of two string comparisons
-- Unit tests still pass :)

Follows up: r92933, 93012

resources/mediawiki/mediawiki.js

index fd3f03e..4bb14a3 100644 (file)
@@ -685,23 +685,30 @@ window.mw = window.mediaWiki = new ( function( $ ) {
                                script.setAttribute( 'src', src );
                                script.setAttribute( 'type', 'text/javascript' );
                                if ( $.isFunction( callback ) ) {
-                                       // Attach handlers for all browsers -- this is based on jQuery.getScript
+                                       // Attach handlers for all browsers -- this is based on jQuery.ajax
                                        script.onload = script.onreadystatechange = function() {
+
                                                if (
                                                        !done
                                                        && (
-                                                               !this.readyState
-                                                               || this.readyState === 'loaded'
-                                                               || this.readyState === 'complete'
+                                                               !script.readyState
+                                                               || /loaded|complete/.test( script.readyState )
                                                        )
                                                ) {
+
                                                        done = true;
-                                                       callback();
+
                                                        // Handle memory leak in IE
                                                        script.onload = script.onreadystatechange = null;
+
+                                                       callback();
+
                                                        if ( script.parentNode ) {
                                                                script.parentNode.removeChild( script );
                                                        }
+
+                                                       // Dereference the script
+                                                       script = undefined;
                                                }
                                        };
                                }