5 ], function( jQuery ) {
7 // The deferred used on DOM ready
10 jQuery.fn.ready = function( fn ) {
12 jQuery.ready.promise().done( fn );
18 // Is the DOM ready to be used? Set to true once it occurs.
21 // A counter to track how many items to wait for before
22 // the ready event fires. See #6781
25 // Hold (or release) the ready event
26 holdReady: function( hold ) {
34 // Handle when the DOM is ready
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 // If there are functions bound, to execute
51 readyList.resolveWith( document, [ jQuery ] );
53 // Trigger any bound ready events
54 if ( jQuery.fn.triggerHandler ) {
55 jQuery( document ).triggerHandler( "ready" );
56 jQuery( document ).off( "ready" );
62 * The ready event handler and self cleanup method
64 function completed() {
65 document.removeEventListener( "DOMContentLoaded", completed, false );
66 window.removeEventListener( "load", completed, false );
70 jQuery.ready.promise = function( obj ) {
73 readyList = jQuery.Deferred();
75 // Catch cases where $(document).ready() is called after the browser event has already occurred.
76 // We once tried to use readyState "interactive" here, but it caused issues like the one
77 // discovered by ChrisS here: http://bugs.jquery.com/ticket/12282#comment:15
78 if ( document.readyState === "complete" ) {
79 // Handle it asynchronously to allow scripts the opportunity to delay ready
80 setTimeout( jQuery.ready );
84 // Use the handy event callback
85 document.addEventListener( "DOMContentLoaded", completed, false );
87 // A fallback to window.onload, that will always work
88 window.addEventListener( "load", completed, false );
91 return readyList.promise( obj );
94 // Kick off the DOM ready check even if the user does not
95 jQuery.ready.promise();