From f5fd41252e3ae48a655c5da4a0b2910bb897b6ed Mon Sep 17 00:00:00 2001 From: Mike Sherov Date: Fri, 6 Jul 2012 10:12:20 -0400 Subject: [PATCH] Fix #12018, readyState "interactive" in oldIE lies! Closes gh-848. --- src/core.js | 9 ++++--- test/data/event/asyncReady.html | 35 +++++++++++++------------- test/data/event/longLoadScript.php | 4 +++ test/data/event/promiseReady.html | 2 +- test/data/event/syncReady.html | 13 +++++++--- test/data/event/syncReadyLongLoad.html | 26 +++++++++++++++++++ test/unit/event.js | 22 ++++++++++------ 7 files changed, 77 insertions(+), 34 deletions(-) create mode 100644 test/data/event/longLoadScript.php create mode 100644 test/data/event/syncReadyLongLoad.html diff --git a/src/core.js b/src/core.js index c92774075..6b0615009 100644 --- a/src/core.js +++ b/src/core.js @@ -63,12 +63,13 @@ var DOMContentLoaded = function() { if ( document.addEventListener ) { document.removeEventListener( "DOMContentLoaded", DOMContentLoaded, false ); - } else { - // we're here because readyState !== "loading" in oldIE + jQuery.ready(); + } else if ( document.readyState === "complete" ) { + // 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(); }, // [[Class]] -> type pairs @@ -818,7 +819,7 @@ jQuery.ready.promise = function( obj ) { // Catch cases where $(document).ready() is called after the // browser event has already occurred. - if ( document.readyState !== "loading" ) { + if ( document.readyState === "complete" || ( document.readyState !== "loading" && document.addEventListener ) ) { // Handle it asynchronously to allow scripts the opportunity to delay ready setTimeout( jQuery.ready, 1 ); diff --git a/test/data/event/asyncReady.html b/test/data/event/asyncReady.html index 174c0f780..48a967a2a 100644 --- a/test/data/event/asyncReady.html +++ b/test/data/event/asyncReady.html @@ -4,27 +4,26 @@ Test case for jQuery ticket #10067 + + + +
+ diff --git a/test/data/event/longLoadScript.php b/test/data/event/longLoadScript.php new file mode 100644 index 000000000..ba47168b4 --- /dev/null +++ b/test/data/event/longLoadScript.php @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/test/data/event/promiseReady.html b/test/data/event/promiseReady.html index f8567cc91..3ea11f05e 100644 --- a/test/data/event/promiseReady.html +++ b/test/data/event/promiseReady.html @@ -12,6 +12,6 @@ jQuery.when( jQuery.ready ).done(function() { - + diff --git a/test/data/event/syncReady.html b/test/data/event/syncReady.html index c542c987a..126e2d57f 100644 --- a/test/data/event/syncReady.html +++ b/test/data/event/syncReady.html @@ -6,13 +6,18 @@ + - - + + + +
diff --git a/test/data/event/syncReadyLongLoad.html b/test/data/event/syncReadyLongLoad.html new file mode 100644 index 000000000..83f2859ed --- /dev/null +++ b/test/data/event/syncReadyLongLoad.html @@ -0,0 +1,26 @@ + + + + +Test case for jQuery ticket #10067 + + + + + + + + +
+ + + + + diff --git a/test/unit/event.js b/test/unit/event.js index 2261e6f79..6d3603672 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -2345,7 +2345,7 @@ test("jQuery.off using dispatched jQuery.Event", function() { test( "delegated event with delegateTarget-relative selector (#)", function() { expect(1); var markup = jQuery( '