]> git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/ex-mode/node_modules/space-pen/node_modules/jquery/src/core/ready.js
db1a6e60aebdbebebfb00273f7d2f8a3a422a192
[rbdr/dotfiles] / atom / packages / ex-mode / node_modules / space-pen / node_modules / jquery / src / core / ready.js
1 define([
2 "../core",
3 "../core/init",
4 "../deferred"
5 ], function( jQuery ) {
6
7 // The deferred used on DOM ready
8 var readyList;
9
10 jQuery.fn.ready = function( fn ) {
11 // Add the callback
12 jQuery.ready.promise().done( fn );
13
14 return this;
15 };
16
17 jQuery.extend({
18 // Is the DOM ready to be used? Set to true once it occurs.
19 isReady: false,
20
21 // A counter to track how many items to wait for before
22 // the ready event fires. See #6781
23 readyWait: 1,
24
25 // Hold (or release) the ready event
26 holdReady: function( hold ) {
27 if ( hold ) {
28 jQuery.readyWait++;
29 } else {
30 jQuery.ready( true );
31 }
32 },
33
34 // Handle when the DOM is ready
35 ready: function( wait ) {
36
37 // Abort if there are pending holds or we're already ready
38 if ( wait === true ? --jQuery.readyWait : jQuery.isReady ) {
39 return;
40 }
41
42 // Remember that the DOM is ready
43 jQuery.isReady = true;
44
45 // If a normal DOM Ready event fired, decrement, and wait if need be
46 if ( wait !== true && --jQuery.readyWait > 0 ) {
47 return;
48 }
49
50 // If there are functions bound, to execute
51 readyList.resolveWith( document, [ jQuery ] );
52
53 // Trigger any bound ready events
54 if ( jQuery.fn.triggerHandler ) {
55 jQuery( document ).triggerHandler( "ready" );
56 jQuery( document ).off( "ready" );
57 }
58 }
59 });
60
61 /**
62 * The ready event handler and self cleanup method
63 */
64 function completed() {
65 document.removeEventListener( "DOMContentLoaded", completed, false );
66 window.removeEventListener( "load", completed, false );
67 jQuery.ready();
68 }
69
70 jQuery.ready.promise = function( obj ) {
71 if ( !readyList ) {
72
73 readyList = jQuery.Deferred();
74
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 );
81
82 } else {
83
84 // Use the handy event callback
85 document.addEventListener( "DOMContentLoaded", completed, false );
86
87 // A fallback to window.onload, that will always work
88 window.addEventListener( "load", completed, false );
89 }
90 }
91 return readyList.promise( obj );
92 };
93
94 // Kick off the DOM ready check even if the user does not
95 jQuery.ready.promise();
96
97 });