scratch – Diff between revs 58 and 125
?pathlinks?
Rev 58 | Rev 125 | |||
---|---|---|---|---|
1 | define( [ |
1 | define([ |
|
2 | "../core", |
2 | "../core", |
|
3 | "../var/document", |
3 | "../core/init", |
|
4 | "../core/readyException", |
- | ||
5 | "../deferred" |
4 | "../deferred" |
|
6 | ], function( jQuery, document ) { |
5 | ], function( jQuery ) { |
|
7 | |
- | ||
8 | "use strict"; |
- | ||
9 | |
6 | |
|
10 | // The deferred used on DOM ready |
7 | // The deferred used on DOM ready |
|
11 | var readyList = jQuery.Deferred(); |
8 | var readyList; |
|
12 | |
- | ||
13 | jQuery.fn.ready = function( fn ) { |
- | ||
14 | |
- | ||
15 | readyList |
- | ||
16 | .then( fn ) |
- | ||
17 | |
- | ||
18 | // Wrap jQuery.readyException in a function so that the lookup |
9 | |
|
19 | // happens at the time of error handling instead of callback |
- | ||
20 | // registration. |
10 | jQuery.fn.ready = function( fn ) { |
|
21 | .catch( function( error ) { |
- | ||
22 | jQuery.readyException( error ); |
11 | // Add the callback |
|
23 | } ); |
12 | jQuery.ready.promise().done( fn ); |
|
24 | |
13 | |
|
25 | return this; |
14 | return this; |
|
26 | }; |
15 | }; |
|
27 | |
16 | |
|
28 | jQuery.extend( { |
- | ||
29 | |
17 | jQuery.extend({ |
|
30 | // Is the DOM ready to be used? Set to true once it occurs. |
18 | // Is the DOM ready to be used? Set to true once it occurs. |
|
31 | isReady: false, |
19 | isReady: false, |
|
32 | |
20 | |
|
33 | // A counter to track how many items to wait for before |
21 | // A counter to track how many items to wait for before |
|
34 | // the ready event fires. See #6781 |
22 | // the ready event fires. See #6781 |
|
35 | readyWait: 1, |
23 | readyWait: 1, |
|
36 | |
24 | |
|
37 | // Hold (or release) the ready event |
25 | // Hold (or release) the ready event |
|
38 | holdReady: function( hold ) { |
26 | holdReady: function( hold ) { |
|
39 | if ( hold ) { |
27 | if ( hold ) { |
|
40 | jQuery.readyWait++; |
28 | jQuery.readyWait++; |
|
41 | } else { |
29 | } else { |
|
42 | jQuery.ready( true ); |
30 | jQuery.ready( true ); |
|
43 | } |
31 | } |
|
44 | }, |
32 | }, |
|
45 | |
33 | |
|
46 | // Handle when the DOM is ready |
34 | // Handle when the DOM is ready |
|
47 | ready: function( wait ) { |
35 | ready: function( wait ) { |
|
48 | |
36 | |
|
49 | // Abort if there are pending holds or we're already ready |
37 | // Abort if there are pending holds or we're already ready |
|
50 | if ( wait === true ? --jQuery.readyWait : jQuery.isReady ) { |
38 | if ( wait === true ? --jQuery.readyWait : jQuery.isReady ) { |
|
51 | return; |
39 | return; |
|
52 | } |
40 | } |
|
53 | |
41 | |
|
54 | // Remember that the DOM is ready |
42 | // Remember that the DOM is ready |
|
55 | jQuery.isReady = true; |
43 | jQuery.isReady = true; |
|
56 | |
44 | |
|
57 | // If a normal DOM Ready event fired, decrement, and wait if need be |
45 | // If a normal DOM Ready event fired, decrement, and wait if need be |
|
58 | if ( wait !== true && --jQuery.readyWait > 0 ) { |
46 | if ( wait !== true && --jQuery.readyWait > 0 ) { |
|
59 | return; |
47 | return; |
|
60 | } |
48 | } |
|
61 | |
49 | |
|
62 | // If there are functions bound, to execute |
50 | // If there are functions bound, to execute |
|
63 | readyList.resolveWith( document, [ jQuery ] ); |
51 | readyList.resolveWith( document, [ jQuery ] ); |
|
64 | } |
- | ||
65 | } ); |
- | ||
66 | |
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 | }); |
||
67 | jQuery.ready.then = readyList.then; |
60 | |
|
- | 61 | /** |
||
68 | |
62 | * The ready event handler and self cleanup method |
|
69 | // The ready event handler and self cleanup method |
63 | */ |
|
70 | function completed() { |
64 | function completed() { |
|
71 | document.removeEventListener( "DOMContentLoaded", completed ); |
65 | document.removeEventListener( "DOMContentLoaded", completed, false ); |
|
72 | window.removeEventListener( "load", completed ); |
66 | window.removeEventListener( "load", completed, false ); |
|
73 | jQuery.ready(); |
67 | jQuery.ready(); |
|
74 | } |
68 | } |
|
75 | |
- | ||
76 | // Catch cases where $(document).ready() is called |
- | ||
77 | // after the browser event has already occurred. |
- | ||
78 | // Support: IE <=9 - 10 only |
69 | |
|
79 | // Older IE sometimes signals "interactive" too soon |
70 | jQuery.ready.promise = function( obj ) { |
|
80 | if ( document.readyState === "complete" || |
- | ||
81 | ( document.readyState !== "loading" && !document.documentElement.doScroll ) ) { |
- | ||
82 | |
- | ||
83 | // Handle it asynchronously to allow scripts the opportunity to delay ready |
- | ||
84 | window.setTimeout( jQuery.ready ); |
71 | if ( !readyList ) { |
|
- | 72 | |
||
- | 73 | readyList = jQuery.Deferred(); |
||
- | 74 | |
||
85 | |
75 | // Catch cases where $(document).ready() is called after the browser event has already occurred. |
|
86 | } else { |
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 { |
||
87 | |
83 | |
|
88 | // Use the handy event callback |
84 | // Use the handy event callback |
|
- | 85 | document.addEventListener( "DOMContentLoaded", completed, false ); |
||
- | 86 | |
||
- | 87 | // A fallback to window.onload, that will always work |
||
89 | document.addEventListener( "DOMContentLoaded", completed ); |
88 | window.addEventListener( "load", completed, false ); |
|
- | 89 | } |
||
- | 90 | } |
||
- | 91 | return readyList.promise( obj ); |
||
90 | |
92 | }; |
|
91 | // A fallback to window.onload, that will always work |
93 | |
|
92 | window.addEventListener( "load", completed ); |
94 | // Kick off the DOM ready check even if the user does not |
|
93 | } |
95 | jQuery.ready.promise(); |
|
94 | |
96 | |
|
95 | } ); |
97 | }); |
|
96 | |
98 | |