5 ], function( jQuery, document, isFunction ) {
9 var readyCallbacks = [],
10 whenReady = function( fn ) {
11 readyCallbacks.push( fn );
13 executeReady = function( fn ) {
15 // Prevent errors from freezing future callback execution (gh-1823)
16 // Not backwards-compatible as this does not execute sync
17 window.setTimeout( function() {
18 fn.call( document, jQuery );
22 jQuery.fn.ready = function( fn ) {
29 // Is the DOM ready to be used? Set to true once it occurs.
32 // A counter to track how many items to wait for before
33 // the ready event fires. See #6781
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 whenReady = function( fn ) {
52 readyCallbacks.push( fn );
54 while ( readyCallbacks.length ) {
55 fn = readyCallbacks.shift();
56 if ( isFunction( fn ) ) {
66 // Make jQuery.ready Promise consumable (gh-1778)
67 jQuery.ready.then = jQuery.fn.ready;
70 * The ready event handler and self cleanup method
72 function completed() {
73 document.removeEventListener( "DOMContentLoaded", completed );
74 window.removeEventListener( "load", completed );
78 // Catch cases where $(document).ready() is called
79 // after the browser event has already occurred.
80 // Support: IE9-10 only
81 // Older IE sometimes signals "interactive" too soon
82 if ( document.readyState === "complete" ||
83 ( document.readyState !== "loading" && !document.documentElement.doScroll ) ) {
85 // Handle it asynchronously to allow scripts the opportunity to delay ready
86 window.setTimeout( jQuery.ready );
90 // Use the handy event callback
91 document.addEventListener( "DOMContentLoaded", completed );
93 // A fallback to window.onload, that will always work
94 window.addEventListener( "load", completed );