Skip to content
Browse files
Create jQuery.holdReady(true/false) method to encapsulate…
…yWait++ / jQuery.ready(true) logic. Fix problem where jQuery.ready may trigger twice, causing the (unsupported) document.onready to run twice. Fixes #8803 .
  • Loading branch information
dmethvin committed Apr 7, 2011
1 parent bbd9c77 commit 14193e449efe76105df61d745ebd7031dd7fe783
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
@@ -374,15 +374,19 @@ jQuery.extend({
// the ready event fires. See #6781
readyWait: 1,

// Handle when the DOM is ready
ready: function( wait ) {
// A third-party is pushing the ready event forwards
if ( wait === true ) {
// Hold (or release) the ready event
holdReady: function( hold ) {
if ( hold ) {
} else {
jQuery.ready( true );

// Make sure that the DOM is not already loaded
if ( !jQuery.readyWait || (wait !== true && !jQuery.isReady) ) {
// Handle when the DOM is ready
ready: function( wait ) {
// Either a released hold or an DOMready/load event and not yet ready
if ( (wait === true && !--jQuery.readyWait) || (wait !== true && !jQuery.isReady) ) {
// Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
if ( !document.body ) {
return setTimeout( jQuery.ready, 1 );
@@ -1,14 +1,14 @@
// Simple script loader that uses jQuery.readyWait
// Simple script loader that uses jQuery.readyWait via jQuery.holdReady()

//Hold on jQuery!

var readyRegExp = /^(complete|loaded)$/;

function assetLoaded( evt ){
var node = evt.currentTarget || evt.srcElement;
if ( evt.type === "load" || readyRegExp.test(node.readyState) ) {

@@ -1,13 +1,13 @@
<!DOCTYPE html>
Test for jQuery.readyWait. Needs to be a
Test for jQuery.holdReady. Needs to be a
standalone test since it deals with DOM
jQuery.readyWait Test
jQuery.holdReady Test
div { margin-top: 10px; }
@@ -52,23 +52,25 @@
jQuery.readyWait Test
jQuery.holdReady Test
This is a test page for jQuery.readyWait, that was
added due to this ticket
<a href="">#6781</a>.
This is a test page for jQuery.readyWait and jQuery.holdReady,
<a href="">#6781</a>
<a href="">#8803</a>.
Test for jQuery.readyWait, which can be used
Test for jQuery.holdReady, which can be used
by plugins and other scripts to indicate something
important to the page is still loading and needs
to block the DOM ready callbacks that are registered
with jQuery.
Script loaders are the most likely kind of script
to use jQuery.readyWait, but it could be used by
to use jQuery.holdReady, but it could be used by
other things like a script that loads a CSS file
and wants to pause the DOM ready callbacks.

0 comments on commit 14193e4

Please sign in to comment.