Skip to content

Commit

Permalink
remove jQuery.quickReady, save bytes, style nits in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mikesherov committed May 4, 2012
1 parent bab6f53 commit f925c7a
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 100 deletions.
41 changes: 13 additions & 28 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,18 @@ var jQuery = function( selector, context ) {
readyList,

// The ready event handler
DOMContentLoaded,
// Cleanup function for the document ready method
DOMContentLoaded = function() {
if ( document.addEventListener ) {
document.removeEventListener( "DOMContentLoaded", DOMContentLoaded, false );
jQuery.ready();
} else if ( document.readyState !== "loading" ) {
// if document.addEventListener isn't present, we assume detachEvent is!
// Make sure body exists by checking readystate, at least, in case IE gets a little overzealous (ticket #5443).
document.detachEvent( "onreadystatechange", DOMContentLoaded );
jQuery.ready();
}
},

// Save a reference to some core methods
toString = Object.prototype.toString,
Expand Down Expand Up @@ -375,9 +386,6 @@ jQuery.extend({
// the ready event fires. See #6781
readyWait: 1,

// should we fire ready on readyState "interactive" ?
quickReady: true,

// Hold (or release) the ready event
holdReady: function( hold ) {
if ( hold ) {
Expand All @@ -389,11 +397,6 @@ jQuery.extend({

// Handle when the DOM is ready
ready: function( wait ) {
// user wasn't necessarily given the chance to set jQuery.quickReady before bindReady
// so we check here for quickReady instead
if ( !jQuery.quickReady && document.readyState === "interactive" ) {
return;
}

// Either a released hold or an DOMready/load event and not yet ready
if ( (wait === true && !--jQuery.readyWait) || (wait !== true && !jQuery.isReady) ) {
Expand Down Expand Up @@ -431,7 +434,7 @@ jQuery.extend({
// browser event has already occurred.
if ( document.readyState !== "loading" ) {
// Handle it asynchronously to allow scripts the opportunity to delay ready
setTimeout( jQuery.ready, 1 );
return setTimeout( jQuery.ready, 1 );
}

// Mozilla, Opera and webkit nightlies currently support this event
Expand Down Expand Up @@ -921,24 +924,6 @@ if ( rnotwhite.test( "\xA0" ) ) {
// All jQuery objects should point back to these
rootjQuery = jQuery(document);

// Cleanup functions for the document ready method
if ( document.addEventListener ) {
DOMContentLoaded = function() {
jQuery.quickReady = true;
document.removeEventListener( "DOMContentLoaded", DOMContentLoaded, false );
jQuery.ready();
};

} else if ( document.attachEvent ) {
DOMContentLoaded = function() {
// Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
if ( document.readyState === "complete" || ( jQuery.quickReady && document.readyState === "interactive" ) ) {
document.detachEvent( "onreadystatechange", DOMContentLoaded );
jQuery.ready();
}
};
}

// The DOM ready check for Internet Explorer
function doScrollCheck() {
if ( jQuery.isReady ) {
Expand Down
32 changes: 0 additions & 32 deletions test/data/event/asyncQuickReadyFalse.html

This file was deleted.

30 changes: 0 additions & 30 deletions test/data/event/asyncQuickReadyTrue.html

This file was deleted.

30 changes: 30 additions & 0 deletions test/data/event/asyncReady.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!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">
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() {
el = document.createElement("script");
el.type = "text/javascript";
el.onload = function() {
jQuery( document ).ready(function() {
window.parent.iframeCallback( true );
});
}
document.getElementsByTagName("head")[ 0 ].appendChild( el );
el.src = "../include_js.php";
}, 1000 );
}
</script>
</head>
<body>
<!-- long loading iframe -->
<iframe src="longLoad.php?sleep=15&return=false" style="width: 1px; height: 1px"></iframe>
</body>
</html>
4 changes: 2 additions & 2 deletions test/data/event/syncReady.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</head>
<body>
<script type="text/javascript">
jQuery(document).ready(function () {
window.parent.iframeCallback(true);
jQuery( document ).ready(function () {
window.parent.iframeCallback( true );
});
</script>
<!-- long loading iframe -->
Expand Down
13 changes: 5 additions & 8 deletions test/unit/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -2794,23 +2794,20 @@ test("fixHooks extensions", function() {
jQuery.event.fixHooks.click = saved;
});

testIframeWithCallback( "jQuery.ready sync load", "event/syncReady", function( isOk ) {
expect(1);
ok( isOk, "jQuery loaded synchronously fires ready before all sub-resources are loaded" );
});

// async loaded tests expect jQuery to be loaded as a single file
// if we're not doing PHP concat, then we fall back to document.write
// which breaks order of execution on async loaded files
// also need PHP to make the incepted IFRAME hang
if ( hasPHP ) {
testIframeWithCallback( "jQuery.ready async load with quickReady true", "event/asyncQuickReadyTrue", function( isOk ) {
testIframeWithCallback( "jQuery.ready synchronous load with long loading iframe", "event/syncReady", function( isOk ) {
expect(1);
ok( isOk, "jQuery loaded asynchronously with quickReady true fires ready before all sub-resources are loaded" );
ok( isOk, "jQuery loaded synchronously fires ready before all sub-resources are loaded" );
});

testIframeWithCallback( "jQuery.ready async load with quickReady false", "event/asyncQuickReadyFalse", function( isOk ) {
testIframeWithCallback( "jQuery.ready asynchronous load with long loading iframe", "event/asyncReady", function( isOk ) {
expect(1);
ok( isOk, "jQuery loaded asynchronously with quickReady false fires ready after all sub-resources are loaded" );
ok( isOk, "jQuery loaded asynchronously fires ready before all sub-resources are loaded" );
});
}

Expand Down

0 comments on commit f925c7a

Please sign in to comment.