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/nonce", |
3 | "./var/nonce", |
|
4 | "./var/rquery", |
4 | "./var/rquery", |
|
5 | "../ajax" |
5 | "../ajax" |
|
6 | ], function( jQuery, nonce, rquery ) { |
6 | ], function( jQuery, nonce, rquery ) { |
|
Line 7... | Line -... | |||
7 | |
- | ||
8 | "use strict"; |
- | ||
9 | |
7 | |
|
10 | var oldCallbacks = [], |
8 | var oldCallbacks = [], |
|
Line 11... | Line 9... | |||
11 | rjsonp = /(=)\?(?=&|$)|\?\?/; |
9 | rjsonp = /(=)\?(?=&|$)|\?\?/; |
|
12 | |
10 | |
|
13 | // Default jsonp settings |
11 | // Default jsonp settings |
|
14 | jQuery.ajaxSetup( { |
12 | jQuery.ajaxSetup({ |
|
15 | jsonp: "callback", |
13 | jsonp: "callback", |
|
16 | jsonpCallback: function() { |
14 | jsonpCallback: function() { |
|
17 | var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( nonce++ ) ); |
15 | var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( nonce++ ) ); |
|
18 | this[ callback ] = true; |
16 | this[ callback ] = true; |
|
19 | return callback; |
17 | return callback; |
|
Line 20... | Line 18... | |||
20 | } |
18 | } |
|
21 | } ); |
19 | }); |
|
Line 22... | Line 20... | |||
22 | |
20 | |
|
23 | // Detect, normalize options and install callbacks for jsonp requests |
21 | // Detect, normalize options and install callbacks for jsonp requests |
|
24 | jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) { |
22 | jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) { |
|
25 | |
- | ||
26 | var callbackName, overwritten, responseContainer, |
- | ||
27 | jsonProp = s.jsonp !== false && ( rjsonp.test( s.url ) ? |
23 | |
|
28 | "url" : |
- | ||
29 | typeof s.data === "string" && |
24 | var callbackName, overwritten, responseContainer, |
|
Line 30... | Line 25... | |||
30 | ( s.contentType || "" ) |
25 | jsonProp = s.jsonp !== false && ( rjsonp.test( s.url ) ? |
|
31 | .indexOf( "application/x-www-form-urlencoded" ) === 0 && |
26 | "url" : |
|
Line 46... | Line 41... | |||
46 | } else if ( s.jsonp !== false ) { |
41 | } else if ( s.jsonp !== false ) { |
|
47 | s.url += ( rquery.test( s.url ) ? "&" : "?" ) + s.jsonp + "=" + callbackName; |
42 | s.url += ( rquery.test( s.url ) ? "&" : "?" ) + s.jsonp + "=" + callbackName; |
|
48 | } |
43 | } |
|
Line 49... | Line 44... | |||
49 | |
44 | |
|
50 | // Use data converter to retrieve json after script execution |
45 | // Use data converter to retrieve json after script execution |
|
51 | s.converters[ "script json" ] = function() { |
46 | s.converters["script json"] = function() { |
|
52 | if ( !responseContainer ) { |
47 | if ( !responseContainer ) { |
|
53 | jQuery.error( callbackName + " was not called" ); |
48 | jQuery.error( callbackName + " was not called" ); |
|
54 | } |
49 | } |
|
55 | return responseContainer[ 0 ]; |
50 | return responseContainer[ 0 ]; |
|
Line 56... | Line 51... | |||
56 | }; |
51 | }; |
|
57 | |
52 | |
|
Line 58... | Line 53... | |||
58 | // Force json dataType |
53 | // force json dataType |
|
59 | s.dataTypes[ 0 ] = "json"; |
54 | s.dataTypes[ 0 ] = "json"; |
|
60 | |
55 | |
|
61 | // Install callback |
56 | // Install callback |
|
62 | overwritten = window[ callbackName ]; |
57 | overwritten = window[ callbackName ]; |
|
Line 63... | Line 58... | |||
63 | window[ callbackName ] = function() { |
58 | window[ callbackName ] = function() { |
|
64 | responseContainer = arguments; |
59 | responseContainer = arguments; |
|
65 | }; |
- | ||
66 | |
- | ||
67 | // Clean-up function (fires after converters) |
- | ||
68 | jqXHR.always( function() { |
- | ||
69 | |
- | ||
70 | // If previous value didn't exist - remove it |
60 | }; |
|
71 | if ( overwritten === undefined ) { |
- | ||
72 | jQuery( window ).removeProp( callbackName ); |
61 | |
|
73 | |
- | ||
Line 74... | Line 62... | |||
74 | // Otherwise restore preexisting value |
62 | // Clean-up function (fires after converters) |
|
75 | } else { |
63 | jqXHR.always(function() { |
|
76 | window[ callbackName ] = overwritten; |
- | ||
77 | } |
64 | // Restore preexisting value |
|
78 | |
65 | window[ callbackName ] = overwritten; |
|
Line 79... | Line 66... | |||
79 | // Save back as free |
66 | |
|
80 | if ( s[ callbackName ] ) { |
67 | // Save back as free |
|
81 | |
68 | if ( s[ callbackName ] ) { |
|
Line 82... | Line 69... | |||
82 | // Make sure that re-using the options doesn't screw things around |
69 | // make sure that re-using the options doesn't screw things around |
|
83 | s.jsonpCallback = originalSettings.jsonpCallback; |
70 | s.jsonpCallback = originalSettings.jsonpCallback; |
|
84 | |
71 | |
|
85 | // Save the callback name for future use |
72 | // save the callback name for future use |
|
Line 86... | Line 73... | |||
86 | oldCallbacks.push( callbackName ); |
73 | oldCallbacks.push( callbackName ); |
|
87 | } |
74 | } |
|
Line 88... | Line 75... | |||
88 | |
75 | |
|
89 | // Call if it was a function and we have a response |
76 | // Call if it was a function and we have a response |
|
90 | if ( responseContainer && jQuery.isFunction( overwritten ) ) { |
77 | if ( responseContainer && jQuery.isFunction( overwritten ) ) { |
|
91 | overwritten( responseContainer[ 0 ] ); |
78 | overwritten( responseContainer[ 0 ] ); |
|
Line 92... | Line 79... | |||
92 | } |
79 | } |