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.
This commit is contained in:
parent
5b92cdd048
commit
747ba7defd
18
src/core.js
18
src/core.js
|
@ -361,10 +361,19 @@ jQuery.extend({
|
||||||
// Is the DOM ready to be used? Set to true once it occurs.
|
// Is the DOM ready to be used? Set to true once it occurs.
|
||||||
isReady: false,
|
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
|
// 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
|
// 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).
|
// Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
|
||||||
if ( !document.body ) {
|
if ( !document.body ) {
|
||||||
return setTimeout( jQuery.ready, 13 );
|
return setTimeout( jQuery.ready, 13 );
|
||||||
|
@ -373,6 +382,11 @@ jQuery.extend({
|
||||||
// Remember that the DOM is ready
|
// Remember that the DOM is ready
|
||||||
jQuery.isReady = true;
|
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 there are functions bound, to execute
|
||||||
if ( readyList ) {
|
if ( readyList ) {
|
||||||
// Execute all of them
|
// Execute all of them
|
||||||
|
|
Loading…
Reference in a new issue