Skip to content

Commit dabd5ba

Browse files
committed
Core: use interactive to evaluate dom ready, barring IE9-10
Fixes gh-2100
1 parent 87bd130 commit dabd5ba

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

src/core/ready.js

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

7171
// Catch cases where $(document).ready() is called
7272
// after the browser event has already occurred.
73-
// We once tried to use readyState "interactive" here,
74-
// but it caused issues like the one
75-
// discovered by ChrisS here: http://bugs.jquery.com/ticket/12282#comment:15
76-
if ( document.readyState === "complete" ) {
73+
// Support: IE9-10 only
74+
// Older IE sometimes signals "interactive" too soon
75+
if ( document.readyState === "complete" ||
76+
( document.readyState !== "loading" && !document.documentElement.doScroll ) ) {
7777

7878
// Handle it asynchronously to allow scripts the opportunity to delay ready
7979
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
@@ -2518,6 +2518,18 @@ testIframeWithCallback(
25182518
}
25192519
);
25202520

2521+
// need PHP here to make the incepted IFRAME hang
2522+
if ( hasPHP ) {
2523+
testIframeWithCallback(
2524+
"jQuery.ready uses interactive",
2525+
"event/interactiveReady.html",
2526+
function( isOk, assert ) {
2527+
assert.expect( 1 );
2528+
assert.ok( isOk, "jQuery fires ready when the DOM can truly be interacted with" );
2529+
}
2530+
);
2531+
}
2532+
25212533
testIframeWithCallback(
25222534
"Focusing iframe element",
25232535
"event/focusElem.html",

0 commit comments

Comments
 (0)