4 "../core/readyException",
6 ], function( jQuery, document ) {
10 // The deferred used on DOM ready
11 var readyList = jQuery.Deferred();
13 jQuery.fn.ready = function( fn ) {
18 // Wrap jQuery.readyException in a function so that the lookup
19 // happens at the time of error handling instead of callback
21 .catch( function( error ) {
22 jQuery.readyException( error );
30 // Is the DOM ready to be used? Set to true once it occurs.
33 // A counter to track how many items to wait for before
34 // the ready event fires. See #6781
37 // Handle when the DOM is ready
38 ready: function( wait ) {
40 // Abort if there are pending holds or we're already ready
41 if ( wait === true ? --jQuery.readyWait : jQuery.isReady ) {
45 // Remember that the DOM is ready
46 jQuery.isReady = true;
48 // If a normal DOM Ready event fired, decrement, and wait if need be
49 if ( wait !== true && --jQuery.readyWait > 0 ) {
53 // If there are functions bound, to execute
54 readyList.resolveWith( document, [ jQuery ] );
58 jQuery.ready.then = readyList.then;
60 // The ready event handler and self cleanup method
61 function completed() {
62 document.removeEventListener( "DOMContentLoaded", completed );
63 window.removeEventListener( "load", completed );
67 // Catch cases where $(document).ready() is called
68 // after the browser event has already occurred.
69 // Support: IE <=9 - 10 only
70 // Older IE sometimes signals "interactive" too soon
71 if ( document.readyState === "complete" ||
72 ( document.readyState !== "loading" && !document.documentElement.doScroll ) ) {
74 // Handle it asynchronously to allow scripts the opportunity to delay ready
75 window.setTimeout( jQuery.ready );
79 // Use the handy event callback
80 document.addEventListener( "DOMContentLoaded", completed );
82 // A fallback to window.onload, that will always work
83 window.addEventListener( "load", completed );