scratch – Blame information for rev 125

Subversion Repositories:
Rev:
Rev Author Line No. Line
125 office 1 define([
58 office 2 "../core",
3 "./var/nonce",
4 "./var/rquery",
5 "../ajax"
6 ], function( jQuery, nonce, rquery ) {
7  
8 var oldCallbacks = [],
9 rjsonp = /(=)\?(?=&|$)|\?\?/;
10  
11 // Default jsonp settings
125 office 12 jQuery.ajaxSetup({
58 office 13 jsonp: "callback",
14 jsonpCallback: function() {
15 var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( nonce++ ) );
16 this[ callback ] = true;
17 return callback;
18 }
125 office 19 });
58 office 20  
21 // Detect, normalize options and install callbacks for jsonp requests
22 jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
23  
24 var callbackName, overwritten, responseContainer,
25 jsonProp = s.jsonp !== false && ( rjsonp.test( s.url ) ?
26 "url" :
125 office 27 typeof s.data === "string" && !( s.contentType || "" ).indexOf("application/x-www-form-urlencoded") && rjsonp.test( s.data ) && "data"
58 office 28 );
29  
30 // Handle iff the expected data type is "jsonp" or we have a parameter to set
31 if ( jsonProp || s.dataTypes[ 0 ] === "jsonp" ) {
32  
33 // Get callback name, remembering preexisting value associated with it
34 callbackName = s.jsonpCallback = jQuery.isFunction( s.jsonpCallback ) ?
35 s.jsonpCallback() :
36 s.jsonpCallback;
37  
38 // Insert callback into url or form data
39 if ( jsonProp ) {
40 s[ jsonProp ] = s[ jsonProp ].replace( rjsonp, "$1" + callbackName );
41 } else if ( s.jsonp !== false ) {
42 s.url += ( rquery.test( s.url ) ? "&" : "?" ) + s.jsonp + "=" + callbackName;
43 }
44  
45 // Use data converter to retrieve json after script execution
125 office 46 s.converters["script json"] = function() {
58 office 47 if ( !responseContainer ) {
48 jQuery.error( callbackName + " was not called" );
49 }
50 return responseContainer[ 0 ];
51 };
52  
125 office 53 // force json dataType
58 office 54 s.dataTypes[ 0 ] = "json";
55  
56 // Install callback
57 overwritten = window[ callbackName ];
58 window[ callbackName ] = function() {
59 responseContainer = arguments;
60 };
61  
62 // Clean-up function (fires after converters)
125 office 63 jqXHR.always(function() {
64 // Restore preexisting value
65 window[ callbackName ] = overwritten;
58 office 66  
67 // Save back as free
68 if ( s[ callbackName ] ) {
125 office 69 // make sure that re-using the options doesn't screw things around
58 office 70 s.jsonpCallback = originalSettings.jsonpCallback;
71  
125 office 72 // save the callback name for future use
58 office 73 oldCallbacks.push( callbackName );
74 }
75  
76 // Call if it was a function and we have a response
77 if ( responseContainer && jQuery.isFunction( overwritten ) ) {
78 overwritten( responseContainer[ 0 ] );
79 }
80  
81 responseContainer = overwritten = undefined;
125 office 82 });
58 office 83  
84 // Delegate to script
85 return "script";
86 }
125 office 87 });
58 office 88  
125 office 89 });