|
define( [ |
|
"../core", |
|
"./var/nonce", |
|
"./var/rquery", |
|
"../ajax" |
|
], function( jQuery, nonce, rquery ) { |
|
|
|
var oldCallbacks = [], |
|
rjsonp = /(=)\?(?=&|$)|\?\?/; |
|
|
|
|
|
jQuery.ajaxSetup( { |
|
jsonp: "callback", |
|
jsonpCallback: function() { |
|
var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( nonce++ ) ); |
|
this[ callback ] = true; |
|
return callback; |
|
} |
|
} ); |
|
|
|
|
|
jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) { |
|
|
|
var callbackName, overwritten, responseContainer, |
|
jsonProp = s.jsonp !== false && ( rjsonp.test( s.url ) ? |
|
"url" : |
|
typeof s.data === "string" && |
|
( s.contentType || "" ) |
|
.indexOf( "application/x-www-form-urlencoded" ) === 0 && |
|
rjsonp.test( s.data ) && "data" |
|
); |
|
|
|
|
|
if ( jsonProp || s.dataTypes[ 0 ] === "jsonp" ) { |
|
|
|
|
|
callbackName = s.jsonpCallback = jQuery.isFunction( s.jsonpCallback ) ? |
|
s.jsonpCallback() : |
|
s.jsonpCallback; |
|
|
|
|
|
if ( jsonProp ) { |
|
s[ jsonProp ] = s[ jsonProp ].replace( rjsonp, "$1" + callbackName ); |
|
} else if ( s.jsonp !== false ) { |
|
s.url += ( rquery.test( s.url ) ? "&" : "?" ) + s.jsonp + "=" + callbackName; |
|
} |
|
|
|
|
|
s.converters[ "script json" ] = function() { |
|
if ( !responseContainer ) { |
|
jQuery.error( callbackName + " was not called" ); |
|
} |
|
return responseContainer[ 0 ]; |
|
}; |
|
|
|
|
|
s.dataTypes[ 0 ] = "json"; |
|
|
|
|
|
overwritten = window[ callbackName ]; |
|
window[ callbackName ] = function() { |
|
responseContainer = arguments; |
|
}; |
|
|
|
|
|
jqXHR.always( function() { |
|
|
|
|
|
if ( overwritten === undefined ) { |
|
jQuery( window ).removeProp( callbackName ); |
|
|
|
|
|
} else { |
|
window[ callbackName ] = overwritten; |
|
} |
|
|
|
|
|
if ( s[ callbackName ] ) { |
|
|
|
|
|
s.jsonpCallback = originalSettings.jsonpCallback; |
|
|
|
|
|
oldCallbacks.push( callbackName ); |
|
} |
|
|
|
|
|
if ( responseContainer && jQuery.isFunction( overwritten ) ) { |
|
overwritten( responseContainer[ 0 ] ); |
|
} |
|
|
|
responseContainer = overwritten = undefined; |
|
} ); |
|
|
|
|
|
return "script"; |
|
} |
|
} ); |
|
|
|
} ); |
|
|