mirror of
https://github.com/jquery/jquery.git
synced 2025-01-10 18:24:24 +00:00
Fix #12018, readyState "interactive" in oldIE lies! Closes gh-848.
This commit is contained in:
parent
aaf134bb70
commit
f5fd41252e
@ -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();
|
||||
}
|
||||
},
|
||||
|
||||
// [[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 );
|
||||
|
||||
|
@ -4,27 +4,26 @@
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||
<title>Test case for jQuery ticket #10067</title>
|
||||
<script type="text/javascript">
|
||||
if ( document.attachEvent ) {
|
||||
// browsers that use the non-standard event API will load the iframe
|
||||
// before jQuery, so there's no way to fire ready before the iframe loads
|
||||
window.parent.iframeCallback( true );
|
||||
} else {
|
||||
setTimeout(function() {
|
||||
setTimeout(function() {
|
||||
el = document.createElement("script");
|
||||
el.type = "text/javascript";
|
||||
el.onload = function() {
|
||||
jQuery( document ).ready(function() {
|
||||
jQuery("body").append("<div>modifying DOM</div>");
|
||||
window.parent.iframeCallback( true );
|
||||
window.parent.iframeCallback( jQuery('#container').length === 1 );
|
||||
});
|
||||
}
|
||||
document.getElementsByTagName("head")[ 0 ].appendChild( el );
|
||||
el.src = "../../../dist/jquery.js";
|
||||
}, 1000 );
|
||||
}
|
||||
}, 1000 );
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<!-- external resources that come before elements trick
|
||||
oldIE into thinking the dom is ready, but it's not... -->
|
||||
<script type="text/javascript" src="longLoadScript.php?sleep=1"></script>
|
||||
<div id="container" style="height: 300px"></div>
|
||||
|
||||
<!-- long loading iframe -->
|
||||
<iframe src="longLoad.php?sleep=15&return=false" style="width: 1px; height: 1px"></iframe>
|
||||
</body>
|
||||
|
4
test/data/event/longLoadScript.php
Normal file
4
test/data/event/longLoadScript.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
sleep((int)$_GET['sleep']);
|
||||
header('Content-type: text/javascript');
|
||||
?>
|
@ -12,6 +12,6 @@ jQuery.when( jQuery.ready ).done(function() {
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<!-- long loading iframe -->
|
||||
<!-- empty body -->
|
||||
</body>
|
||||
</html>
|
||||
|
@ -6,13 +6,18 @@
|
||||
<script type="text/javascript" src="../../../dist/jquery.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<script type="text/javascript">
|
||||
jQuery( document ).ready(function () {
|
||||
jQuery("body").append("<div>modifying DOM</div>");
|
||||
window.parent.iframeCallback( true );
|
||||
window.parent.iframeCallback( jQuery('#container').length === 1 );
|
||||
});
|
||||
</script>
|
||||
<!-- long loading iframe -->
|
||||
<iframe src="longLoad.php?sleep=10&return=false" style="width: 1px; height: 1px"></iframe>
|
||||
|
||||
<!-- 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>
|
||||
|
26
test/data/event/syncReadyLongLoad.html
Normal file
26
test/data/event/syncReadyLongLoad.html
Normal file
@ -0,0 +1,26 @@
|
||||
<!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 jQuery ticket #10067</title>
|
||||
<script type="text/javascript" src="../../../dist/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>
|
||||
|
||||
<!-- long loading iframe -->
|
||||
<iframe src="longLoad.php?sleep=10&return=false" style="width: 1px; height: 1px"></iframe>
|
||||
</body>
|
||||
</html>
|
@ -2884,7 +2884,9 @@ if ( hasPHP ) {
|
||||
ok( isOk, "$.when( $.ready ) works" );
|
||||
});
|
||||
|
||||
testIframeWithCallback( "jQuery.ready synchronous load with long loading iframe", "event/syncReady", function( isOk ) {
|
||||
// oldIE needs all subresources to be loaded before it can gaurantee the document is truly ready to be interacted with
|
||||
if( document.addEventListener ) {
|
||||
testIframeWithCallback( "jQuery.ready synchronous load with long loading iframe", "event/syncReadyLongLoad", function( isOk ) {
|
||||
expect(1);
|
||||
ok( isOk, "jQuery loaded synchronously fires ready before all sub-resources are loaded" );
|
||||
});
|
||||
@ -2893,6 +2895,12 @@ if ( hasPHP ) {
|
||||
expect(1);
|
||||
ok( isOk, "jQuery loaded asynchronously fires ready before all sub-resources are loaded" );
|
||||
});
|
||||
}
|
||||
|
||||
testIframeWithCallback( "jQuery.ready synchronous load with long loading subresources", "event/syncReady", function( isOk ) {
|
||||
expect(1);
|
||||
ok( isOk, "jQuery loaded synchronously fires ready when the DOM can truly be interacted with" );
|
||||
});
|
||||
}
|
||||
|
||||
(function(){
|
||||
|
Loading…
Reference in New Issue
Block a user