aboutsummaryrefslogtreecommitdiffstats
path: root/src/core.js
diff options
context:
space:
mode:
authorDave Methvin <dave.methvin@gmail.com>2011-02-02 21:57:44 -0500
committerDave Methvin <dave.methvin@gmail.com>2011-04-07 11:26:42 -0400
commit14193e449efe76105df61d745ebd7031dd7fe783 (patch)
tree7e815de898328446c0e2c1bcf99840d36de1da9e /src/core.js
parentbbd9c776ea22296a6807d5b760bd4e82ee5f4414 (diff)
downloadjquery-14193e449efe76105df61d745ebd7031dd7fe783.tar.gz
jquery-14193e449efe76105df61d745ebd7031dd7fe783.zip
Create jQuery.holdReady(true/false) method to encapsulate jQuery.readyWait++ / jQuery.ready(true) logic. Fix problem where jQuery.ready may trigger twice, causing the (unsupported) document.onready to run twice. Fixes #8803 .
Diffstat (limited to 'src/core.js')
-rw-r--r--src/core.js18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/core.js b/src/core.js
index a893fc9b3..b81fa7644 100644
--- a/src/core.js
+++ b/src/core.js
@@ -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 ) {
- jQuery.readyWait--;
+ // Hold (or release) the ready event
+ holdReady: function( hold ) {
+ if ( hold ) {
+ jQuery.readyWait++;
+ } 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 );