diff options
author | Richard Gibson <richard.gibson@gmail.com> | 2012-11-23 10:29:08 -0500 |
---|---|---|
committer | Richard Gibson <richard.gibson@gmail.com> | 2012-11-25 13:07:46 -0500 |
commit | a938d7b1282fc0e5c52502c225ae8f0cef219f0a (patch) | |
tree | e65720e5c0ab9c55690cabf16f0a7423c1c2daa7 /src/ajax/jsonp.js | |
parent | c27dc018e22260b6ad084dff4505172e6b107178 (diff) | |
download | jquery-a938d7b1282fc0e5c52502c225ae8f0cef219f0a.tar.gz jquery-a938d7b1282fc0e5c52502c225ae8f0cef219f0a.zip |
No ticket: compress ajax. Close gh-1041.
Diffstat (limited to 'src/ajax/jsonp.js')
-rw-r--r-- | src/ajax/jsonp.js | 31 |
1 files changed, 12 insertions, 19 deletions
diff --git a/src/ajax/jsonp.js b/src/ajax/jsonp.js index c39913fac..b8803df44 100644 --- a/src/ajax/jsonp.js +++ b/src/ajax/jsonp.js @@ -1,13 +1,11 @@ var oldCallbacks = [], - rquestion = /\?/, - rjsonp = /(=)\?(?=&|$)|\?\?/, - nonce = jQuery.now(); + rjsonp = /(=)\?(?=&|$)|\?\?/; // Default jsonp settings jQuery.ajaxSetup({ jsonp: "callback", jsonpCallback: function() { - var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( nonce++ ) ); + var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( ajax_nonce++ ) ); this[ callback ] = true; return callback; } @@ -17,30 +15,24 @@ jQuery.ajaxSetup({ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) { var callbackName, overwritten, responseContainer, - data = s.data, - url = s.url, - hasCallback = s.jsonp !== false, - replaceInUrl = hasCallback && rjsonp.test( url ), - replaceInData = hasCallback && !replaceInUrl && typeof data === "string" && - !( s.contentType || "" ).indexOf("application/x-www-form-urlencoded") && - rjsonp.test( data ); + jsonProp = s.jsonp !== false && ( rjsonp.test( s.url ) ? + "url" : + typeof s.data === "string" && !( s.contentType || "" ).indexOf("application/x-www-form-urlencoded") && rjsonp.test( s.data ) && "data" + ); // Handle iff the expected data type is "jsonp" or we have a parameter to set - if ( s.dataTypes[ 0 ] === "jsonp" || replaceInUrl || replaceInData ) { + if ( jsonProp || s.dataTypes[ 0 ] === "jsonp" ) { // Get callback name, remembering preexisting value associated with it callbackName = s.jsonpCallback = jQuery.isFunction( s.jsonpCallback ) ? s.jsonpCallback() : s.jsonpCallback; - overwritten = window[ callbackName ]; // Insert callback into url or form data - if ( replaceInUrl ) { - s.url = url.replace( rjsonp, "$1" + callbackName ); - } else if ( replaceInData ) { - s.data = data.replace( rjsonp, "$1" + callbackName ); - } else if ( hasCallback ) { - s.url += ( rquestion.test( url ) ? "&" : "?" ) + s.jsonp + "=" + callbackName; + if ( jsonProp ) { + s[ jsonProp ] = s[ jsonProp ].replace( rjsonp, "$1" + callbackName ); + } else if ( s.jsonp !== false ) { + s.url += ( ajax_rquery.test( s.url ) ? "&" : "?" ) + s.jsonp + "=" + callbackName; } // Use data converter to retrieve json after script execution @@ -55,6 +47,7 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) { s.dataTypes[ 0 ] = "json"; // Install callback + overwritten = window[ callbackName ]; window[ callbackName ] = function() { responseContainer = arguments; }; |