+
+// Base function for both ajaxPrefilter and ajaxTransport
+function ajaxPrefilterOrTransport( arg0 , arg1 , arg2 ) {
+
+ var type = jQuery.type( arg1 ),
+ structure = jQuery.ajaxSettings[ arg0 ],
+ i,
+ length;
+
+ // We have an options map so we have to inspect the structure
+ if ( type === "object" ) {
+
+ var options = arg1,
+ originalOptions = arg2,
+ // When dealing with prefilters, we execute only
+ // (no selection so we never stop when a function
+ // returns a non-falsy, non-string value)
+ executeOnly = ( arg0 === "prefilters" ),
+ inspect = function( dataType, tested ) {
+
+ if ( ! tested[ dataType ] ) {
+
+ tested[ dataType ] = true;
+
+ var list = structure[ dataType ],
+ selected;
+
+ for( i = 0, length = list ? list.length : 0 ; ( executeOnly || ! selected ) && i < length ; i++ ) {
+ selected = list[ i ]( options , originalOptions );
+ // If we got redirected to a different dataType,
+ // we add it and switch to the corresponding list
+ if ( typeof( selected ) === "string" && selected !== dataType ) {
+ options.dataTypes.unshift( selected );
+ selected = inspect( selected , tested );
+ // We always break in order not to continue
+ // to iterate in previous list
+ break;
+ }
+ }
+ // If we're only executing or nothing was selected
+ // we try the catchall dataType
+ if ( executeOnly || ! selected ) {
+ selected = inspect( "*" , tested );
+ }
+ // This will be ignored by ajaxPrefilter
+ // so it's safe to return no matter what
+ return selected;
+ }
+
+ };
+
+ // Start inspection with current transport dataType
+ return inspect( options.dataTypes[ 0 ] , {} );
+
+ } else {
+
+ // We're requested to add to the structure
+ // Signature is ( dataTypeExpression , function )
+ // with dataTypeExpression being optional and
+ // defaulting to catchAll (*)
+ type = type === "function";
+
+ if ( type ) {
+ arg2 = arg1;
+ arg1 = undefined;
+ }
+ arg1 = arg1 || "*";
+
+ // We control that the second argument is really a function
+ if ( type || jQuery.isFunction( arg2 ) ) {
+
+ var dataTypes = arg1.split( /\s+/ ),
+ functor = arg2,
+ dataType,
+ list,
+ placeBefore;
+
+ // For each dataType in the dataTypeExpression
+ for( i = 0 , length = dataTypes.length ; i < length ; i++ ) {
+ dataType = dataTypes[ i ];
+ // We control if we're asked to add before
+ // any existing element
+ placeBefore = /^\+/.test( dataType );
+ if ( placeBefore ) {
+ dataType = dataType.substr( 1 );
+ }
+ list = structure[ dataType ] = structure[ dataType ] || [];
+ // then we add to the structure accordingly
+ list[ placeBefore ? "unshift" : "push" ]( functor );
+ }
+ }
+ }
+}
+
+})( jQuery );