Skip to content

Commit 7a98b55

Browse files
author
InfinitiesLoop
committed
Ticket 6844. Ability to delay the ready event.
1 parent 1650672 commit 7a98b55

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/core.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ var jQuery = function( selector, context ) {
4646

4747
// The functions to execute on DOM ready
4848
readyList = [],
49+
50+
// Counts how many ready holds are active
51+
readyHold = 0,
4952

5053
// The ready event handler
5154
DOMContentLoaded,
@@ -360,9 +363,20 @@ jQuery.extend({
360363
isReady: false,
361364

362365
// Handle when the DOM is ready
363-
ready: function() {
366+
ready: function(state) {
364367
// Make sure that the DOM is not already loaded
365368
if ( !jQuery.isReady ) {
369+
if ( typeof state === "boolean" ) {
370+
// plugin is delaying or undelaying the ready event
371+
if ( state ) {
372+
readyHold--;
373+
} else {
374+
readyHold++;
375+
}
376+
}
377+
if ( readyHold > 0 ) {
378+
return;
379+
}
366380
// Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
367381
if ( !document.body ) {
368382
return setTimeout( jQuery.ready, 13 );

0 commit comments

Comments
 (0)