4 ], function( jQuery, document ) {
8 var readyCallbacks = [],
9 whenReady = function( fn ) {
10 readyCallbacks.push( fn );
12 executeReady = function( fn ) {
14 // Prevent errors from freezing future callback execution (gh-1823)
15 // Not backwards-compatible as this does not execute sync
16 window.setTimeout( function() {
17 fn.call( document, jQuery );
21 jQuery.fn.ready = function( fn ) {
28 // Is the DOM ready to be used? Set to true once it occurs.
31 // A counter to track how many items to wait for before
32 // the ready event fires. See #6781
35 ready: function( wait ) {
37 // Abort if there are pending holds or we're already ready
38 if ( wait === true ? --jQuery.readyWait : jQuery.isReady ) {
42 // Remember that the DOM is ready
43 jQuery.isReady = true;
45 // If a normal DOM Ready event fired, decrement, and wait if need be
46 if ( wait !== true && --jQuery.readyWait > 0 ) {
50 whenReady = function( fn ) {
51 readyCallbacks.push( fn );
53 while ( readyCallbacks.length ) {
54 fn = readyCallbacks.shift();
55 if ( jQuery.isFunction( fn ) ) {
65 // Make jQuery.ready Promise consumable (gh-1778)
66 jQuery.ready.then = jQuery.fn.ready;
69 * The ready event handler and self cleanup method
71 function completed() {
72 document.removeEventListener( "DOMContentLoaded", completed );
73 window.removeEventListener( "load", completed );
77 // Catch cases where $(document).ready() is called
78 // after the browser event has already occurred.
79 // Support: IE9-10 only
80 // Older IE sometimes signals "interactive" too soon
81 if ( document.readyState === "complete" ||
82 ( document.readyState !== "loading" && !document.documentElement.doScroll ) ) {
84 // Handle it asynchronously to allow scripts the opportunity to delay ready
85 window.setTimeout( jQuery.ready );
89 // Use the handy event callback
90 document.addEventListener( "DOMContentLoaded", completed );
92 // A fallback to window.onload, that will always work
93 window.addEventListener( "load", completed );