/bower_components/jquery/src/ajax.js |
@@ -1,30 +1,23 @@ |
define( [ |
define([ |
"./core", |
"./var/document", |
"./var/rnothtmlwhite", |
"./ajax/var/location", |
"./var/rnotwhite", |
"./ajax/var/nonce", |
"./ajax/var/rquery", |
|
"./core/init", |
"./ajax/parseJSON", |
"./ajax/parseXML", |
"./event/trigger", |
"./deferred", |
"./serialize" // jQuery.param |
], function( jQuery, document, rnothtmlwhite, location, nonce, rquery ) { |
"./deferred" |
], function( jQuery, rnotwhite, nonce, rquery ) { |
|
"use strict"; |
|
var |
r20 = /%20/g, |
rhash = /#.*$/, |
rantiCache = /([?&])_=[^&]*/, |
rts = /([?&])_=[^&]*/, |
rheaders = /^(.*?):[ \t]*([^\r\n]*)$/mg, |
|
// #7653, #8125, #8152: local protocol detection |
rlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/, |
rnoContent = /^(?:GET|HEAD)$/, |
rprotocol = /^\/\//, |
rurl = /^([\w.+-]+:)(?:\/\/(?:[^\/?#]*@|)([^\/?#:]*)(?::(\d+)|)|)/, |
|
/* Prefilters |
* 1) They are useful to introduce custom dataTypes (see ajax/jsonp.js for an example) |
@@ -47,10 +40,12 @@ |
// Avoid comment-prolog char sequence (#10098); must appease lint and evade compression |
allTypes = "*/".concat( "*" ), |
|
// Anchor tag for parsing the document origin |
originAnchor = document.createElement( "a" ); |
originAnchor.href = location.href; |
// Document location |
ajaxLocation = window.location.href, |
|
// Segment location into parts |
ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() ) || []; |
|
// Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport |
function addToPrefiltersOrTransports( structure ) { |
|
@@ -64,21 +59,19 @@ |
|
var dataType, |
i = 0, |
dataTypes = dataTypeExpression.toLowerCase().match( rnothtmlwhite ) || []; |
dataTypes = dataTypeExpression.toLowerCase().match( rnotwhite ) || []; |
|
if ( jQuery.isFunction( func ) ) { |
|
// For each dataType in the dataTypeExpression |
while ( ( dataType = dataTypes[ i++ ] ) ) { |
|
while ( (dataType = dataTypes[i++]) ) { |
// Prepend if requested |
if ( dataType[ 0 ] === "+" ) { |
if ( dataType[0] === "+" ) { |
dataType = dataType.slice( 1 ) || "*"; |
( structure[ dataType ] = structure[ dataType ] || [] ).unshift( func ); |
(structure[ dataType ] = structure[ dataType ] || []).unshift( func ); |
|
// Otherwise append |
} else { |
( structure[ dataType ] = structure[ dataType ] || [] ).push( func ); |
(structure[ dataType ] = structure[ dataType ] || []).push( func ); |
} |
} |
} |
@@ -96,9 +89,7 @@ |
inspected[ dataType ] = true; |
jQuery.each( structure[ dataType ] || [], function( _, prefilterOrFactory ) { |
var dataTypeOrTransport = prefilterOrFactory( options, originalOptions, jqXHR ); |
if ( typeof dataTypeOrTransport === "string" && |
!seekingTransport && !inspected[ dataTypeOrTransport ] ) { |
|
if ( typeof dataTypeOrTransport === "string" && !seekingTransport && !inspected[ dataTypeOrTransport ] ) { |
options.dataTypes.unshift( dataTypeOrTransport ); |
inspect( dataTypeOrTransport ); |
return false; |
@@ -105,7 +96,7 @@ |
} else if ( seekingTransport ) { |
return !( selected = dataTypeOrTransport ); |
} |
} ); |
}); |
return selected; |
} |
|
@@ -121,7 +112,7 @@ |
|
for ( key in src ) { |
if ( src[ key ] !== undefined ) { |
( flatOptions[ key ] ? target : ( deep || ( deep = {} ) ) )[ key ] = src[ key ]; |
( flatOptions[ key ] ? target : ( deep || (deep = {}) ) )[ key ] = src[ key ]; |
} |
} |
if ( deep ) { |
@@ -145,7 +136,7 @@ |
while ( dataTypes[ 0 ] === "*" ) { |
dataTypes.shift(); |
if ( ct === undefined ) { |
ct = s.mimeType || jqXHR.getResponseHeader( "Content-Type" ); |
ct = s.mimeType || jqXHR.getResponseHeader("Content-Type"); |
} |
} |
|
@@ -163,10 +154,9 @@ |
if ( dataTypes[ 0 ] in responses ) { |
finalDataType = dataTypes[ 0 ]; |
} else { |
|
// Try convertible dataTypes |
for ( type in responses ) { |
if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[ 0 ] ] ) { |
if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) { |
finalDataType = type; |
break; |
} |
@@ -174,7 +164,6 @@ |
firstDataType = type; |
} |
} |
|
// Or just use first one |
finalDataType = finalDataType || firstDataType; |
} |
@@ -196,7 +185,6 @@ |
function ajaxConvert( s, response, jqXHR, isSuccess ) { |
var conv2, current, conv, tmp, prev, |
converters = {}, |
|
// Work with a copy of dataTypes in case we need to modify it for conversion |
dataTypes = s.dataTypes.slice(); |
|
@@ -226,7 +214,7 @@ |
|
if ( current ) { |
|
// There's only work to do if current dataType is non-auto |
// There's only work to do if current dataType is non-auto |
if ( current === "*" ) { |
|
current = prev; |
@@ -249,7 +237,6 @@ |
conv = converters[ prev + " " + tmp[ 0 ] ] || |
converters[ "* " + tmp[ 0 ] ]; |
if ( conv ) { |
|
// Condense equivalence converters |
if ( conv === true ) { |
conv = converters[ conv2 ]; |
@@ -269,16 +256,13 @@ |
if ( conv !== true ) { |
|
// Unless errors are allowed to bubble, catch and return them |
if ( conv && s.throws ) { |
if ( conv && s[ "throws" ] ) { |
response = conv( response ); |
} else { |
try { |
response = conv( response ); |
} catch ( e ) { |
return { |
state: "parsererror", |
error: conv ? e : "No conversion from " + prev + " to " + current |
}; |
return { state: "parsererror", error: conv ? e : "No conversion from " + prev + " to " + current }; |
} |
} |
} |
@@ -289,7 +273,7 @@ |
return { state: "success", data: response }; |
} |
|
jQuery.extend( { |
jQuery.extend({ |
|
// Counter for holding the number of active queries |
active: 0, |
@@ -299,14 +283,13 @@ |
etag: {}, |
|
ajaxSettings: { |
url: location.href, |
url: ajaxLocation, |
type: "GET", |
isLocal: rlocalProtocol.test( location.protocol ), |
isLocal: rlocalProtocol.test( ajaxLocParts[ 1 ] ), |
global: true, |
processData: true, |
async: true, |
contentType: "application/x-www-form-urlencoded; charset=UTF-8", |
|
/* |
timeout: 0, |
data: null, |
@@ -328,9 +311,9 @@ |
}, |
|
contents: { |
xml: /\bxml\b/, |
html: /\bhtml/, |
json: /\bjson\b/ |
xml: /xml/, |
html: /html/, |
json: /json/ |
}, |
|
responseFields: { |
@@ -350,7 +333,7 @@ |
"text html": true, |
|
// Evaluate text as a json expression |
"text json": JSON.parse, |
"text json": jQuery.parseJSON, |
|
// Parse text as xml |
"text xml": jQuery.parseXML |
@@ -395,58 +378,39 @@ |
options = options || {}; |
|
var transport, |
|
// URL without anti-cache param |
cacheURL, |
|
// Response headers |
responseHeadersString, |
responseHeaders, |
|
// timeout handle |
timeoutTimer, |
|
// Url cleanup var |
urlAnchor, |
|
// Request state (becomes false upon send and true upon completion) |
completed, |
|
// Cross-domain detection vars |
parts, |
// To know if global events are to be dispatched |
fireGlobals, |
|
// Loop variable |
i, |
|
// uncached part of the url |
uncached, |
|
// Create the final options object |
s = jQuery.ajaxSetup( {}, options ), |
|
// Callbacks context |
callbackContext = s.context || s, |
|
// Context for global events is callbackContext if it is a DOM node or jQuery collection |
globalEventContext = s.context && |
( callbackContext.nodeType || callbackContext.jquery ) ? |
jQuery( callbackContext ) : |
jQuery.event, |
|
globalEventContext = s.context && ( callbackContext.nodeType || callbackContext.jquery ) ? |
jQuery( callbackContext ) : |
jQuery.event, |
// Deferreds |
deferred = jQuery.Deferred(), |
completeDeferred = jQuery.Callbacks( "once memory" ), |
|
completeDeferred = jQuery.Callbacks("once memory"), |
// Status-dependent callbacks |
statusCode = s.statusCode || {}, |
|
// Headers (they are sent all at once) |
requestHeaders = {}, |
requestHeadersNames = {}, |
|
// The jqXHR state |
state = 0, |
// Default abort message |
strAbort = "canceled", |
|
// Fake xhr |
jqXHR = { |
readyState: 0, |
@@ -454,11 +418,11 @@ |
// Builds headers hashtable if needed |
getResponseHeader: function( key ) { |
var match; |
if ( completed ) { |
if ( state === 2 ) { |
if ( !responseHeaders ) { |
responseHeaders = {}; |
while ( ( match = rheaders.exec( responseHeadersString ) ) ) { |
responseHeaders[ match[ 1 ].toLowerCase() ] = match[ 2 ]; |
while ( (match = rheaders.exec( responseHeadersString )) ) { |
responseHeaders[ match[1].toLowerCase() ] = match[ 2 ]; |
} |
} |
match = responseHeaders[ key.toLowerCase() ]; |
@@ -468,14 +432,14 @@ |
|
// Raw string |
getAllResponseHeaders: function() { |
return completed ? responseHeadersString : null; |
return state === 2 ? responseHeadersString : null; |
}, |
|
// Caches the header |
setRequestHeader: function( name, value ) { |
if ( completed == null ) { |
name = requestHeadersNames[ name.toLowerCase() ] = |
requestHeadersNames[ name.toLowerCase() ] || name; |
var lname = name.toLowerCase(); |
if ( !state ) { |
name = requestHeadersNames[ lname ] = requestHeadersNames[ lname ] || name; |
requestHeaders[ name ] = value; |
} |
return this; |
@@ -483,7 +447,7 @@ |
|
// Overrides response content-type header |
overrideMimeType: function( type ) { |
if ( completed == null ) { |
if ( !state ) { |
s.mimeType = type; |
} |
return this; |
@@ -493,16 +457,14 @@ |
statusCode: function( map ) { |
var code; |
if ( map ) { |
if ( completed ) { |
|
// Execute the appropriate callbacks |
jqXHR.always( map[ jqXHR.status ] ); |
} else { |
|
// Lazy-add the new callbacks in a way that preserves old ones |
if ( state < 2 ) { |
for ( code in map ) { |
// Lazy-add the new callback in a way that preserves old ones |
statusCode[ code ] = [ statusCode[ code ], map[ code ] ]; |
} |
} else { |
// Execute the appropriate callbacks |
jqXHR.always( map[ jqXHR.status ] ); |
} |
} |
return this; |
@@ -520,41 +482,31 @@ |
}; |
|
// Attach deferreds |
deferred.promise( jqXHR ); |
deferred.promise( jqXHR ).complete = completeDeferred.add; |
jqXHR.success = jqXHR.done; |
jqXHR.error = jqXHR.fail; |
|
// Remove hash character (#7531: and string promotion) |
// Add protocol if not provided (prefilters might expect it) |
// Handle falsy url in the settings object (#10093: consistency with old signature) |
// We also use the url parameter if available |
s.url = ( ( url || s.url || location.href ) + "" ) |
.replace( rprotocol, location.protocol + "//" ); |
s.url = ( ( url || s.url || ajaxLocation ) + "" ).replace( rhash, "" ) |
.replace( rprotocol, ajaxLocParts[ 1 ] + "//" ); |
|
// Alias method option to type as per ticket #12004 |
s.type = options.method || options.type || s.method || s.type; |
|
// Extract dataTypes list |
s.dataTypes = ( s.dataType || "*" ).toLowerCase().match( rnothtmlwhite ) || [ "" ]; |
s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().match( rnotwhite ) || [ "" ]; |
|
// A cross-domain request is in order when the origin doesn't match the current origin. |
// A cross-domain request is in order when we have a protocol:host:port mismatch |
if ( s.crossDomain == null ) { |
urlAnchor = document.createElement( "a" ); |
|
// Support: IE <=8 - 11, Edge 12 - 13 |
// IE throws exception on accessing the href property if url is malformed, |
// e.g. http://example.com:80x/ |
try { |
urlAnchor.href = s.url; |
|
// Support: IE <=8 - 11 only |
// Anchor's host property isn't correctly set when s.url is relative |
urlAnchor.href = urlAnchor.href; |
s.crossDomain = originAnchor.protocol + "//" + originAnchor.host !== |
urlAnchor.protocol + "//" + urlAnchor.host; |
} catch ( e ) { |
|
// If there is an error parsing the URL, assume it is crossDomain, |
// it can be rejected by the transport if it is invalid |
s.crossDomain = true; |
} |
parts = rurl.exec( s.url.toLowerCase() ); |
s.crossDomain = !!( parts && |
( parts[ 1 ] !== ajaxLocParts[ 1 ] || parts[ 2 ] !== ajaxLocParts[ 2 ] || |
( parts[ 3 ] || ( parts[ 1 ] === "http:" ? "80" : "443" ) ) !== |
( ajaxLocParts[ 3 ] || ( ajaxLocParts[ 1 ] === "http:" ? "80" : "443" ) ) ) |
); |
} |
|
// Convert data if not already a string |
@@ -566,7 +518,7 @@ |
inspectPrefiltersOrTransports( prefilters, s, options, jqXHR ); |
|
// If request was aborted inside a prefilter, stop there |
if ( completed ) { |
if ( state === 2 ) { |
return jqXHR; |
} |
|
@@ -576,7 +528,7 @@ |
|
// Watch for a new set of requests |
if ( fireGlobals && jQuery.active++ === 0 ) { |
jQuery.event.trigger( "ajaxStart" ); |
jQuery.event.trigger("ajaxStart"); |
} |
|
// Uppercase the type |
@@ -587,36 +539,28 @@ |
|
// Save the URL in case we're toying with the If-Modified-Since |
// and/or If-None-Match header later on |
// Remove hash to simplify url manipulation |
cacheURL = s.url.replace( rhash, "" ); |
cacheURL = s.url; |
|
// More options handling for requests with no content |
if ( !s.hasContent ) { |
|
// Remember the hash so we can put it back |
uncached = s.url.slice( cacheURL.length ); |
|
// If data is available, append data to url |
if ( s.data ) { |
cacheURL += ( rquery.test( cacheURL ) ? "&" : "?" ) + s.data; |
|
cacheURL = ( s.url += ( rquery.test( cacheURL ) ? "&" : "?" ) + s.data ); |
// #9682: remove data so that it's not used in an eventual retry |
delete s.data; |
} |
|
// Add or update anti-cache param if needed |
// Add anti-cache in url if needed |
if ( s.cache === false ) { |
cacheURL = cacheURL.replace( rantiCache, "$1" ); |
uncached = ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + ( nonce++ ) + uncached; |
} |
s.url = rts.test( cacheURL ) ? |
|
// Put hash and anti-cache on the URL that will be requested (gh-1732) |
s.url = cacheURL + uncached; |
// If there is already a '_' parameter, set its value |
cacheURL.replace( rts, "$1_=" + nonce++ ) : |
|
// Change '%20' to '+' if this is encoded form body content (gh-2658) |
} else if ( s.data && s.processData && |
( s.contentType || "" ).indexOf( "application/x-www-form-urlencoded" ) === 0 ) { |
s.data = s.data.replace( r20, "+" ); |
// Otherwise add one to the end |
cacheURL + ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + nonce++; |
} |
} |
|
// Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode. |
@@ -637,9 +581,8 @@ |
// Set the Accepts header for the server, depending on the dataType |
jqXHR.setRequestHeader( |
"Accept", |
s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[ 0 ] ] ? |
s.accepts[ s.dataTypes[ 0 ] ] + |
( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) : |
s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[0] ] ? |
s.accepts[ s.dataTypes[0] ] + ( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) : |
s.accepts[ "*" ] |
); |
|
@@ -649,9 +592,7 @@ |
} |
|
// Allow custom headers/mimetypes and early abort |
if ( s.beforeSend && |
( s.beforeSend.call( callbackContext, jqXHR, s ) === false || completed ) ) { |
|
if ( s.beforeSend && ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) { |
// Abort if not done already and return |
return jqXHR.abort(); |
} |
@@ -660,9 +601,9 @@ |
strAbort = "abort"; |
|
// Install callbacks on deferreds |
completeDeferred.add( s.complete ); |
jqXHR.done( s.success ); |
jqXHR.fail( s.error ); |
for ( i in { success: 1, error: 1, complete: 1 } ) { |
jqXHR[ i ]( s[ i ] ); |
} |
|
// Get transport |
transport = inspectPrefiltersOrTransports( transports, s, options, jqXHR ); |
@@ -677,31 +618,24 @@ |
if ( fireGlobals ) { |
globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] ); |
} |
|
// If request was aborted inside ajaxSend, stop there |
if ( completed ) { |
return jqXHR; |
} |
|
// Timeout |
if ( s.async && s.timeout > 0 ) { |
timeoutTimer = window.setTimeout( function() { |
jqXHR.abort( "timeout" ); |
timeoutTimer = setTimeout(function() { |
jqXHR.abort("timeout"); |
}, s.timeout ); |
} |
|
try { |
completed = false; |
state = 1; |
transport.send( requestHeaders, done ); |
} catch ( e ) { |
|
// Rethrow post-completion exceptions |
if ( completed ) { |
// Propagate exception as error if not done |
if ( state < 2 ) { |
done( -1, e ); |
// Simply rethrow otherwise |
} else { |
throw e; |
} |
|
// Propagate others as results |
done( -1, e ); |
} |
} |
|
@@ -710,16 +644,17 @@ |
var isSuccess, success, error, response, modified, |
statusText = nativeStatusText; |
|
// Ignore repeat invocations |
if ( completed ) { |
// Called once |
if ( state === 2 ) { |
return; |
} |
|
completed = true; |
// State is "done" now |
state = 2; |
|
// Clear timeout if it exists |
if ( timeoutTimer ) { |
window.clearTimeout( timeoutTimer ); |
clearTimeout( timeoutTimer ); |
} |
|
// Dereference transport for early garbage collection |
@@ -748,11 +683,11 @@ |
|
// Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode. |
if ( s.ifModified ) { |
modified = jqXHR.getResponseHeader( "Last-Modified" ); |
modified = jqXHR.getResponseHeader("Last-Modified"); |
if ( modified ) { |
jQuery.lastModified[ cacheURL ] = modified; |
} |
modified = jqXHR.getResponseHeader( "etag" ); |
modified = jqXHR.getResponseHeader("etag"); |
if ( modified ) { |
jQuery.etag[ cacheURL ] = modified; |
} |
@@ -774,7 +709,6 @@ |
isSuccess = !error; |
} |
} else { |
|
// Extract error from statusText and normalize for non-aborts |
error = statusText; |
if ( status || !statusText ) { |
@@ -810,10 +744,9 @@ |
|
if ( fireGlobals ) { |
globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] ); |
|
// Handle the global AJAX counter |
if ( !( --jQuery.active ) ) { |
jQuery.event.trigger( "ajaxStop" ); |
jQuery.event.trigger("ajaxStop"); |
} |
} |
} |
@@ -828,11 +761,10 @@ |
getScript: function( url, callback ) { |
return jQuery.get( url, undefined, callback, "script" ); |
} |
} ); |
}); |
|
jQuery.each( [ "get", "post" ], function( i, method ) { |
jQuery[ method ] = function( url, data, callback, type ) { |
|
// Shift arguments if data argument was omitted |
if ( jQuery.isFunction( data ) ) { |
type = type || callback; |
@@ -840,16 +772,15 @@ |
data = undefined; |
} |
|
// The url can be an options object (which then must have .url) |
return jQuery.ajax( jQuery.extend( { |
return jQuery.ajax({ |
url: url, |
type: method, |
dataType: type, |
data: data, |
success: callback |
}, jQuery.isPlainObject( url ) && url ) ); |
}); |
}; |
} ); |
}); |
|
return jQuery; |
} ); |
}); |