scratch – Diff between revs 58 and 125
?pathlinks?
Rev 58 | Rev 125 | |||
---|---|---|---|---|
Line 1... | Line 1... | |||
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"; |
- | ||
Line 9... | Line 6... | |||
9 | |
6 | |
|
10 | // The deferred used on DOM ready |
7 | // The deferred used on DOM ready |
|
Line 11... | Line 8... | |||
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 ) { |
- | ||
Line 22... | Line 11... | |||
22 | jQuery.readyException( error ); |
11 | // Add the callback |
|
23 | } ); |
12 | jQuery.ready.promise().done( fn ); |
|
Line 24... | Line 13... | |||
24 | |
13 | |
|
25 | return this; |
- | ||
26 | }; |
14 | return this; |
|
27 | |
15 | }; |
|
Line 28... | Line 16... | |||
28 | jQuery.extend( { |
16 | |
|
29 | |
17 | jQuery.extend({ |
|
Line 59... | Line 47... | |||
59 | return; |
47 | return; |
|
60 | } |
48 | } |
|
Line 61... | Line 49... | |||
61 | |
49 | |
|
62 | // If there are functions bound, to execute |
50 | // If there are functions bound, to execute |
|
63 | readyList.resolveWith( document, [ jQuery ] ); |
- | ||
64 | } |
- | ||
Line 65... | Line 51... | |||
65 | } ); |
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 | } |
||
Line -... | Line 58... | |||
- | 58 | } |
||
66 | |
59 | }); |
|
- | 60 | |
||
67 | jQuery.ready.then = readyList.then; |
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 ); |
|
Line 72... | Line -... | |||
72 | window.removeEventListener( "load", completed ); |
- | ||
73 | jQuery.ready(); |
- | ||
74 | } |
- | ||
75 | |
66 | window.removeEventListener( "load", completed, false ); |
|
76 | // Catch cases where $(document).ready() is called |
67 | jQuery.ready(); |
|
77 | // after the browser event has already occurred. |
- | ||
78 | // Support: IE <=9 - 10 only |
- | ||
79 | // Older IE sometimes signals "interactive" too soon |
- | ||
80 | if ( document.readyState === "complete" || |
- | ||
Line 81... | Line 68... | |||
81 | ( document.readyState !== "loading" && !document.documentElement.doScroll ) ) { |
68 | } |
|
Line -... | Line 69... | |||
- | 69 | |
||
- | 70 | jQuery.ready.promise = function( obj ) { |
||
- | 71 | if ( !readyList ) { |
||
82 | |
72 | |
|
83 | // Handle it asynchronously to allow scripts the opportunity to delay ready |
73 | readyList = jQuery.Deferred(); |
|
- | 74 | |
||
Line -... | Line 75... | |||
- | 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 |
||
84 | window.setTimeout( jQuery.ready ); |
80 | setTimeout( jQuery.ready ); |
|
85 | |
81 | |
|
- | 82 | } else { |
||
- | 83 | |
||
- | 84 | // Use the handy event callback |
||
86 | } else { |
85 | document.addEventListener( "DOMContentLoaded", completed, false ); |
|
- | 86 | |
||
- | 87 | // A fallback to window.onload, that will always work |
||
- | 88 | window.addEventListener( "load", completed, false ); |
||
Line 87... | Line 89... | |||
87 | |
89 | } |