7 ], function( jQuery, isFunction, nonce, rquery ) {
11 var oldCallbacks = [],
12 rjsonp = /(=)\?(?=&|$)|\?\?/;
14 // Default jsonp settings
17 jsonpCallback: function() {
18 var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( nonce++ ) );
19 this[ callback ] = true;
24 // Detect, normalize options and install callbacks for jsonp requests
25 jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
27 var callbackName, overwritten, responseContainer,
28 jsonProp = s.jsonp !== false && ( rjsonp.test( s.url ) ?
30 typeof s.data === "string" &&
31 ( s.contentType || "" )
32 .indexOf( "application/x-www-form-urlencoded" ) === 0 &&
33 rjsonp.test( s.data ) && "data"
36 // Handle iff the expected data type is "jsonp" or we have a parameter to set
37 if ( jsonProp || s.dataTypes[ 0 ] === "jsonp" ) {
39 // Get callback name, remembering preexisting value associated with it
40 callbackName = s.jsonpCallback = isFunction( s.jsonpCallback ) ?
44 // Insert callback into url or form data
46 s[ jsonProp ] = s[ jsonProp ].replace( rjsonp, "$1" + callbackName );
47 } else if ( s.jsonp !== false ) {
48 s.url += ( rquery.test( s.url ) ? "&" : "?" ) + s.jsonp + "=" + callbackName;
51 // Use data converter to retrieve json after script execution
52 s.converters[ "script json" ] = function() {
53 if ( !responseContainer ) {
54 jQuery.error( callbackName + " was not called" );
56 return responseContainer[ 0 ];
59 // Force json dataType
60 s.dataTypes[ 0 ] = "json";
63 overwritten = window[ callbackName ];
64 window[ callbackName ] = function() {
65 responseContainer = arguments;
68 // Clean-up function (fires after converters)
69 jqXHR.always( function() {
71 // If previous value didn't exist - remove it
72 if ( overwritten === undefined ) {
73 jQuery( window ).removeProp( callbackName );
75 // Otherwise restore preexisting value
77 window[ callbackName ] = overwritten;
81 if ( s[ callbackName ] ) {
83 // Make sure that re-using the options doesn't screw things around
84 s.jsonpCallback = originalSettings.jsonpCallback;
86 // Save the callback name for future use
87 oldCallbacks.push( callbackName );
90 // Call if it was a function and we have a response
91 if ( responseContainer && isFunction( overwritten ) ) {
92 overwritten( responseContainer[ 0 ] );
95 responseContainer = overwritten = undefined;