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