6 ], function( jQuery, document ) {
8 // The deferred used on DOM ready
11 jQuery.fn.ready = function( fn ) {
14 jQuery.ready.promise().done( fn );
21 // Is the DOM ready to be used? Set to true once it occurs.
24 // A counter to track how many items to wait for before
25 // the ready event fires. See #6781
28 // Hold (or release) the ready event
29 holdReady: function( hold ) {
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 ] );
56 // Trigger any bound ready events
57 if ( jQuery.fn.triggerHandler ) {
58 jQuery( document ).triggerHandler( "ready" );
59 jQuery( document ).off( "ready" );
65 * The ready event handler and self cleanup method
67 function completed() {
68 document.removeEventListener( "DOMContentLoaded", completed );
69 window.removeEventListener( "load", completed );
73 jQuery.ready.promise = function( obj ) {
76 readyList = jQuery.Deferred();
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 );
97 return readyList.promise( obj );
100 // Kick off the DOM ready check even if the user does not
101 jQuery.ready.promise();