6 ], function( jQuery
, document
) {
8 // The deferred used on DOM ready
11 jQuery
.fn
.ready = function( fn
) {
13 jQuery
.ready
.promise().done( fn
);
19 // Is the DOM ready to be used? Set to true once it occurs.
22 // A counter to track how many items to wait for before
23 // the ready event fires. See #6781
26 // Hold (or release) the ready event
27 holdReady: function( hold
) {
35 // Handle when the DOM is ready
36 ready: function( wait
) {
38 // Abort if there are pending holds or we're already ready
39 if ( wait
=== true ? --jQuery
.readyWait
: jQuery
.isReady
) {
43 // Remember that the DOM is ready
44 jQuery
.isReady
= true;
46 // If a normal DOM Ready event fired, decrement, and wait if need be
47 if ( wait
!== true && --jQuery
.readyWait
> 0 ) {
51 // If there are functions bound, to execute
52 readyList
.resolveWith( document
, [ jQuery
] );
54 // Trigger any bound ready events
55 if ( jQuery
.fn
.triggerHandler
) {
56 jQuery( document
).triggerHandler( "ready" );
57 jQuery( document
).off( "ready" );
63 * The ready event handler and self cleanup method
65 function completed() {
66 document
.removeEventListener( "DOMContentLoaded", completed
, false );
67 window
.removeEventListener( "load", completed
, false );
71 jQuery
.ready
.promise = function( obj
) {
74 readyList
= jQuery
.Deferred();
76 // Catch cases where $(document).ready() is called
77 // after the browser event has already occurred.
78 // We once tried to use readyState "interactive" here,
79 // but it caused issues like the one
80 // discovered by ChrisS here: http://bugs.jquery.com/ticket/12282#comment:15
81 if ( document
.readyState
=== "complete" ) {
82 // Handle it asynchronously to allow scripts the opportunity to delay ready
83 setTimeout( jQuery
.ready
);
87 // Use the handy event callback
88 document
.addEventListener( "DOMContentLoaded", completed
, false );
90 // A fallback to window.onload, that will always work
91 window
.addEventListener( "load", completed
, false );
94 return readyList
.promise( obj
);
97 // Kick off the DOM ready check even if the user does not
98 jQuery
.ready
.promise();