Skip to content

Commit 8c293e6

Browse files
committed
Core: use interactive to evaluate dom ready, barring IE6-10
Fixes jquerygh-2100 Close jquerygh-2821
1 parent d19aa97 commit 8c293e6

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

src/core/ready.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,10 @@ jQuery.ready.promise = function( obj ) {
9797

9898
// Catch cases where $(document).ready() is called
9999
// after the browser event has already occurred.
100-
// we once tried to use readyState "interactive" here,
101-
// but it caused issues like the one
102-
// discovered by ChrisS here:
103-
// http://bugs.jquery.com/ticket/12282#comment:15
104-
if ( document.readyState === "complete" ) {
100+
// Support: IE6-10
101+
// Older IE sometimes signals "interactive" too soon
102+
if ( document.readyState === "complete" ||
103+
( document.readyState !== "loading" && !document.documentElement.doScroll ) ) {
105104

106105
// Handle it asynchronously to allow scripts the opportunity to delay ready
107106
window.setTimeout( jQuery.ready );
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2+
<html>
3+
<head>
4+
<meta http-equiv="content-type" content="text/html; charset=utf-8">
5+
<title>Test case for gh-2100</title>
6+
<script src="../../jquery.js"></script>
7+
</head>
8+
<body>
9+
10+
<script type="text/javascript">
11+
jQuery( document ).ready(function () {
12+
window.parent.iframeCallback( jQuery("#container").length === 1 );
13+
});
14+
</script>
15+
16+
<!-- external resources that come before elements trick
17+
oldIE into thinking the dom is ready, but it's not...
18+
leaving this check here for future trailblazers to attempt
19+
fixing this...-->
20+
<script type="text/javascript" src="../longLoadScript.php?sleep=1"></script>
21+
<div id="container" style="height: 300px"></div>
22+
</body>
23+
</html>

test/unit/event.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2589,6 +2589,18 @@ testIframeWithCallback(
25892589
}
25902590
);
25912591

2592+
// need PHP here to make the incepted IFRAME hang
2593+
if ( hasPHP ) {
2594+
testIframeWithCallback(
2595+
"jQuery.ready uses interactive",
2596+
"event/interactiveReady.html",
2597+
function( isOk, assert ) {
2598+
assert.expect( 1 );
2599+
assert.ok( isOk, "jQuery fires ready when the DOM can truly be interacted with" );
2600+
}
2601+
);
2602+
}
2603+
25922604
testIframeWithCallback(
25932605
"Focusing iframe element",
25942606
"event/focusElem.html",

0 commit comments

Comments
 (0)