]> source.dussan.org Git - jquery.git/commitdiff
Consistently clean up after .ready() handler, close gh-1135.
authorOleg <markelog@gmail.com>
Tue, 15 Jan 2013 14:45:21 +0000 (18:45 +0400)
committerDave Methvin <dave.methvin@gmail.com>
Sun, 20 Jan 2013 23:20:53 +0000 (18:20 -0500)
src/core.js

index 202188debc83721e62c5c3d1599c307ec73b728e..d909c8144dda508cc72ca0a4e5924f1c1f7dd468 100644 (file)
@@ -62,8 +62,9 @@ var
        },
 
        // The ready event handler and self cleanup method
-       DOMContentLoaded = function() {
-               document.removeEventListener( "DOMContentLoaded", DOMContentLoaded, false );
+       completed = function() {
+               document.removeEventListener( "DOMContentLoaded", completed, false );
+               window.removeEventListener( "load", completed, false );
                jQuery.ready();
        };
 
@@ -770,13 +771,13 @@ jQuery.ready.promise = function( obj ) {
                        // Handle it asynchronously to allow scripts the opportunity to delay ready
                        setTimeout( jQuery.ready );
 
-               // Standards-based browsers support DOMContentLoaded
                } else {
+
                        // Use the handy event callback
-                       document.addEventListener( "DOMContentLoaded", DOMContentLoaded, false );
+                       document.addEventListener( "DOMContentLoaded", completed, false );
 
                        // A fallback to window.onload, that will always work
-                       window.addEventListener( "load", jQuery.ready, false );
+                       window.addEventListener( "load", completed, false );
                }
        }
        return readyList.promise( obj );