]> source.dussan.org Git - jquery.git/commitdiff
Core: use interactive to evaluate dom ready, barring IE6-10
authorTimmy Willison <timmywillisn@gmail.com>
Wed, 28 Oct 2015 17:54:04 +0000 (13:54 -0400)
committerTimmy Willison <timmywillisn@gmail.com>
Thu, 14 Jan 2016 15:18:31 +0000 (10:18 -0500)
Fixes gh-2100
Close gh-2821

src/core/ready.js
test/data/event/interactiveReady.html [new file with mode: 0644]
test/unit/event.js

index 49c1da20292259e80cb5f08b18f2704c46876442..da7a0a2922f1856e46c91b4e8f27ee0f1d90e1ad 100644 (file)
@@ -97,11 +97,10 @@ jQuery.ready.promise = function( obj ) {
 
                // Catch cases where $(document).ready() is called
                // after the browser event has already occurred.
-               // we once tried to use readyState "interactive" here,
-               // but it caused issues like the one
-               // discovered by ChrisS here:
-               // http://bugs.jquery.com/ticket/12282#comment:15
-               if ( document.readyState === "complete" ) {
+               // Support: IE6-10
+               // Older IE sometimes signals "interactive" too soon
+               if ( document.readyState === "complete" ||
+                       ( document.readyState !== "loading" && !document.documentElement.doScroll ) ) {
 
                        // Handle it asynchronously to allow scripts the opportunity to delay ready
                        window.setTimeout( jQuery.ready );
diff --git a/test/data/event/interactiveReady.html b/test/data/event/interactiveReady.html
new file mode 100644 (file)
index 0000000..77b3710
--- /dev/null
@@ -0,0 +1,23 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+<meta http-equiv="content-type" content="text/html; charset=utf-8">
+<title>Test case for gh-2100</title>
+<script src="../../jquery.js"></script>
+</head>
+<body>
+
+<script type="text/javascript">
+jQuery( document ).ready(function () {
+       window.parent.iframeCallback( jQuery("#container").length === 1 );
+});
+</script>
+
+<!-- external resources that come before elements trick
+       oldIE into thinking the dom is ready, but it's not...
+       leaving this check here for future trailblazers to attempt
+       fixing this...-->
+<script type="text/javascript" src="../longLoadScript.php?sleep=1"></script>
+<div id="container" style="height: 300px"></div>
+</body>
+</html>
index c8c0667d34339750854cbd95ad5f00352f8f08c3..14fcba0b3f65d92d7a7940507755bdf5ca954745 100644 (file)
@@ -2589,6 +2589,18 @@ testIframeWithCallback(
        }
 );
 
+// need PHP here to make the incepted IFRAME hang
+if ( hasPHP ) {
+       testIframeWithCallback(
+               "jQuery.ready uses interactive",
+               "event/interactiveReady.html",
+               function( isOk, assert ) {
+                       assert.expect( 1 );
+                       assert.ok( isOk, "jQuery fires ready when the DOM can truly be interacted with" );
+               }
+       );
+}
+
 testIframeWithCallback(
        "Focusing iframe element",
        "event/focusElem.html",