From f925c7a1c93afd7eae1edcf540e9d4374b2aa27b Mon Sep 17 00:00:00 2001 From: Mike Sherov Date: Fri, 4 May 2012 09:57:32 -0400 Subject: [PATCH] remove jQuery.quickReady, save bytes, style nits in tests --- src/core.js | 41 +++++++---------------- test/data/event/asyncQuickReadyFalse.html | 32 ------------------ test/data/event/asyncQuickReadyTrue.html | 30 ----------------- test/data/event/asyncReady.html | 30 +++++++++++++++++ test/data/event/syncReady.html | 4 +-- test/unit/event.js | 13 +++---- 6 files changed, 50 insertions(+), 100 deletions(-) delete mode 100644 test/data/event/asyncQuickReadyFalse.html delete mode 100644 test/data/event/asyncQuickReadyTrue.html create mode 100644 test/data/event/asyncReady.html diff --git a/src/core.js b/src/core.js index 22f186336..b5b8efcd7 100644 --- a/src/core.js +++ b/src/core.js @@ -60,7 +60,18 @@ var jQuery = function( selector, context ) { readyList, // The ready event handler - DOMContentLoaded, + // Cleanup function for the document ready method + DOMContentLoaded = function() { + if ( document.addEventListener ) { + document.removeEventListener( "DOMContentLoaded", DOMContentLoaded, false ); + jQuery.ready(); + } else if ( document.readyState !== "loading" ) { + // if document.addEventListener isn't present, we assume detachEvent is! + // Make sure body exists by checking readystate, at least, in case IE gets a little overzealous (ticket #5443). + document.detachEvent( "onreadystatechange", DOMContentLoaded ); + jQuery.ready(); + } + }, // Save a reference to some core methods toString = Object.prototype.toString, @@ -375,9 +386,6 @@ jQuery.extend({ // the ready event fires. See #6781 readyWait: 1, - // should we fire ready on readyState "interactive" ? - quickReady: true, - // Hold (or release) the ready event holdReady: function( hold ) { if ( hold ) { @@ -389,11 +397,6 @@ jQuery.extend({ // Handle when the DOM is ready ready: function( wait ) { - // user wasn't necessarily given the chance to set jQuery.quickReady before bindReady - // so we check here for quickReady instead - if ( !jQuery.quickReady && document.readyState === "interactive" ) { - return; - } // Either a released hold or an DOMready/load event and not yet ready if ( (wait === true && !--jQuery.readyWait) || (wait !== true && !jQuery.isReady) ) { @@ -431,7 +434,7 @@ jQuery.extend({ // browser event has already occurred. if ( document.readyState !== "loading" ) { // Handle it asynchronously to allow scripts the opportunity to delay ready - setTimeout( jQuery.ready, 1 ); + return setTimeout( jQuery.ready, 1 ); } // Mozilla, Opera and webkit nightlies currently support this event @@ -921,24 +924,6 @@ if ( rnotwhite.test( "\xA0" ) ) { // All jQuery objects should point back to these rootjQuery = jQuery(document); -// Cleanup functions for the document ready method -if ( document.addEventListener ) { - DOMContentLoaded = function() { - jQuery.quickReady = true; - document.removeEventListener( "DOMContentLoaded", DOMContentLoaded, false ); - jQuery.ready(); - }; - -} else if ( document.attachEvent ) { - DOMContentLoaded = function() { - // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443). - if ( document.readyState === "complete" || ( jQuery.quickReady && document.readyState === "interactive" ) ) { - document.detachEvent( "onreadystatechange", DOMContentLoaded ); - jQuery.ready(); - } - }; -} - // The DOM ready check for Internet Explorer function doScrollCheck() { if ( jQuery.isReady ) { diff --git a/test/data/event/asyncQuickReadyFalse.html b/test/data/event/asyncQuickReadyFalse.html deleted file mode 100644 index 935269749..000000000 --- a/test/data/event/asyncQuickReadyFalse.html +++ /dev/null @@ -1,32 +0,0 @@ - - - - -Test case for jQuery ticket #10067 - - - - - - - \ No newline at end of file diff --git a/test/data/event/asyncQuickReadyTrue.html b/test/data/event/asyncQuickReadyTrue.html deleted file mode 100644 index cdcb82128..000000000 --- a/test/data/event/asyncQuickReadyTrue.html +++ /dev/null @@ -1,30 +0,0 @@ - - - - -Test case for jQuery ticket #10067 - - - - - - - \ No newline at end of file diff --git a/test/data/event/asyncReady.html b/test/data/event/asyncReady.html new file mode 100644 index 000000000..e32ff9cfb --- /dev/null +++ b/test/data/event/asyncReady.html @@ -0,0 +1,30 @@ + + + + +Test case for jQuery ticket #10067 + + + + + + + \ No newline at end of file diff --git a/test/data/event/syncReady.html b/test/data/event/syncReady.html index b9dbb2280..df66bc623 100644 --- a/test/data/event/syncReady.html +++ b/test/data/event/syncReady.html @@ -7,8 +7,8 @@ diff --git a/test/unit/event.js b/test/unit/event.js index 545cc05bc..5d96ec1b7 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -2794,23 +2794,20 @@ test("fixHooks extensions", function() { jQuery.event.fixHooks.click = saved; }); -testIframeWithCallback( "jQuery.ready sync load", "event/syncReady", function( isOk ) { - expect(1); - ok( isOk, "jQuery loaded synchronously fires ready before all sub-resources are loaded" ); -}); // async loaded tests expect jQuery to be loaded as a single file // if we're not doing PHP concat, then we fall back to document.write // which breaks order of execution on async loaded files +// also need PHP to make the incepted IFRAME hang if ( hasPHP ) { - testIframeWithCallback( "jQuery.ready async load with quickReady true", "event/asyncQuickReadyTrue", function( isOk ) { + testIframeWithCallback( "jQuery.ready synchronous load with long loading iframe", "event/syncReady", function( isOk ) { expect(1); - ok( isOk, "jQuery loaded asynchronously with quickReady true fires ready before all sub-resources are loaded" ); + ok( isOk, "jQuery loaded synchronously fires ready before all sub-resources are loaded" ); }); - testIframeWithCallback( "jQuery.ready async load with quickReady false", "event/asyncQuickReadyFalse", function( isOk ) { + testIframeWithCallback( "jQuery.ready asynchronous load with long loading iframe", "event/asyncReady", function( isOk ) { expect(1); - ok( isOk, "jQuery loaded asynchronously with quickReady false fires ready after all sub-resources are loaded" ); + ok( isOk, "jQuery loaded asynchronously fires ready before all sub-resources are loaded" ); }); }