From 54fab3174c7844959b374e98b453c048b60de0d0 Mon Sep 17 00:00:00 2001 From: Mike Sherov Date: Mon, 23 Apr 2012 15:43:26 -0400 Subject: [PATCH] Fix #10067. Create jQuery.quickReady; closes gh-736. Allows us to get to the ready state sooner by not waiting for iframes to load. If that causes backcompat pain, use `jQuery.quickReady = false` as prescribed by your developer. --- src/core.js | 16 ++++++++--- test/data/event/asyncQuickReadyFalse.html | 32 ++++++++++++++++++++++ test/data/event/asyncQuickReadyTrue.html | 30 +++++++++++++++++++++ test/data/event/longLoad.php | 6 +++++ test/data/event/syncReady.html | 17 ++++++++++++ test/data/support/bodyBackground.html | 2 +- test/data/support/boxModelIE.html | 2 +- test/data/support/hiddenIFrameFF.html | 7 ----- test/data/support/testElementCrash.html | 7 ++--- test/data/testinit.js | 25 ++++++++++++++++- test/unit/event.js | 20 ++++++++++++++ test/unit/support.js | 33 +++-------------------- 12 files changed, 149 insertions(+), 48 deletions(-) create mode 100644 test/data/event/asyncQuickReadyFalse.html create mode 100644 test/data/event/asyncQuickReadyTrue.html create mode 100644 test/data/event/longLoad.php create mode 100644 test/data/event/syncReady.html delete mode 100644 test/data/support/hiddenIFrameFF.html diff --git a/src/core.js b/src/core.js index f317666ce..22f186336 100644 --- a/src/core.js +++ b/src/core.js @@ -375,6 +375,9 @@ 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 ) { @@ -386,6 +389,12 @@ 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) ) { // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443). @@ -420,9 +429,9 @@ jQuery.extend({ // Catch cases where $(document).ready() is called after the // browser event has already occurred. - if ( document.readyState === "complete" ) { + if ( document.readyState !== "loading" ) { // Handle it asynchronously to allow scripts the opportunity to delay ready - return setTimeout( jQuery.ready, 1 ); + setTimeout( jQuery.ready, 1 ); } // Mozilla, Opera and webkit nightlies currently support this event @@ -915,6 +924,7 @@ 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(); }; @@ -922,7 +932,7 @@ if ( document.addEventListener ) { } 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" ) { + if ( document.readyState === "complete" || ( jQuery.quickReady && document.readyState === "interactive" ) ) { document.detachEvent( "onreadystatechange", DOMContentLoaded ); jQuery.ready(); } diff --git a/test/data/event/asyncQuickReadyFalse.html b/test/data/event/asyncQuickReadyFalse.html new file mode 100644 index 000000000..935269749 --- /dev/null +++ b/test/data/event/asyncQuickReadyFalse.html @@ -0,0 +1,32 @@ + + + + +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 new file mode 100644 index 000000000..cdcb82128 --- /dev/null +++ b/test/data/event/asyncQuickReadyTrue.html @@ -0,0 +1,30 @@ + + + + +Test case for jQuery ticket #10067 + + + + + + + \ No newline at end of file diff --git a/test/data/event/longLoad.php b/test/data/event/longLoad.php new file mode 100644 index 000000000..ba1d43f82 --- /dev/null +++ b/test/data/event/longLoad.php @@ -0,0 +1,6 @@ + + \ No newline at end of file diff --git a/test/data/event/syncReady.html b/test/data/event/syncReady.html new file mode 100644 index 000000000..b9dbb2280 --- /dev/null +++ b/test/data/event/syncReady.html @@ -0,0 +1,17 @@ + + + + +Test case for jQuery ticket #10067 + + + + + + + + \ No newline at end of file diff --git a/test/data/support/bodyBackground.html b/test/data/support/bodyBackground.html index 0f12e75f9..4f0105a1d 100644 --- a/test/data/support/bodyBackground.html +++ b/test/data/support/bodyBackground.html @@ -21,7 +21,7 @@ diff --git a/test/data/support/boxModelIE.html b/test/data/support/boxModelIE.html index ca647a281..24e4c6100 100644 --- a/test/data/support/boxModelIE.html +++ b/test/data/support/boxModelIE.html @@ -3,7 +3,7 @@ diff --git a/test/data/support/hiddenIFrameFF.html b/test/data/support/hiddenIFrameFF.html deleted file mode 100644 index c2dda8cd4..000000000 --- a/test/data/support/hiddenIFrameFF.html +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/test/data/support/testElementCrash.html b/test/data/support/testElementCrash.html index 583ca7b0f..6ef9651da 100644 --- a/test/data/support/testElementCrash.html +++ b/test/data/support/testElementCrash.html @@ -7,14 +7,11 @@ background: url('http://s1.postimage.org/2d2r8xih0/body_background.png'); } - - - - + diff --git a/test/data/testinit.js b/test/data/testinit.js index 1f775c1d7..9a27f5287 100644 --- a/test/data/testinit.js +++ b/test/data/testinit.js @@ -192,7 +192,7 @@ function url(value) { }); function loadFixture() { - var src = "./data/" + fileName + ".html?" + parseInt( Math.random()*1000, 10 ), + var src = url("./data/" + fileName + ".html"), iframe = jQuery("