6 ], function( jQuery, nonce, rquery ) {
10 var oldCallbacks = [],
11 rjsonp = /(=)\?(?=&|$)|\?\?/;
13 // Default jsonp settings
16 jsonpCallback: function() {
17 var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( nonce++ ) );
18 this[ callback ] = true;
23 // Detect, normalize options and install callbacks for jsonp requests
24 jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
26 var callbackName, overwritten, responseContainer,
27 jsonProp = s.jsonp !== false && ( rjsonp.test( s.url ) ?
29 typeof s.data === "string" &&
30 ( s.contentType || "" )
31 .indexOf( "application/x-www-form-urlencoded" ) === 0 &&
32 rjsonp.test( s.data ) && "data"
35 // Handle iff the expected data type is "jsonp" or we have a parameter to set
36 if ( jsonProp || s.dataTypes[ 0 ] === "jsonp" ) {
38 // Get callback name, remembering preexisting value associated with it
39 callbackName = s.jsonpCallback = jQuery.isFunction( s.jsonpCallback ) ?
43 // Insert callback into url or form data
45 s[ jsonProp ] = s[ jsonProp ].replace( rjsonp, "$1" + callbackName );
46 } else if ( s.jsonp !== false ) {
47 s.url += ( rquery.test( s.url ) ? "&" : "?" ) + s.jsonp + "=" + callbackName;
50 // Use data converter to retrieve json after script execution
51 s.converters[ "script json" ] = function() {
52 if ( !responseContainer ) {
53 jQuery.error( callbackName + " was not called" );
55 return responseContainer[ 0 ];
58 // Force json dataType
59 s.dataTypes[ 0 ] = "json";
62 overwritten = window[ callbackName ];
63 window[ callbackName ] = function() {
64 responseContainer = arguments;
67 // Clean-up function (fires after converters)
68 jqXHR.always( function() {
70 // If previous value didn't exist - remove it
71 if ( overwritten === undefined ) {
72 jQuery( window ).removeProp( callbackName );
74 // Otherwise restore preexisting value
76 window[ callbackName ] = overwritten;
80 if ( s[ callbackName ] ) {
82 // Make sure that re-using the options doesn't screw things around
83 s.jsonpCallback = originalSettings.jsonpCallback;
85 // Save the callback name for future use
86 oldCallbacks.push( callbackName );
89 // Call if it was a function and we have a response
90 if ( responseContainer && jQuery.isFunction( overwritten ) ) {
91 overwritten( responseContainer[ 0 ] );
94 responseContainer = overwritten = undefined;