diff options
author | Mike Sherov <mike.sherov@gmail.com> | 2012-07-09 21:38:11 -0400 |
---|---|---|
committer | Dave Methvin <dave.methvin@gmail.com> | 2012-07-09 21:39:22 -0400 |
commit | 8f01b92b8fd85a66f2cba671f8b9ff6f7095c34b (patch) | |
tree | 6120b02292d65f3ac1248a7c82aae5fbbb505d7d /src/ajax.js | |
parent | f30f7732e7775b6e417c4c22ced7adb2bf76bf89 (diff) | |
download | jquery-8f01b92b8fd85a66f2cba671f8b9ff6f7095c34b.tar.gz jquery-8f01b92b8fd85a66f2cba671f8b9ff6f7095c34b.zip |
Follow the style guide, lose 72 bytes! Closes gh-840.
Diffstat (limited to 'src/ajax.js')
-rw-r--r-- | src/ajax.js | 81 |
1 files changed, 39 insertions, 42 deletions
diff --git a/src/ajax.js b/src/ajax.js index 8e7f10ef5..ac08de36c 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -1,4 +1,9 @@ -var r20 = /%20/g, +var // Document location + ajaxLocation, + // Document location segments + ajaxLocParts, + + r20 = /%20/g, rbracket = /\[\]$/, rCRLF = /\r?\n/g, rhash = /#.*$/, @@ -35,12 +40,6 @@ var r20 = /%20/g, */ transports = {}, - // Document location - ajaxLocation, - - // Document location segments - ajaxLocParts, - // Avoid comment-prolog char sequence (#10098); must appease lint and evade compression allTypes = ["*/"] + ["*"]; @@ -70,14 +69,12 @@ function addToPrefiltersOrTransports( structure ) { dataTypeExpression = "*"; } - if ( jQuery.isFunction( func ) ) { - var dataTypes = dataTypeExpression.toLowerCase().split( core_rspace ), - i = 0, - length = dataTypes.length, - dataType, - list, - placeBefore; + var dataType, list, placeBefore, + dataTypes = dataTypeExpression.toLowerCase().split( core_rspace ), + i = 0, + length = dataTypes.length; + if ( jQuery.isFunction( func ) ) { // For each dataType in the dataTypeExpression for ( ; i < length; i++ ) { dataType = dataTypes[ i ]; @@ -104,11 +101,11 @@ function inspectPrefiltersOrTransports( structure, options, originalOptions, jqX inspected[ dataType ] = true; - var list = structure[ dataType ], + var selection, + list = structure[ dataType ], i = 0, length = list ? list.length : 0, - executeOnly = ( structure === prefilters ), - selection; + executeOnly = ( structure === prefilters ); for ( ; i < length && ( executeOnly || !selection ); i++ ) { selection = list[ i ]( options, originalOptions, jqXHR ); @@ -383,7 +380,22 @@ jQuery.extend({ // Force options to be an object options = options || {}; - var // Create the final options object + var // ifModified key + ifModifiedKey, + // Response headers + responseHeadersString, + responseHeaders, + // transport + transport, + // timeout handle + timeoutTimer, + // Cross-domain detection vars + parts, + // To know if global events are to be dispatched + fireGlobals, + // Loop variable + i, + // Create the final options object s = jQuery.ajaxSetup( {}, options ), // Callbacks context callbackContext = s.context || s, @@ -398,26 +410,11 @@ jQuery.extend({ completeDeferred = jQuery.Callbacks( "once memory" ), // Status-dependent callbacks statusCode = s.statusCode || {}, - // ifModified key - ifModifiedKey, // Headers (they are sent all at once) requestHeaders = {}, requestHeadersNames = {}, - // Response headers - responseHeadersString, - responseHeaders, - // transport - transport, - // timeout handle - timeoutTimer, - // Cross-domain detection vars - parts, // The jqXHR state state = 0, - // To know if global events are to be dispatched - fireGlobals, - // Loop variable - i, // Default abort message strAbort = "canceled", // Fake xhr @@ -759,7 +756,8 @@ jQuery.extend({ // Serialize an array of form elements or a set of // key/values into a query string param: function( a, traditional ) { - var s = [], + var prefix, + s = [], add = function( key, value ) { // If value is a function, invoke it and return its value value = jQuery.isFunction( value ) ? value() : ( value == null ? "" : value ); @@ -781,7 +779,7 @@ jQuery.extend({ } else { // If traditional, encode the "old" way (the way 1.3.2 or older // did it), otherwise encode params recursively. - for ( var prefix in a ) { + for ( prefix in a ) { buildParams( prefix, a[ prefix ], traditional, add ); } } @@ -792,6 +790,8 @@ jQuery.extend({ }); function buildParams( prefix, obj, traditional, add ) { + var name; + if ( jQuery.isArray( obj ) ) { // Serialize array item. jQuery.each( obj, function( i, v ) { @@ -813,7 +813,7 @@ function buildParams( prefix, obj, traditional, add ) { } else if ( !traditional && jQuery.type( obj ) === "object" ) { // Serialize object item. - for ( var name in obj ) { + for ( name in obj ) { buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add ); } @@ -843,13 +843,10 @@ jQuery.extend({ */ function ajaxHandleResponses( s, jqXHR, responses ) { - var contents = s.contents, + var ct, type, finalDataType, firstDataType, + contents = s.contents, dataTypes = s.dataTypes, - responseFields = s.responseFields, - ct, - type, - finalDataType, - firstDataType; + responseFields = s.responseFields; // Fill responseXXX fields for ( type in responseFields ) { |