From dbf4926e31390ceda57730c68d40f34536803114 Mon Sep 17 00:00:00 2001 From: Oleg Date: Tue, 15 Jan 2013 18:45:21 +0400 Subject: [PATCH] Consistently clean up after .ready() handler, close gh-1135. --- src/core.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/core.js b/src/core.js index 202188debc..d909c8144d 100644 --- a/src/core.js +++ b/src/core.js @@ -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 );