- length,
- checked = {},
- flag,
- noSelect = structure !== "transports";
-
- function initSearch( dataType ) {
-
- flag = transportDataType !== dataType && ! checked[ dataType ];
-
- if ( flag ) {
-
- checked[ dataType ] = 1;
- transportDataType = dataType;
- list = s[ structure ][ dataType ];
- i = -1;
- length = list ? list.length : 0 ;
- }
-
- return flag;
- }
-
- initSearch( dataTypes[ 0 ] );
-
- for ( i = 0 ; ( noSelect || ! selected ) && i <= length ; i++ ) {
-
- if ( i === length ) {
-
- initSearch( "*" );
-
- } else {
-
- selected = list[ i ]( s , determineDataType );
-
- // If we got redirected to another dataType
- // Search there (if not in progress or already tried)
- if ( typeof( selected ) === "string" &&
- initSearch( selected ) ) {
-
- dataTypes.unshift( selected );
- selected = 0;
- }
- }
- }
-
- return noSelect ? jQuery.ajax : selected;
-}
-
-// Add an element to one of the structures in ajaxSettings
-function ajax_addElement( structure , args ) {
-
- var i,
- start = 0,
- length = args.length,
- dataTypes = [ "*" ],
- dLength = 1,
- dataType,
- functors = [],
- first,
- append,
- list;
-
- if ( length ) {
-
- first = jQuery.type( args[ 0 ] );
+ 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;
+ }