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