aboutsummaryrefslogtreecommitdiffstats
path: root/src/core.js
diff options
context:
space:
mode:
authorJohn Resig <jeresig@gmail.com>2010-09-20 14:53:29 -0400
committerJohn Resig <jeresig@gmail.com>2010-09-20 14:53:29 -0400
commit747ba7defd82bffa6c7ccb69e53b834cbfddb62c (patch)
tree70a4b888d141841c357e4333dfdde3063452ffe4 /src/core.js
parent5b92cdd0488804ba689dab70c6f8443aae23bcf9 (diff)
downloadjquery-747ba7defd82bffa6c7ccb69e53b834cbfddb62c.tar.gz
jquery-747ba7defd82bffa6c7ccb69e53b834cbfddb62c.zip
Allow plugins to delay the exeuction of the ready event. Delay the ready event by calling: jQuery.readyWait++ and force the event to fire by doing: jQuery.ready(true). Fixes #6781.
Diffstat (limited to 'src/core.js')
-rw-r--r--src/core.js18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/core.js b/src/core.js
index 0fec6e1c3..2b00627db 100644
--- a/src/core.js
+++ b/src/core.js
@@ -360,11 +360,20 @@ jQuery.extend({
// Is the DOM ready to be used? Set to true once it occurs.
isReady: false,
+
+ // A counter to track how many items to wait for before
+ // the ready event fires. See #6781
+ readyWait: 1,
// Handle when the DOM is ready
- ready: function() {
+ ready: function( wait ) {
+ // A third-party is pushing the ready event forwards
+ if ( wait === true ) {
+ jQuery.readyWait--;
+ }
+
// Make sure that the DOM is not already loaded
- if ( !jQuery.isReady ) {
+ if ( !jQuery.readyWait && !jQuery.isReady ) {
// Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
if ( !document.body ) {
return setTimeout( jQuery.ready, 13 );
@@ -373,6 +382,11 @@ jQuery.extend({
// Remember that the DOM is ready
jQuery.isReady = true;
+ // If a normal DOM Ready event fired, decrement, and wait if need be
+ if ( wait !== true && --jQuery.readyWait > 0 ) {
+ return;
+ }
+
// If there are functions bound, to execute
if ( readyList ) {
// Execute all of them