Commit f3c776dc authored by Oleg's avatar Oleg Committed by Dave Methvin

Fix #13356. Clean up after load/ready handlers. Close gh-1152.

parent 8226666b
...@@ -74,17 +74,25 @@ var ...@@ -74,17 +74,25 @@ var
return letter.toUpperCase(); return letter.toUpperCase();
}, },
// The ready event handler and self cleanup method // The ready event handler
DOMContentLoaded = function() { completed = function( event ) {
if ( document.addEventListener ) {
document.removeEventListener( "DOMContentLoaded", DOMContentLoaded, false ); // readyState === "complete" is good enough for us to call the dom ready in oldIE
jQuery.ready(); if ( document.addEventListener || event.type === "load" || document.readyState === "complete" ) {
} else if ( document.readyState === "complete" ) { detach();
// we're here because readyState === "complete" in oldIE
// which is good enough for us to call the dom ready!
document.detachEvent( "onreadystatechange", DOMContentLoaded );
jQuery.ready(); jQuery.ready();
} }
},
// Clean-up method for dom ready events
detach = function() {
if ( document.addEventListener ) {
document.removeEventListener( "DOMContentLoaded", completed, false );
window.removeEventListener( "load", completed, false );
} else {
document.detachEvent( "onreadystatechange", completed );
window.detachEvent( "onload", completed );
}
}; };
jQuery.fn = jQuery.prototype = { jQuery.fn = jQuery.prototype = {
...@@ -869,18 +877,18 @@ jQuery.ready.promise = function( obj ) { ...@@ -869,18 +877,18 @@ jQuery.ready.promise = function( obj ) {
// Standards-based browsers support DOMContentLoaded // Standards-based browsers support DOMContentLoaded
} else if ( document.addEventListener ) { } else if ( document.addEventListener ) {
// Use the handy event callback // Use the handy event callback
document.addEventListener( "DOMContentLoaded", DOMContentLoaded, false ); document.addEventListener( "DOMContentLoaded", completed, false );
// A fallback to window.onload, that will always work // A fallback to window.onload, that will always work
window.addEventListener( "load", jQuery.ready, false ); window.addEventListener( "load", completed, false );
// If IE event model is used // If IE event model is used
} else { } else {
// Ensure firing before onload, maybe late but safe also for iframes // Ensure firing before onload, maybe late but safe also for iframes
document.attachEvent( "onreadystatechange", DOMContentLoaded ); document.attachEvent( "onreadystatechange", completed );
// A fallback to window.onload, that will always work // A fallback to window.onload, that will always work
window.attachEvent( "onload", jQuery.ready ); window.attachEvent( "onload", completed );
// If IE and not a frame // If IE and not a frame
// continually check to see if the document is ready // continually check to see if the document is ready
...@@ -902,6 +910,9 @@ jQuery.ready.promise = function( obj ) { ...@@ -902,6 +910,9 @@ jQuery.ready.promise = function( obj ) {
return setTimeout( doScrollCheck, 50 ); return setTimeout( doScrollCheck, 50 );
} }
// detach all dom ready events
detach();
// and execute any waiting functions // and execute any waiting functions
jQuery.ready(); jQuery.ready();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment