Skip to content

Core: use interactive to evaluate dom ready #2678

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/core/ready.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,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: IE9-10 only
// 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 );
Expand Down
23 changes: 23 additions & 0 deletions test/data/event/interactiveReady.html
Original file line number Diff line number Diff line change
@@ -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>
12 changes: 12 additions & 0 deletions test/unit/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -2518,6 +2518,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",
Expand Down