scratch – Blame information for rev 125
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
125 | office | 1 | define([ |
58 | office | 2 | "../core", |
125 | office | 3 | "../core/init", |
58 | office | 4 | "../deferred" |
125 | office | 5 | ], function( jQuery ) { |
58 | office | 6 | |
7 | // The deferred used on DOM ready |
||
125 | office | 8 | var readyList; |
58 | office | 9 | |
10 | jQuery.fn.ready = function( fn ) { |
||
125 | office | 11 | // Add the callback |
12 | jQuery.ready.promise().done( fn ); |
||
58 | office | 13 | |
14 | return this; |
||
15 | }; |
||
16 | |||
125 | office | 17 | jQuery.extend({ |
58 | office | 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 ] ); |
||
125 | office | 52 | |
53 | // Trigger any bound ready events |
||
54 | if ( jQuery.fn.triggerHandler ) { |
||
55 | jQuery( document ).triggerHandler( "ready" ); |
||
56 | jQuery( document ).off( "ready" ); |
||
57 | } |
||
58 | office | 58 | } |
125 | office | 59 | }); |
58 | office | 60 | |
125 | office | 61 | /** |
62 | * The ready event handler and self cleanup method |
||
63 | */ |
||
58 | office | 64 | function completed() { |
125 | office | 65 | document.removeEventListener( "DOMContentLoaded", completed, false ); |
66 | window.removeEventListener( "load", completed, false ); |
||
58 | office | 67 | jQuery.ready(); |
68 | } |
||
69 | |||
125 | office | 70 | jQuery.ready.promise = function( obj ) { |
71 | if ( !readyList ) { |
||
58 | office | 72 | |
125 | office | 73 | readyList = jQuery.Deferred(); |
58 | office | 74 | |
125 | office | 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 ); |
||
58 | office | 81 | |
125 | office | 82 | } else { |
58 | office | 83 | |
125 | office | 84 | // Use the handy event callback |
85 | document.addEventListener( "DOMContentLoaded", completed, false ); |
||
58 | office | 86 | |
125 | office | 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 | }); |