Cleaning up trailing whitespace again.
This commit is contained in:
parent
ae6655bcb6
commit
e56de77df9
244
src/ajax.js
244
src/ajax.js
|
@ -1,5 +1,5 @@
|
||||||
(function( jQuery ) {
|
(function( jQuery ) {
|
||||||
|
|
||||||
var r20 = /%20/g,
|
var r20 = /%20/g,
|
||||||
rbracket = /\[\]$/,
|
rbracket = /\[\]$/,
|
||||||
rhash = /#.*$/,
|
rhash = /#.*$/,
|
||||||
|
@ -14,7 +14,7 @@ var r20 = /%20/g,
|
||||||
|
|
||||||
// Slice function
|
// Slice function
|
||||||
sliceFunc = Array.prototype.slice,
|
sliceFunc = Array.prototype.slice,
|
||||||
|
|
||||||
// Keep a copy of the old load method
|
// Keep a copy of the old load method
|
||||||
_load = jQuery.fn.load;
|
_load = jQuery.fn.load;
|
||||||
|
|
||||||
|
@ -227,26 +227,26 @@ jQuery.extend({
|
||||||
// Main method
|
// Main method
|
||||||
// (s is used internally)
|
// (s is used internally)
|
||||||
ajax: function( url , options , s ) {
|
ajax: function( url , options , s ) {
|
||||||
|
|
||||||
// Handle varargs
|
// Handle varargs
|
||||||
if ( arguments.length === 1 ) {
|
if ( arguments.length === 1 ) {
|
||||||
options = url;
|
options = url;
|
||||||
url = options ? options.url : undefined;
|
url = options ? options.url : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Force options to be an object
|
// Force options to be an object
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
// Get the url if provided separately
|
// Get the url if provided separately
|
||||||
options.url = url || options.url;
|
options.url = url || options.url;
|
||||||
|
|
||||||
// Create the final options object
|
// Create the final options object
|
||||||
s = jQuery.extend( true , {} , jQuery.ajaxSettings , options );
|
s = jQuery.extend( true , {} , jQuery.ajaxSettings , options );
|
||||||
|
|
||||||
// We force the original context
|
// We force the original context
|
||||||
// (plain objects used as context get extended)
|
// (plain objects used as context get extended)
|
||||||
s.context = options.context;
|
s.context = options.context;
|
||||||
|
|
||||||
var // jQuery lists
|
var // jQuery lists
|
||||||
jQuery_lastModified = jQuery.lastModified,
|
jQuery_lastModified = jQuery.lastModified,
|
||||||
jQuery_etag = jQuery.etag,
|
jQuery_etag = jQuery.etag,
|
||||||
|
@ -271,9 +271,9 @@ jQuery.extend({
|
||||||
i,
|
i,
|
||||||
// Fake xhr
|
// Fake xhr
|
||||||
jXHR = {
|
jXHR = {
|
||||||
|
|
||||||
readyState: 0,
|
readyState: 0,
|
||||||
|
|
||||||
// Caches the header
|
// Caches the header
|
||||||
setRequestHeader: function(name,value) {
|
setRequestHeader: function(name,value) {
|
||||||
if ( state === 0 ) {
|
if ( state === 0 ) {
|
||||||
|
@ -281,26 +281,26 @@ jQuery.extend({
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
// Raw string
|
// Raw string
|
||||||
getAllResponseHeaders: function() {
|
getAllResponseHeaders: function() {
|
||||||
return state === 2 ? responseHeadersString : null;
|
return state === 2 ? responseHeadersString : null;
|
||||||
},
|
},
|
||||||
|
|
||||||
// Builds headers hashtable if needed
|
// Builds headers hashtable if needed
|
||||||
// (match is used internally)
|
// (match is used internally)
|
||||||
getResponseHeader: function( key , match ) {
|
getResponseHeader: function( key , match ) {
|
||||||
|
|
||||||
if ( state !== 2 ) {
|
if ( state !== 2 ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( responseHeaders === undefined ) {
|
if ( responseHeaders === undefined ) {
|
||||||
|
|
||||||
responseHeaders = {};
|
responseHeaders = {};
|
||||||
|
|
||||||
if ( typeof responseHeadersString === "string" ) {
|
if ( typeof responseHeadersString === "string" ) {
|
||||||
|
|
||||||
while( ( match = rheaders.exec( responseHeadersString ) ) ) {
|
while( ( match = rheaders.exec( responseHeadersString ) ) ) {
|
||||||
responseHeaders[ match[ 1 ].toLowerCase() ] = match[ 2 ];
|
responseHeaders[ match[ 1 ].toLowerCase() ] = match[ 2 ];
|
||||||
}
|
}
|
||||||
|
@ -308,7 +308,7 @@ jQuery.extend({
|
||||||
}
|
}
|
||||||
return responseHeaders[ key.toLowerCase() ];
|
return responseHeaders[ key.toLowerCase() ];
|
||||||
},
|
},
|
||||||
|
|
||||||
// Cancel the request
|
// Cancel the request
|
||||||
abort: function( statusText ) {
|
abort: function( statusText ) {
|
||||||
if ( transport && state !== 2 ) {
|
if ( transport && state !== 2 ) {
|
||||||
|
@ -323,15 +323,15 @@ jQuery.extend({
|
||||||
// It is defined here because jslint complains if it is declared
|
// It is defined here because jslint complains if it is declared
|
||||||
// at the end of the function (which would be more logical and readable)
|
// at the end of the function (which would be more logical and readable)
|
||||||
function done( status , statusText , response , headers) {
|
function done( status , statusText , response , headers) {
|
||||||
|
|
||||||
// Called once
|
// Called once
|
||||||
if ( state === 2 ) {
|
if ( state === 2 ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// State is "done" now
|
// State is "done" now
|
||||||
state = 2;
|
state = 2;
|
||||||
|
|
||||||
// Set readyState
|
// Set readyState
|
||||||
jXHR.readyState = status ? 4 : 0;
|
jXHR.readyState = status ? 4 : 0;
|
||||||
|
|
||||||
|
@ -342,35 +342,35 @@ jQuery.extend({
|
||||||
if ( timeoutTimer ) {
|
if ( timeoutTimer ) {
|
||||||
clearTimeout(timeoutTimer);
|
clearTimeout(timeoutTimer);
|
||||||
}
|
}
|
||||||
|
|
||||||
var // Reference url
|
var // Reference url
|
||||||
url = s.url,
|
url = s.url,
|
||||||
// and ifModified status
|
// and ifModified status
|
||||||
ifModified = s.ifModified,
|
ifModified = s.ifModified,
|
||||||
|
|
||||||
// Is it a success?
|
// Is it a success?
|
||||||
isSuccess = 0,
|
isSuccess = 0,
|
||||||
// Stored success
|
// Stored success
|
||||||
success,
|
success,
|
||||||
// Stored error
|
// Stored error
|
||||||
error = statusText;
|
error = statusText;
|
||||||
|
|
||||||
// If not timeout, force a jQuery-compliant status text
|
// If not timeout, force a jQuery-compliant status text
|
||||||
if ( statusText != "timeout" ) {
|
if ( statusText != "timeout" ) {
|
||||||
statusText = ( status >= 200 && status < 300 ) ?
|
statusText = ( status >= 200 && status < 300 ) ?
|
||||||
"success" :
|
"success" :
|
||||||
( status === 304 ? "notmodified" : "error" );
|
( status === 304 ? "notmodified" : "error" );
|
||||||
}
|
}
|
||||||
|
|
||||||
// If successful, handle type chaining
|
// If successful, handle type chaining
|
||||||
if ( statusText === "success" || statusText === "notmodified" ) {
|
if ( statusText === "success" || statusText === "notmodified" ) {
|
||||||
|
|
||||||
// Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
|
// Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
|
||||||
if ( s.ifModified ) {
|
if ( s.ifModified ) {
|
||||||
|
|
||||||
var lastModified = jXHR.getResponseHeader("Last-Modified"),
|
var lastModified = jXHR.getResponseHeader("Last-Modified"),
|
||||||
etag = jXHR.getResponseHeader("Etag");
|
etag = jXHR.getResponseHeader("Etag");
|
||||||
|
|
||||||
if (lastModified) {
|
if (lastModified) {
|
||||||
jQuery_lastModified[ s.url ] = lastModified;
|
jQuery_lastModified[ s.url ] = lastModified;
|
||||||
}
|
}
|
||||||
|
@ -378,17 +378,17 @@ jQuery.extend({
|
||||||
jQuery_etag[ s.url ] = etag;
|
jQuery_etag[ s.url ] = etag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( s.ifModified && statusText === "notmodified" ) {
|
if ( s.ifModified && statusText === "notmodified" ) {
|
||||||
|
|
||||||
success = null;
|
success = null;
|
||||||
isSuccess = 1;
|
isSuccess = 1;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Chain data conversions and determine the final value
|
// Chain data conversions and determine the final value
|
||||||
// (if an exception is thrown in the process, it'll be notified as an error)
|
// (if an exception is thrown in the process, it'll be notified as an error)
|
||||||
try {
|
try {
|
||||||
|
|
||||||
var i,
|
var i,
|
||||||
current,
|
current,
|
||||||
prev,
|
prev,
|
||||||
|
@ -403,27 +403,27 @@ jQuery.extend({
|
||||||
"xml": "XML",
|
"xml": "XML",
|
||||||
"text": "Text"
|
"text": "Text"
|
||||||
};
|
};
|
||||||
|
|
||||||
for( i = 0 ; i < dataTypes.length ; i++ ) {
|
for( i = 0 ; i < dataTypes.length ; i++ ) {
|
||||||
|
|
||||||
current = dataTypes[ i ];
|
current = dataTypes[ i ];
|
||||||
|
|
||||||
if ( responses[ current ] ) {
|
if ( responses[ current ] ) {
|
||||||
jXHR[ "response" + responses[ current ] ] = response;
|
jXHR[ "response" + responses[ current ] ] = response;
|
||||||
responses[ current ] = 0;
|
responses[ current ] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( i ) {
|
if ( i ) {
|
||||||
|
|
||||||
prev = dataTypes[ i - 1 ];
|
prev = dataTypes[ i - 1 ];
|
||||||
|
|
||||||
if ( prev !== "*" && current !== "*" && prev !== current ) {
|
if ( prev !== "*" && current !== "*" && prev !== current ) {
|
||||||
|
|
||||||
conv = converters[ ( conversion = prev + " " + current ) ] ||
|
conv = converters[ ( conversion = prev + " " + current ) ] ||
|
||||||
converters[ "* " + current ];
|
converters[ "* " + current ];
|
||||||
|
|
||||||
conv1 = conv2 = 0;
|
conv1 = conv2 = 0;
|
||||||
|
|
||||||
if ( ! conv && prev !== "text" && current !== "text" ) {
|
if ( ! conv && prev !== "text" && current !== "text" ) {
|
||||||
conv1 = converters[ prev + " text" ] || converters[ "* text" ];
|
conv1 = converters[ prev + " text" ] || converters[ "* text" ];
|
||||||
conv2 = converters[ "text " + current ];
|
conv2 = converters[ "text " + current ];
|
||||||
|
@ -433,58 +433,58 @@ jQuery.extend({
|
||||||
conv = conv1;
|
conv = conv1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! ( conv || conv1 && conv2 ) ) {
|
if ( ! ( conv || conv1 && conv2 ) ) {
|
||||||
throw conversion;
|
throw conversion;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( conv !== true ) {
|
if ( conv !== true ) {
|
||||||
response = conv ? conv( response ) : conv2( conv1( response ) );
|
response = conv ? conv( response ) : conv2( conv1( response ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ( s.dataFilter ) {
|
} else if ( s.dataFilter ) {
|
||||||
|
|
||||||
response = s.dataFilter( response );
|
response = s.dataFilter( response );
|
||||||
dataTypes = s.dataTypes;
|
dataTypes = s.dataTypes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We have a real success
|
// We have a real success
|
||||||
success = response;
|
success = response;
|
||||||
isSuccess = 1;
|
isSuccess = 1;
|
||||||
|
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
|
|
||||||
statusText = "parsererror";
|
statusText = "parsererror";
|
||||||
error = "" + e;
|
error = "" + e;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else { // if not success, mark it as an error
|
} else { // if not success, mark it as an error
|
||||||
|
|
||||||
error = error || statusText;
|
error = error || statusText;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set data for the fake xhr object
|
// Set data for the fake xhr object
|
||||||
jXHR.status = status;
|
jXHR.status = status;
|
||||||
jXHR.statusText = statusText;
|
jXHR.statusText = statusText;
|
||||||
|
|
||||||
// Success/Error
|
// Success/Error
|
||||||
if ( isSuccess ) {
|
if ( isSuccess ) {
|
||||||
deferred.fire( callbackContext , [ success , statusText , jXHR ] );
|
deferred.fire( callbackContext , [ success , statusText , jXHR ] );
|
||||||
} else {
|
} else {
|
||||||
deferred.fireReject( callbackContext , [ jXHR , statusText , error ] );
|
deferred.fireReject( callbackContext , [ jXHR , statusText , error ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( s.global ) {
|
if ( s.global ) {
|
||||||
globalEventContext.trigger( "ajax" + ( isSuccess ? "Success" : "Error" ) ,
|
globalEventContext.trigger( "ajax" + ( isSuccess ? "Success" : "Error" ) ,
|
||||||
[ jXHR , s , isSuccess ? success : error ] );
|
[ jXHR , s , isSuccess ? success : error ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Complete
|
// Complete
|
||||||
completeDeferred.fire( callbackContext, [ jXHR , statusText ] );
|
completeDeferred.fire( callbackContext, [ jXHR , statusText ] );
|
||||||
|
|
||||||
if ( s.global ) {
|
if ( s.global ) {
|
||||||
globalEventContext.trigger( "ajaxComplete" , [ jXHR , s] );
|
globalEventContext.trigger( "ajaxComplete" , [ jXHR , s] );
|
||||||
// Handle the global AJAX counter
|
// Handle the global AJAX counter
|
||||||
|
@ -493,7 +493,7 @@ jQuery.extend({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attach deferreds
|
// Attach deferreds
|
||||||
deferred.promise( jXHR );
|
deferred.promise( jXHR );
|
||||||
jXHR.success = jXHR.complete;
|
jXHR.success = jXHR.complete;
|
||||||
|
@ -502,16 +502,16 @@ jQuery.extend({
|
||||||
|
|
||||||
// Remove hash character (#7531: and string promotion)
|
// Remove hash character (#7531: and string promotion)
|
||||||
s.url = ( "" + s.url ).replace( rhash , "" );
|
s.url = ( "" + s.url ).replace( rhash , "" );
|
||||||
|
|
||||||
// Uppercase the type
|
// Uppercase the type
|
||||||
s.type = s.type.toUpperCase();
|
s.type = s.type.toUpperCase();
|
||||||
|
|
||||||
// Determine if request has content
|
// Determine if request has content
|
||||||
s.hasContent = ! rnoContent.test( s.type );
|
s.hasContent = ! rnoContent.test( s.type );
|
||||||
|
|
||||||
// Extract dataTypes list
|
// Extract dataTypes list
|
||||||
s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().split( /\s+/ );
|
s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().split( /\s+/ );
|
||||||
|
|
||||||
// Determine if a cross-domain request is in order
|
// Determine if a cross-domain request is in order
|
||||||
var parts = rurl.exec( s.url.toLowerCase() ),
|
var parts = rurl.exec( s.url.toLowerCase() ),
|
||||||
loc = location;
|
loc = location;
|
||||||
|
@ -526,93 +526,93 @@ jQuery.extend({
|
||||||
if ( s.global && jQuery.active++ === 0 ) {
|
if ( s.global && jQuery.active++ === 0 ) {
|
||||||
jQuery.event.trigger( "ajaxStart" );
|
jQuery.event.trigger( "ajaxStart" );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get transport
|
// Get transport
|
||||||
transport = jQuery.ajax.prefilter( s ).transport( s );
|
transport = jQuery.ajax.prefilter( s ).transport( s );
|
||||||
|
|
||||||
// If no transport, we auto-abort
|
// If no transport, we auto-abort
|
||||||
if ( ! transport ) {
|
if ( ! transport ) {
|
||||||
|
|
||||||
done( 0 , "transport not found" );
|
done( 0 , "transport not found" );
|
||||||
jXHR = false;
|
jXHR = false;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// More options handling for requests with no content
|
// More options handling for requests with no content
|
||||||
if ( ! s.hasContent ) {
|
if ( ! s.hasContent ) {
|
||||||
|
|
||||||
// If data is available, append data to url
|
// If data is available, append data to url
|
||||||
if ( s.data ) {
|
if ( s.data ) {
|
||||||
s.url += ( rquery.test( s.url ) ? "&" : "?" ) + s.data;
|
s.url += ( rquery.test( s.url ) ? "&" : "?" ) + s.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add anti-cache in url if needed
|
// Add anti-cache in url if needed
|
||||||
if ( s.cache === false ) {
|
if ( s.cache === false ) {
|
||||||
|
|
||||||
var ts = jQuery.now(),
|
var ts = jQuery.now(),
|
||||||
// try replacing _= if it is there
|
// try replacing _= if it is there
|
||||||
ret = s.url.replace( rts , "$1_=" + ts );
|
ret = s.url.replace( rts , "$1_=" + ts );
|
||||||
|
|
||||||
// if nothing was replaced, add timestamp to the end
|
// if nothing was replaced, add timestamp to the end
|
||||||
s.url = ret + ( (ret == s.url ) ? ( rquery.test( s.url ) ? "&" : "?" ) + "_=" + ts : "");
|
s.url = ret + ( (ret == s.url ) ? ( rquery.test( s.url ) ? "&" : "?" ) + "_=" + ts : "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the correct header, if data is being sent
|
// Set the correct header, if data is being sent
|
||||||
if ( ( s.data && s.hasContent ) || options.contentType ) {
|
if ( ( s.data && s.hasContent ) || options.contentType ) {
|
||||||
requestHeaders[ "content-type" ] = s.contentType;
|
requestHeaders[ "content-type" ] = s.contentType;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
|
// Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
|
||||||
if ( s.ifModified ) {
|
if ( s.ifModified ) {
|
||||||
if ( jQuery_lastModified[ s.url ] ) {
|
if ( jQuery_lastModified[ s.url ] ) {
|
||||||
requestHeaders[ "if-modified-since" ] = jQuery_lastModified[ s.url ];
|
requestHeaders[ "if-modified-since" ] = jQuery_lastModified[ s.url ];
|
||||||
}
|
}
|
||||||
if ( jQuery_etag[ s.url ] ) {
|
if ( jQuery_etag[ s.url ] ) {
|
||||||
requestHeaders[ "if-none-match" ] = jQuery_etag[ s.url ];
|
requestHeaders[ "if-none-match" ] = jQuery_etag[ s.url ];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the Accepts header for the server, depending on the dataType
|
// Set the Accepts header for the server, depending on the dataType
|
||||||
requestHeaders.accept = s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[ 0 ] ] ?
|
requestHeaders.accept = s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[ 0 ] ] ?
|
||||||
s.accepts[ s.dataTypes[ 0 ] ] + ( s.dataTypes[ 0 ] !== "*" ? ", */*; q=0.01" : "" ) :
|
s.accepts[ s.dataTypes[ 0 ] ] + ( s.dataTypes[ 0 ] !== "*" ? ", */*; q=0.01" : "" ) :
|
||||||
s.accepts[ "*" ];
|
s.accepts[ "*" ];
|
||||||
|
|
||||||
// Check for headers option
|
// Check for headers option
|
||||||
for ( i in s.headers ) {
|
for ( i in s.headers ) {
|
||||||
requestHeaders[ i.toLowerCase() ] = s.headers[ i ];
|
requestHeaders[ i.toLowerCase() ] = s.headers[ i ];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow custom headers/mimetypes and early abort
|
// Allow custom headers/mimetypes and early abort
|
||||||
if ( s.beforeSend && ( s.beforeSend.call( callbackContext , jXHR , s ) === false || state === 2 ) ) {
|
if ( s.beforeSend && ( s.beforeSend.call( callbackContext , jXHR , s ) === false || state === 2 ) ) {
|
||||||
|
|
||||||
// Abort if not done already
|
// Abort if not done already
|
||||||
done( 0 , "abort" );
|
done( 0 , "abort" );
|
||||||
jXHR = false;
|
jXHR = false;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// Set state as sending
|
// Set state as sending
|
||||||
state = 1;
|
state = 1;
|
||||||
jXHR.readyState = 1;
|
jXHR.readyState = 1;
|
||||||
|
|
||||||
// Install callbacks on deferreds
|
// Install callbacks on deferreds
|
||||||
for ( i in { success:1, error:1, complete:1 } ) {
|
for ( i in { success:1, error:1, complete:1 } ) {
|
||||||
jXHR[ i ]( s[ i ] );
|
jXHR[ i ]( s[ i ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send global event
|
// Send global event
|
||||||
if ( s.global ) {
|
if ( s.global ) {
|
||||||
globalEventContext.trigger( "ajaxSend" , [ jXHR , s ] );
|
globalEventContext.trigger( "ajaxSend" , [ jXHR , s ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Timeout
|
// Timeout
|
||||||
if ( s.async && s.timeout > 0 ) {
|
if ( s.async && s.timeout > 0 ) {
|
||||||
timeoutTimer = setTimeout(function(){
|
timeoutTimer = setTimeout(function(){
|
||||||
jXHR.abort( "timeout" );
|
jXHR.abort( "timeout" );
|
||||||
}, s.timeout);
|
}, s.timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to send
|
// Try to send
|
||||||
try {
|
try {
|
||||||
transport.send(requestHeaders, done);
|
transport.send(requestHeaders, done);
|
||||||
|
@ -622,7 +622,7 @@ jQuery.extend({
|
||||||
|
|
||||||
done(0, "error", "" + e);
|
done(0, "error", "" + e);
|
||||||
jXHR = false;
|
jXHR = false;
|
||||||
|
|
||||||
// Simply rethrow otherwise
|
// Simply rethrow otherwise
|
||||||
} else {
|
} else {
|
||||||
jQuery.error(e);
|
jQuery.error(e);
|
||||||
|
@ -630,7 +630,7 @@ jQuery.extend({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return jXHR;
|
return jXHR;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -733,13 +733,13 @@ function ajax_selectOrExecute( structure , s ) {
|
||||||
checked = {},
|
checked = {},
|
||||||
flag,
|
flag,
|
||||||
noSelect = structure !== "transports";
|
noSelect = structure !== "transports";
|
||||||
|
|
||||||
function initSearch( dataType ) {
|
function initSearch( dataType ) {
|
||||||
|
|
||||||
flag = transportDataType !== dataType && ! checked[ dataType ];
|
flag = transportDataType !== dataType && ! checked[ dataType ];
|
||||||
|
|
||||||
if ( flag ) {
|
if ( flag ) {
|
||||||
|
|
||||||
checked[ dataType ] = 1;
|
checked[ dataType ] = 1;
|
||||||
transportDataType = dataType;
|
transportDataType = dataType;
|
||||||
list = s[ structure ][ dataType ];
|
list = s[ structure ][ dataType ];
|
||||||
|
@ -749,15 +749,15 @@ function ajax_selectOrExecute( structure , s ) {
|
||||||
|
|
||||||
return flag;
|
return flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
initSearch( dataTypes[ 0 ] );
|
initSearch( dataTypes[ 0 ] );
|
||||||
|
|
||||||
for ( i = 0 ; ( noSelect || ! selected ) && i <= length ; i++ ) {
|
for ( i = 0 ; ( noSelect || ! selected ) && i <= length ; i++ ) {
|
||||||
|
|
||||||
if ( i === length ) {
|
if ( i === length ) {
|
||||||
|
|
||||||
initSearch( "*" );
|
initSearch( "*" );
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
selected = list[ i ]( s , determineDataType );
|
selected = list[ i ]( s , determineDataType );
|
||||||
|
@ -778,7 +778,7 @@ function ajax_selectOrExecute( structure , s ) {
|
||||||
|
|
||||||
// Add an element to one of the structures in ajaxSettings
|
// Add an element to one of the structures in ajaxSettings
|
||||||
function ajax_addElement( structure , args ) {
|
function ajax_addElement( structure , args ) {
|
||||||
|
|
||||||
var i,
|
var i,
|
||||||
start = 0,
|
start = 0,
|
||||||
length = args.length,
|
length = args.length,
|
||||||
|
@ -789,41 +789,41 @@ function ajax_addElement( structure , args ) {
|
||||||
first,
|
first,
|
||||||
append,
|
append,
|
||||||
list;
|
list;
|
||||||
|
|
||||||
if ( length ) {
|
if ( length ) {
|
||||||
|
|
||||||
first = jQuery.type( args[ 0 ] );
|
first = jQuery.type( args[ 0 ] );
|
||||||
|
|
||||||
if ( first === "object" ) {
|
if ( first === "object" ) {
|
||||||
return ajax_selectOrExecute( structure , args[ 0 ] );
|
return ajax_selectOrExecute( structure , args[ 0 ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
structure = jQuery.ajaxSettings[ structure ];
|
structure = jQuery.ajaxSettings[ structure ];
|
||||||
|
|
||||||
if ( first !== "function" ) {
|
if ( first !== "function" ) {
|
||||||
|
|
||||||
dataTypes = args[ 0 ].toLowerCase().split(/\s+/);
|
dataTypes = args[ 0 ].toLowerCase().split(/\s+/);
|
||||||
dLength = dataTypes.length;
|
dLength = dataTypes.length;
|
||||||
start = 1;
|
start = 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( dLength && start < length ) {
|
if ( dLength && start < length ) {
|
||||||
|
|
||||||
functors = sliceFunc.call( args , start );
|
functors = sliceFunc.call( args , start );
|
||||||
|
|
||||||
for( i = 0 ; i < dLength ; i++ ) {
|
for( i = 0 ; i < dLength ; i++ ) {
|
||||||
|
|
||||||
dataType = dataTypes[ i ];
|
dataType = dataTypes[ i ];
|
||||||
|
|
||||||
first = /^\+/.test( dataType );
|
first = /^\+/.test( dataType );
|
||||||
|
|
||||||
if (first) {
|
if (first) {
|
||||||
dataType = dataType.substr(1);
|
dataType = dataType.substr(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( dataType !== "" ) {
|
if ( dataType !== "" ) {
|
||||||
|
|
||||||
append = Array.prototype[ first ? "unshift" : "push" ];
|
append = Array.prototype[ first ? "unshift" : "push" ];
|
||||||
list = structure[ dataType ] = structure[ dataType ] || [];
|
list = structure[ dataType ] = structure[ dataType ] || [];
|
||||||
append.apply( list , functors );
|
append.apply( list , functors );
|
||||||
|
@ -831,7 +831,7 @@ function ajax_addElement( structure , args ) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return jQuery.ajax;
|
return jQuery.ajax;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -842,18 +842,18 @@ jQuery.each( [ "prefilter" , "transport" ] , function( _ , name ) {
|
||||||
return ajax_addElement( _ , arguments );
|
return ajax_addElement( _ , arguments );
|
||||||
};
|
};
|
||||||
} );
|
} );
|
||||||
|
|
||||||
// Utility function that handles dataType when response is received
|
// Utility function that handles dataType when response is received
|
||||||
// (for those transports that can give text or xml responses)
|
// (for those transports that can give text or xml responses)
|
||||||
function determineDataType( s , ct , text , xml ) {
|
function determineDataType( s , ct , text , xml ) {
|
||||||
|
|
||||||
var contents = s.contents,
|
var contents = s.contents,
|
||||||
type,
|
type,
|
||||||
regexp,
|
regexp,
|
||||||
dataTypes = s.dataTypes,
|
dataTypes = s.dataTypes,
|
||||||
transportDataType = dataTypes[0],
|
transportDataType = dataTypes[0],
|
||||||
response;
|
response;
|
||||||
|
|
||||||
// Auto (xml, json, script or text determined given headers)
|
// Auto (xml, json, script or text determined given headers)
|
||||||
if ( transportDataType === "*" ) {
|
if ( transportDataType === "*" ) {
|
||||||
|
|
||||||
|
@ -862,30 +862,30 @@ function determineDataType( s , ct , text , xml ) {
|
||||||
transportDataType = dataTypes[0] = type;
|
transportDataType = dataTypes[0] = type;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// xml and parsed as such
|
// xml and parsed as such
|
||||||
if ( transportDataType === "xml" &&
|
if ( transportDataType === "xml" &&
|
||||||
xml &&
|
xml &&
|
||||||
xml.documentElement /* #4958 */ ) {
|
xml.documentElement /* #4958 */ ) {
|
||||||
|
|
||||||
response = xml;
|
response = xml;
|
||||||
|
|
||||||
// Text response was provided
|
// Text response was provided
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
response = text;
|
response = text;
|
||||||
|
|
||||||
// If it's not really text, defer to converters
|
// If it's not really text, defer to converters
|
||||||
if ( transportDataType !== "text" ) {
|
if ( transportDataType !== "text" ) {
|
||||||
dataTypes.unshift( "text" );
|
dataTypes.unshift( "text" );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create the request object; Microsoft failed to properly
|
* Create the request object; Microsoft failed to properly
|
||||||
|
|
64
src/core.js
64
src/core.js
|
@ -59,7 +59,7 @@ var jQuery = function( selector, context ) {
|
||||||
|
|
||||||
// Has the ready events already been bound?
|
// Has the ready events already been bound?
|
||||||
readyBound = false,
|
readyBound = false,
|
||||||
|
|
||||||
// The deferred used on DOM ready
|
// The deferred used on DOM ready
|
||||||
readyList,
|
readyList,
|
||||||
|
|
||||||
|
@ -252,11 +252,11 @@ jQuery.fn = jQuery.prototype = {
|
||||||
each: function( callback, args ) {
|
each: function( callback, args ) {
|
||||||
return jQuery.each( this, callback, args );
|
return jQuery.each( this, callback, args );
|
||||||
},
|
},
|
||||||
|
|
||||||
ready: function() {
|
ready: function() {
|
||||||
// Attach the listeners
|
// Attach the listeners
|
||||||
jQuery.bindReady();
|
jQuery.bindReady();
|
||||||
|
|
||||||
// Change ready & apply
|
// Change ready & apply
|
||||||
return ( jQuery.fn.ready = readyList.complete ).apply( this , arguments );
|
return ( jQuery.fn.ready = readyList.complete ).apply( this , arguments );
|
||||||
},
|
},
|
||||||
|
@ -406,7 +406,7 @@ jQuery.extend({
|
||||||
|
|
||||||
// If there are functions bound, to execute
|
// If there are functions bound, to execute
|
||||||
readyList.fire( document , [ jQuery ] );
|
readyList.fire( document , [ jQuery ] );
|
||||||
|
|
||||||
// Trigger any bound ready events
|
// Trigger any bound ready events
|
||||||
if ( jQuery.fn.trigger ) {
|
if ( jQuery.fn.trigger ) {
|
||||||
jQuery( document ).trigger( "ready" ).unbind( "ready" );
|
jQuery( document ).trigger( "ready" ).unbind( "ready" );
|
||||||
|
@ -543,7 +543,7 @@ jQuery.extend({
|
||||||
jQuery.error( "Invalid JSON: " + data );
|
jQuery.error( "Invalid JSON: " + data );
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// Cross-browser xml parsing
|
// Cross-browser xml parsing
|
||||||
// (xml & tmp used internally)
|
// (xml & tmp used internally)
|
||||||
parseXML: function( data , xml , tmp ) {
|
parseXML: function( data , xml , tmp ) {
|
||||||
|
@ -556,13 +556,13 @@ jQuery.extend({
|
||||||
xml.async = "false";
|
xml.async = "false";
|
||||||
xml.loadXML( data );
|
xml.loadXML( data );
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp = xml.documentElement;
|
tmp = xml.documentElement;
|
||||||
|
|
||||||
if ( ! tmp || ! tmp.nodeName || tmp.nodeName === "parsererror" ) {
|
if ( ! tmp || ! tmp.nodeName || tmp.nodeName === "parsererror" ) {
|
||||||
jQuery.error( "Invalid XML: " + data );
|
jQuery.error( "Invalid XML: " + data );
|
||||||
}
|
}
|
||||||
|
|
||||||
return xml;
|
return xml;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -800,10 +800,10 @@ jQuery.extend({
|
||||||
now: function() {
|
now: function() {
|
||||||
return (new Date()).getTime();
|
return (new Date()).getTime();
|
||||||
},
|
},
|
||||||
|
|
||||||
// Create a simple deferred (one callbacks list)
|
// Create a simple deferred (one callbacks list)
|
||||||
_Deferred: function() {
|
_Deferred: function() {
|
||||||
|
|
||||||
var // callbacks list
|
var // callbacks list
|
||||||
callbacks = [],
|
callbacks = [],
|
||||||
// stored [ context , args ]
|
// stored [ context , args ]
|
||||||
|
@ -814,24 +814,24 @@ jQuery.extend({
|
||||||
cancelled,
|
cancelled,
|
||||||
// the deferred itself
|
// the deferred itself
|
||||||
deferred = {
|
deferred = {
|
||||||
|
|
||||||
// complete( f1, f2, ...)
|
// complete( f1, f2, ...)
|
||||||
complete: function () {
|
complete: function () {
|
||||||
|
|
||||||
if ( ! cancelled ) {
|
if ( ! cancelled ) {
|
||||||
|
|
||||||
var args = arguments,
|
var args = arguments,
|
||||||
i,
|
i,
|
||||||
length,
|
length,
|
||||||
elem,
|
elem,
|
||||||
type,
|
type,
|
||||||
_fired;
|
_fired;
|
||||||
|
|
||||||
if ( fired ) {
|
if ( fired ) {
|
||||||
_fired = fired;
|
_fired = fired;
|
||||||
fired = 0;
|
fired = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( i = 0, length = args.length ; i < length ; i++ ) {
|
for ( i = 0, length = args.length ; i < length ; i++ ) {
|
||||||
elem = args[ i ];
|
elem = args[ i ];
|
||||||
type = jQuery.type( elem );
|
type = jQuery.type( elem );
|
||||||
|
@ -841,21 +841,21 @@ jQuery.extend({
|
||||||
callbacks.push( elem );
|
callbacks.push( elem );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( _fired ) {
|
if ( _fired ) {
|
||||||
deferred.fire( _fired[ 0 ] , _fired[ 1 ] );
|
deferred.fire( _fired[ 0 ] , _fired[ 1 ] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
// resolve with given context and args
|
// resolve with given context and args
|
||||||
fire: function( context , args ) {
|
fire: function( context , args ) {
|
||||||
if ( ! cancelled && ! fired && ! firing ) {
|
if ( ! cancelled && ! fired && ! firing ) {
|
||||||
|
|
||||||
firing = 1;
|
firing = 1;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
while( callbacks[ 0 ] ) {
|
while( callbacks[ 0 ] ) {
|
||||||
callbacks.shift().apply( context , args );
|
callbacks.shift().apply( context , args );
|
||||||
|
@ -868,18 +868,18 @@ jQuery.extend({
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
// resolve with this as context and given arguments
|
// resolve with this as context and given arguments
|
||||||
resolve: function() {
|
resolve: function() {
|
||||||
deferred.fire( jQuery.isFunction( this.promise ) ? this.promise() : this , arguments );
|
deferred.fire( jQuery.isFunction( this.promise ) ? this.promise() : this , arguments );
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
// Has this deferred been resolved?
|
// Has this deferred been resolved?
|
||||||
isResolved: function() {
|
isResolved: function() {
|
||||||
return !!( firing || fired );
|
return !!( firing || fired );
|
||||||
},
|
},
|
||||||
|
|
||||||
// Cancel
|
// Cancel
|
||||||
cancel: function() {
|
cancel: function() {
|
||||||
cancelled = 1;
|
cancelled = 1;
|
||||||
|
@ -887,18 +887,18 @@ jQuery.extend({
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return deferred;
|
return deferred;
|
||||||
},
|
},
|
||||||
|
|
||||||
// Full fledged deferred (two callbacks list)
|
// Full fledged deferred (two callbacks list)
|
||||||
// Typical success/error system
|
// Typical success/error system
|
||||||
Deferred: function( func ) {
|
Deferred: function( func ) {
|
||||||
|
|
||||||
var deferred = jQuery._Deferred(),
|
var deferred = jQuery._Deferred(),
|
||||||
failDeferred = jQuery._Deferred();
|
failDeferred = jQuery._Deferred();
|
||||||
|
|
||||||
// Add errorDeferred methods and redefine cancel
|
// Add errorDeferred methods and redefine cancel
|
||||||
jQuery.extend( deferred , {
|
jQuery.extend( deferred , {
|
||||||
|
|
||||||
then: function( completeCallbacks , failCallbacks ) {
|
then: function( completeCallbacks , failCallbacks ) {
|
||||||
|
@ -923,18 +923,18 @@ jQuery.extend({
|
||||||
}
|
}
|
||||||
|
|
||||||
} );
|
} );
|
||||||
|
|
||||||
// Make sure only one callback list will be used
|
// Make sure only one callback list will be used
|
||||||
deferred.then( failDeferred.cancel , deferred.cancel );
|
deferred.then( failDeferred.cancel , deferred.cancel );
|
||||||
|
|
||||||
// Unexpose cancel
|
// Unexpose cancel
|
||||||
delete deferred.cancel;
|
delete deferred.cancel;
|
||||||
|
|
||||||
// Call given func if any
|
// Call given func if any
|
||||||
if ( func ) {
|
if ( func ) {
|
||||||
func.call( deferred , deferred );
|
func.call( deferred , deferred );
|
||||||
}
|
}
|
||||||
|
|
||||||
return deferred;
|
return deferred;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -15,11 +15,11 @@ jQuery.ajaxSettings.jsonpCallback = function() {
|
||||||
// 3) ensure options jsonp is always provided so that jsonp requests are always
|
// 3) ensure options jsonp is always provided so that jsonp requests are always
|
||||||
// json request with the jsonp option set
|
// json request with the jsonp option set
|
||||||
jQuery.ajax.prefilter("json jsonp", function(s) {
|
jQuery.ajax.prefilter("json jsonp", function(s) {
|
||||||
|
|
||||||
var transportDataType = s.dataTypes[ 0 ];
|
var transportDataType = s.dataTypes[ 0 ];
|
||||||
|
|
||||||
s.dataTypes[ 0 ] = "json";
|
s.dataTypes[ 0 ] = "json";
|
||||||
|
|
||||||
if ( s.jsonp ||
|
if ( s.jsonp ||
|
||||||
transportDataType === "jsonp" ||
|
transportDataType === "jsonp" ||
|
||||||
transportDataType === "json" && ( jsre.test(s.url) || typeof(s.data) === "string" && jsre.test(s.data) ) ) {
|
transportDataType === "json" && ( jsre.test(s.url) || typeof(s.data) === "string" && jsre.test(s.data) ) ) {
|
||||||
|
@ -29,34 +29,34 @@ jQuery.ajax.prefilter("json jsonp", function(s) {
|
||||||
jQuery.isFunction( s.jsonpCallback ) ? s.jsonpCallback() : s.jsonpCallback,
|
jQuery.isFunction( s.jsonpCallback ) ? s.jsonpCallback() : s.jsonpCallback,
|
||||||
url = s.url.replace(jsre, "=" + jsonpCallback + "$1"),
|
url = s.url.replace(jsre, "=" + jsonpCallback + "$1"),
|
||||||
data = s.url == url && typeof(s.data) === "string" ? s.data.replace(jsre, "=" + jsonpCallback + "$1") : s.data;
|
data = s.url == url && typeof(s.data) === "string" ? s.data.replace(jsre, "=" + jsonpCallback + "$1") : s.data;
|
||||||
|
|
||||||
if ( url == s.url && data == s.data ) {
|
if ( url == s.url && data == s.data ) {
|
||||||
url = url += (rquery_jsonp.test( url ) ? "&" : "?") + jsonp + "=" + jsonpCallback;
|
url = url += (rquery_jsonp.test( url ) ? "&" : "?") + jsonp + "=" + jsonpCallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
s.url = url;
|
s.url = url;
|
||||||
s.data = data;
|
s.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bind transport to json dataType
|
// Bind transport to json dataType
|
||||||
}).transport("json", function(s) {
|
}).transport("json", function(s) {
|
||||||
|
|
||||||
if ( s.jsonp ) {
|
if ( s.jsonp ) {
|
||||||
|
|
||||||
// Put callback in place
|
// Put callback in place
|
||||||
var responseContainer,
|
var responseContainer,
|
||||||
jsonpCallback = s.jsonpCallback,
|
jsonpCallback = s.jsonpCallback,
|
||||||
previous = window[ jsonpCallback ];
|
previous = window[ jsonpCallback ];
|
||||||
|
|
||||||
window [ jsonpCallback ] = function( response ) {
|
window [ jsonpCallback ] = function( response ) {
|
||||||
responseContainer = [response];
|
responseContainer = [response];
|
||||||
};
|
};
|
||||||
|
|
||||||
s.complete = [function() {
|
s.complete = [function() {
|
||||||
|
|
||||||
// Set callback back to previous value
|
// Set callback back to previous value
|
||||||
window[ jsonpCallback ] = previous;
|
window[ jsonpCallback ] = previous;
|
||||||
|
|
||||||
// Call if it was a function and we have a response
|
// Call if it was a function and we have a response
|
||||||
if ( previous) {
|
if ( previous) {
|
||||||
if ( responseContainer && jQuery.isFunction ( previous ) ) {
|
if ( responseContainer && jQuery.isFunction ( previous ) ) {
|
||||||
|
@ -66,9 +66,9 @@ jQuery.ajax.prefilter("json jsonp", function(s) {
|
||||||
// else, more memory leak avoidance
|
// else, more memory leak avoidance
|
||||||
try{ delete window[ jsonpCallback ]; } catch(e){}
|
try{ delete window[ jsonpCallback ]; } catch(e){}
|
||||||
}
|
}
|
||||||
|
|
||||||
}, s.complete ];
|
}, s.complete ];
|
||||||
|
|
||||||
// Use data converter to retrieve json after script execution
|
// Use data converter to retrieve json after script execution
|
||||||
s.converters["script json"] = function() {
|
s.converters["script json"] = function() {
|
||||||
if ( ! responseContainer ) {
|
if ( ! responseContainer ) {
|
||||||
|
@ -76,7 +76,7 @@ jQuery.ajax.prefilter("json jsonp", function(s) {
|
||||||
}
|
}
|
||||||
return responseContainer[ 0 ];
|
return responseContainer[ 0 ];
|
||||||
};
|
};
|
||||||
|
|
||||||
// Delegate to script transport
|
// Delegate to script transport
|
||||||
return "script";
|
return "script";
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,11 +6,11 @@ jQuery.extend( true, jQuery.ajaxSettings , {
|
||||||
accepts: {
|
accepts: {
|
||||||
script: "text/javascript, application/javascript"
|
script: "text/javascript, application/javascript"
|
||||||
},
|
},
|
||||||
|
|
||||||
contents: {
|
contents: {
|
||||||
script: /javascript/
|
script: /javascript/
|
||||||
},
|
},
|
||||||
|
|
||||||
converters: {
|
converters: {
|
||||||
"text script": jQuery.globalEval
|
"text script": jQuery.globalEval
|
||||||
}
|
}
|
||||||
|
@ -18,22 +18,22 @@ jQuery.extend( true, jQuery.ajaxSettings , {
|
||||||
|
|
||||||
// Bind script tag hack transport
|
// Bind script tag hack transport
|
||||||
jQuery.ajax.transport("script", function(s) {
|
jQuery.ajax.transport("script", function(s) {
|
||||||
|
|
||||||
// Handle cache special case
|
// Handle cache special case
|
||||||
if ( s.cache === undefined ) {
|
if ( s.cache === undefined ) {
|
||||||
s.cache = false;
|
s.cache = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This transport only deals with cross domain get requests
|
// This transport only deals with cross domain get requests
|
||||||
if ( s.crossDomain && s.async && ( s.type === "GET" || ! s.data ) ) {
|
if ( s.crossDomain && s.async && ( s.type === "GET" || ! s.data ) ) {
|
||||||
|
|
||||||
s.global = false;
|
s.global = false;
|
||||||
|
|
||||||
var script,
|
var script,
|
||||||
head = document.getElementsByTagName("head")[0] || document.documentElement;
|
head = document.getElementsByTagName("head")[0] || document.documentElement;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
||||||
send: function(_, callback) {
|
send: function(_, callback) {
|
||||||
|
|
||||||
script = document.createElement("script");
|
script = document.createElement("script");
|
||||||
|
@ -43,24 +43,24 @@ jQuery.ajax.transport("script", function(s) {
|
||||||
if ( s.scriptCharset ) {
|
if ( s.scriptCharset ) {
|
||||||
script.charset = s.scriptCharset;
|
script.charset = s.scriptCharset;
|
||||||
}
|
}
|
||||||
|
|
||||||
script.src = s.url;
|
script.src = s.url;
|
||||||
|
|
||||||
// Attach handlers for all browsers
|
// Attach handlers for all browsers
|
||||||
script.onload = script.onreadystatechange = function( _ , statusText) {
|
script.onload = script.onreadystatechange = function( _ , statusText) {
|
||||||
|
|
||||||
if ( ! script.readyState || /loaded|complete/.test( script.readyState ) ) {
|
if ( ! script.readyState || /loaded|complete/.test( script.readyState ) ) {
|
||||||
|
|
||||||
// Handle memory leak in IE
|
// Handle memory leak in IE
|
||||||
script.onload = script.onreadystatechange = null;
|
script.onload = script.onreadystatechange = null;
|
||||||
|
|
||||||
// Remove the script
|
// Remove the script
|
||||||
if ( head && script.parentNode ) {
|
if ( head && script.parentNode ) {
|
||||||
head.removeChild( script );
|
head.removeChild( script );
|
||||||
}
|
}
|
||||||
|
|
||||||
script = 0;
|
script = 0;
|
||||||
|
|
||||||
// Callback
|
// Callback
|
||||||
callback( statusText ? 0 : 200, statusText || "success" );
|
callback( statusText ? 0 : 200, statusText || "success" );
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ jQuery.ajax.transport("script", function(s) {
|
||||||
// This arises when a base node is used (#2709 and #4378).
|
// This arises when a base node is used (#2709 and #4378).
|
||||||
head.insertBefore( script, head.firstChild );
|
head.insertBefore( script, head.firstChild );
|
||||||
},
|
},
|
||||||
|
|
||||||
abort: function(statusText) {
|
abort: function(statusText) {
|
||||||
if ( script ) {
|
if ( script ) {
|
||||||
script.onload( 0 , statusText );
|
script.onload( 0 , statusText );
|
||||||
|
|
|
@ -2,28 +2,28 @@
|
||||||
|
|
||||||
var // Next fake timer id
|
var // Next fake timer id
|
||||||
xhrPollingId = jQuery.now(),
|
xhrPollingId = jQuery.now(),
|
||||||
|
|
||||||
// Callbacks hashtable
|
// Callbacks hashtable
|
||||||
xhrs = {},
|
xhrs = {},
|
||||||
|
|
||||||
// #5280: see end of file
|
// #5280: see end of file
|
||||||
xhrUnloadAbortMarker = [];
|
xhrUnloadAbortMarker = [];
|
||||||
|
|
||||||
|
|
||||||
jQuery.ajax.transport( function( s , determineDataType ) {
|
jQuery.ajax.transport( function( s , determineDataType ) {
|
||||||
|
|
||||||
// Cross domain only allowed if supported through XMLHttpRequest
|
// Cross domain only allowed if supported through XMLHttpRequest
|
||||||
if ( ! s.crossDomain || jQuery.support.cors ) {
|
if ( ! s.crossDomain || jQuery.support.cors ) {
|
||||||
|
|
||||||
var callback;
|
var callback;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
||||||
send: function(headers, complete) {
|
send: function(headers, complete) {
|
||||||
|
|
||||||
var xhr = s.xhr(),
|
var xhr = s.xhr(),
|
||||||
handle;
|
handle;
|
||||||
|
|
||||||
// Open the socket
|
// Open the socket
|
||||||
// Passing null username, generates a login popup on Opera (#2865)
|
// Passing null username, generates a login popup on Opera (#2865)
|
||||||
if ( s.username ) {
|
if ( s.username ) {
|
||||||
|
@ -31,7 +31,7 @@ jQuery.ajax.transport( function( s , determineDataType ) {
|
||||||
} else {
|
} else {
|
||||||
xhr.open(s.type, s.url, s.async);
|
xhr.open(s.type, s.url, s.async);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Requested-With header
|
// Requested-With header
|
||||||
// Not set for crossDomain requests with no content
|
// Not set for crossDomain requests with no content
|
||||||
// (see why at http://trac.dojotoolkit.org/ticket/9486)
|
// (see why at http://trac.dojotoolkit.org/ticket/9486)
|
||||||
|
@ -39,16 +39,16 @@ jQuery.ajax.transport( function( s , determineDataType ) {
|
||||||
if ( ! ( s.crossDomain && ! s.hasContent ) && ! headers["x-requested-with"] ) {
|
if ( ! ( s.crossDomain && ! s.hasContent ) && ! headers["x-requested-with"] ) {
|
||||||
headers["x-requested-with"] = "XMLHttpRequest";
|
headers["x-requested-with"] = "XMLHttpRequest";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Need an extra try/catch for cross domain requests in Firefox 3
|
// Need an extra try/catch for cross domain requests in Firefox 3
|
||||||
try {
|
try {
|
||||||
|
|
||||||
jQuery.each(headers, function(key,value) {
|
jQuery.each(headers, function(key,value) {
|
||||||
xhr.setRequestHeader(key,value);
|
xhr.setRequestHeader(key,value);
|
||||||
});
|
});
|
||||||
|
|
||||||
} catch(_) {}
|
} catch(_) {}
|
||||||
|
|
||||||
// Do send the request
|
// Do send the request
|
||||||
try {
|
try {
|
||||||
xhr.send( ( s.hasContent && s.data ) || null );
|
xhr.send( ( s.hasContent && s.data ) || null );
|
||||||
|
@ -56,55 +56,55 @@ jQuery.ajax.transport( function( s , determineDataType ) {
|
||||||
complete(0, "error", "" + e);
|
complete(0, "error", "" + e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Listener
|
// Listener
|
||||||
callback = function ( abortStatusText ) {
|
callback = function ( abortStatusText ) {
|
||||||
|
|
||||||
// Was never called and is aborted or complete
|
// Was never called and is aborted or complete
|
||||||
if ( callback && ( abortStatusText || xhr.readyState === 4 ) ) {
|
if ( callback && ( abortStatusText || xhr.readyState === 4 ) ) {
|
||||||
|
|
||||||
// Do not listen anymore
|
// Do not listen anymore
|
||||||
if (handle) {
|
if (handle) {
|
||||||
xhr.onreadystatechange = jQuery.noop;
|
xhr.onreadystatechange = jQuery.noop;
|
||||||
delete xhrs[ handle ];
|
delete xhrs[ handle ];
|
||||||
handle = undefined;
|
handle = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
callback = 0;
|
callback = 0;
|
||||||
|
|
||||||
// Get info
|
// Get info
|
||||||
var status, statusText, response, responseHeaders;
|
var status, statusText, response, responseHeaders;
|
||||||
|
|
||||||
if ( abortStatusText ) {
|
if ( abortStatusText ) {
|
||||||
|
|
||||||
if ( xhr.readyState !== 4 ) {
|
if ( xhr.readyState !== 4 ) {
|
||||||
xhr.abort();
|
xhr.abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop here if unloadAbort
|
// Stop here if unloadAbort
|
||||||
if ( abortStatusText === xhrUnloadAbortMarker ) {
|
if ( abortStatusText === xhrUnloadAbortMarker ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = 0;
|
status = 0;
|
||||||
statusText = abortStatusText;
|
statusText = abortStatusText;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
status = xhr.status;
|
status = xhr.status;
|
||||||
|
|
||||||
try { // Firefox throws an exception when accessing statusText for faulty cross-domain requests
|
try { // Firefox throws an exception when accessing statusText for faulty cross-domain requests
|
||||||
|
|
||||||
statusText = xhr.statusText;
|
statusText = xhr.statusText;
|
||||||
|
|
||||||
} catch( e ) {
|
} catch( e ) {
|
||||||
|
|
||||||
statusText = ""; // We normalize with Webkit giving an empty statusText
|
statusText = ""; // We normalize with Webkit giving an empty statusText
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
responseHeaders = xhr.getAllResponseHeaders();
|
responseHeaders = xhr.getAllResponseHeaders();
|
||||||
|
|
||||||
// Filter status for non standard behaviours
|
// Filter status for non standard behaviours
|
||||||
// (so many they seem to be the actual "standard")
|
// (so many they seem to be the actual "standard")
|
||||||
status =
|
status =
|
||||||
|
@ -129,10 +129,10 @@ jQuery.ajax.transport( function( s , determineDataType ) {
|
||||||
:
|
:
|
||||||
status
|
status
|
||||||
);
|
);
|
||||||
|
|
||||||
// Guess response if needed & update datatype accordingly
|
// Guess response if needed & update datatype accordingly
|
||||||
if ( status >= 200 && status < 300 ) {
|
if ( status >= 200 && status < 300 ) {
|
||||||
response =
|
response =
|
||||||
determineDataType(
|
determineDataType(
|
||||||
s,
|
s,
|
||||||
xhr.getResponseHeader("content-type"),
|
xhr.getResponseHeader("content-type"),
|
||||||
|
@ -140,30 +140,30 @@ jQuery.ajax.transport( function( s , determineDataType ) {
|
||||||
xhr.responseXML );
|
xhr.responseXML );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call complete
|
// Call complete
|
||||||
complete(status,statusText,response,responseHeaders);
|
complete(status,statusText,response,responseHeaders);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// if we're in sync mode
|
// if we're in sync mode
|
||||||
// or it's in cache and has been retrieved directly (IE6 & IE7)
|
// or it's in cache and has been retrieved directly (IE6 & IE7)
|
||||||
// we need to manually fire the callback
|
// we need to manually fire the callback
|
||||||
if ( ! s.async || xhr.readyState === 4 ) {
|
if ( ! s.async || xhr.readyState === 4 ) {
|
||||||
|
|
||||||
callback();
|
callback();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// Listener is externalized to handle abort on unload
|
// Listener is externalized to handle abort on unload
|
||||||
handle = xhrPollingId++;
|
handle = xhrPollingId++;
|
||||||
xhrs[ handle ] = xhr;
|
xhrs[ handle ] = xhr;
|
||||||
xhr.onreadystatechange = function() {
|
xhr.onreadystatechange = function() {
|
||||||
callback();
|
callback();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
abort: function(statusText) {
|
abort: function(statusText) {
|
||||||
if ( callback ) {
|
if ( callback ) {
|
||||||
callback(statusText);
|
callback(statusText);
|
||||||
|
@ -175,17 +175,17 @@ jQuery.ajax.transport( function( s , determineDataType ) {
|
||||||
|
|
||||||
// #5280: we need to abort on unload or IE will keep connections alive
|
// #5280: we need to abort on unload or IE will keep connections alive
|
||||||
jQuery(window).bind( "unload" , function() {
|
jQuery(window).bind( "unload" , function() {
|
||||||
|
|
||||||
// Abort all pending requests
|
// Abort all pending requests
|
||||||
jQuery.each(xhrs, function(_, xhr) {
|
jQuery.each(xhrs, function(_, xhr) {
|
||||||
if ( xhr.onreadystatechange ) {
|
if ( xhr.onreadystatechange ) {
|
||||||
xhr.onreadystatechange( xhrUnloadAbortMarker );
|
xhr.onreadystatechange( xhrUnloadAbortMarker );
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Resest polling structure to be safe
|
// Resest polling structure to be safe
|
||||||
xhrs = {};
|
xhrs = {};
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
})( jQuery );
|
})( jQuery );
|
||||||
|
|
|
@ -1638,7 +1638,7 @@ test("jQuery ajax - failing cross-domain", function() {
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
var i = 2;
|
var i = 2;
|
||||||
|
|
||||||
if ( jQuery.ajax({
|
if ( jQuery.ajax({
|
||||||
url: 'http://somewebsitethatdoesnotexist-67864863574657654.com',
|
url: 'http://somewebsitethatdoesnotexist-67864863574657654.com',
|
||||||
success: function(){ ok( false , "success" ); },
|
success: function(){ ok( false , "success" ); },
|
||||||
|
@ -1648,7 +1648,7 @@ test("jQuery ajax - failing cross-domain", function() {
|
||||||
ok( true , "no transport" );
|
ok( true , "no transport" );
|
||||||
if ( ! --i ) start();
|
if ( ! --i ) start();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( jQuery.ajax({
|
if ( jQuery.ajax({
|
||||||
url: 'http://www.google.com',
|
url: 'http://www.google.com',
|
||||||
success: function(){ ok( false , "success" ); },
|
success: function(){ ok( false , "success" ); },
|
||||||
|
@ -1658,7 +1658,7 @@ test("jQuery ajax - failing cross-domain", function() {
|
||||||
ok( true , "no transport" );
|
ok( true , "no transport" );
|
||||||
if ( ! --i ) start();
|
if ( ! --i ) start();
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("jQuery ajax - atom+xml", function() {
|
test("jQuery ajax - atom+xml", function() {
|
||||||
|
|
|
@ -151,7 +151,7 @@ test("selector state", function() {
|
||||||
test = jQuery("#main").eq(0);
|
test = jQuery("#main").eq(0);
|
||||||
equals( test.selector, "#main.slice(0,1)", "#main eq Selector" );
|
equals( test.selector, "#main.slice(0,1)", "#main eq Selector" );
|
||||||
equals( test.context, document, "#main eq Context" );
|
equals( test.context, document, "#main eq Context" );
|
||||||
|
|
||||||
var d = "<div />";
|
var d = "<div />";
|
||||||
equals(
|
equals(
|
||||||
jQuery(d).appendTo(jQuery(d)).selector,
|
jQuery(d).appendTo(jQuery(d)).selector,
|
||||||
|
@ -253,38 +253,38 @@ test("isPlainObject", function() {
|
||||||
|
|
||||||
// The use case that we want to match
|
// The use case that we want to match
|
||||||
ok(jQuery.isPlainObject({}), "{}");
|
ok(jQuery.isPlainObject({}), "{}");
|
||||||
|
|
||||||
// Not objects shouldn't be matched
|
// Not objects shouldn't be matched
|
||||||
ok(!jQuery.isPlainObject(""), "string");
|
ok(!jQuery.isPlainObject(""), "string");
|
||||||
ok(!jQuery.isPlainObject(0) && !jQuery.isPlainObject(1), "number");
|
ok(!jQuery.isPlainObject(0) && !jQuery.isPlainObject(1), "number");
|
||||||
ok(!jQuery.isPlainObject(true) && !jQuery.isPlainObject(false), "boolean");
|
ok(!jQuery.isPlainObject(true) && !jQuery.isPlainObject(false), "boolean");
|
||||||
ok(!jQuery.isPlainObject(null), "null");
|
ok(!jQuery.isPlainObject(null), "null");
|
||||||
ok(!jQuery.isPlainObject(undefined), "undefined");
|
ok(!jQuery.isPlainObject(undefined), "undefined");
|
||||||
|
|
||||||
// Arrays shouldn't be matched
|
// Arrays shouldn't be matched
|
||||||
ok(!jQuery.isPlainObject([]), "array");
|
ok(!jQuery.isPlainObject([]), "array");
|
||||||
|
|
||||||
// Instantiated objects shouldn't be matched
|
// Instantiated objects shouldn't be matched
|
||||||
ok(!jQuery.isPlainObject(new Date), "new Date");
|
ok(!jQuery.isPlainObject(new Date), "new Date");
|
||||||
|
|
||||||
var fn = function(){};
|
var fn = function(){};
|
||||||
|
|
||||||
// Functions shouldn't be matched
|
// Functions shouldn't be matched
|
||||||
ok(!jQuery.isPlainObject(fn), "fn");
|
ok(!jQuery.isPlainObject(fn), "fn");
|
||||||
|
|
||||||
// Again, instantiated objects shouldn't be matched
|
// Again, instantiated objects shouldn't be matched
|
||||||
ok(!jQuery.isPlainObject(new fn), "new fn (no methods)");
|
ok(!jQuery.isPlainObject(new fn), "new fn (no methods)");
|
||||||
|
|
||||||
// Makes the function a little more realistic
|
// Makes the function a little more realistic
|
||||||
// (and harder to detect, incidentally)
|
// (and harder to detect, incidentally)
|
||||||
fn.prototype = {someMethod: function(){}};
|
fn.prototype = {someMethod: function(){}};
|
||||||
|
|
||||||
// Again, instantiated objects shouldn't be matched
|
// Again, instantiated objects shouldn't be matched
|
||||||
ok(!jQuery.isPlainObject(new fn), "new fn");
|
ok(!jQuery.isPlainObject(new fn), "new fn");
|
||||||
|
|
||||||
// DOM Element
|
// DOM Element
|
||||||
ok(!jQuery.isPlainObject(document.createElement("div")), "DOM Element");
|
ok(!jQuery.isPlainObject(document.createElement("div")), "DOM Element");
|
||||||
|
|
||||||
// Window
|
// Window
|
||||||
ok(!jQuery.isPlainObject(window), "window");
|
ok(!jQuery.isPlainObject(window), "window");
|
||||||
|
|
||||||
|
@ -298,7 +298,7 @@ test("isPlainObject", function() {
|
||||||
document.body.removeChild( iframe );
|
document.body.removeChild( iframe );
|
||||||
start();
|
start();
|
||||||
};
|
};
|
||||||
|
|
||||||
var doc = iframe.contentDocument || iframe.contentWindow.document;
|
var doc = iframe.contentDocument || iframe.contentWindow.document;
|
||||||
doc.open();
|
doc.open();
|
||||||
doc.write("<body onload='window.parent.iframeDone(Object);'>");
|
doc.write("<body onload='window.parent.iframeDone(Object);'>");
|
||||||
|
@ -659,7 +659,7 @@ test("jQuery.merge()", function() {
|
||||||
|
|
||||||
// Fixed at [5998], #3641
|
// Fixed at [5998], #3641
|
||||||
same( parse([-2,-1], [0,1,2]), [-2,-1,0,1,2], "Second array including a zero (falsy)");
|
same( parse([-2,-1], [0,1,2]), [-2,-1,0,1,2], "Second array including a zero (falsy)");
|
||||||
|
|
||||||
// After fixing #5527
|
// After fixing #5527
|
||||||
same( parse([], [null, undefined]), [null, undefined], "Second array including null and undefined values");
|
same( parse([], [null, undefined]), [null, undefined], "Second array including null and undefined values");
|
||||||
same( parse({length:0}, [1,2]), {length:2, 0:1, 1:2}, "First array like");
|
same( parse({length:0}, [1,2]), {length:2, 0:1, 1:2}, "First array like");
|
||||||
|
@ -694,7 +694,7 @@ test("jQuery.extend(Object, Object)", function() {
|
||||||
equals( deep1.foo2, document, "Make sure that a deep clone was not attempted on the document" );
|
equals( deep1.foo2, document, "Make sure that a deep clone was not attempted on the document" );
|
||||||
|
|
||||||
ok( jQuery.extend(true, {}, nestedarray).arr !== arr, "Deep extend of object must clone child array" );
|
ok( jQuery.extend(true, {}, nestedarray).arr !== arr, "Deep extend of object must clone child array" );
|
||||||
|
|
||||||
// #5991
|
// #5991
|
||||||
ok( jQuery.isArray( jQuery.extend(true, { arr: {} }, nestedarray).arr ), "Cloned array heve to be an Array" );
|
ok( jQuery.isArray( jQuery.extend(true, { arr: {} }, nestedarray).arr ), "Cloned array heve to be an Array" );
|
||||||
ok( jQuery.isPlainObject( jQuery.extend(true, { arr: arr }, { arr: {} }).arr ), "Cloned object heve to be an plain object" );
|
ok( jQuery.isPlainObject( jQuery.extend(true, { arr: arr }, { arr: {} }).arr ), "Cloned object heve to be an plain object" );
|
||||||
|
@ -715,13 +715,13 @@ test("jQuery.extend(Object, Object)", function() {
|
||||||
empty = {};
|
empty = {};
|
||||||
jQuery.extend(true, empty, optionsWithCustomObject);
|
jQuery.extend(true, empty, optionsWithCustomObject);
|
||||||
ok( empty.foo && empty.foo.date === customObject, "Custom objects copy correctly (no methods)" );
|
ok( empty.foo && empty.foo.date === customObject, "Custom objects copy correctly (no methods)" );
|
||||||
|
|
||||||
// Makes the class a little more realistic
|
// Makes the class a little more realistic
|
||||||
myKlass.prototype = { someMethod: function(){} };
|
myKlass.prototype = { someMethod: function(){} };
|
||||||
empty = {};
|
empty = {};
|
||||||
jQuery.extend(true, empty, optionsWithCustomObject);
|
jQuery.extend(true, empty, optionsWithCustomObject);
|
||||||
ok( empty.foo && empty.foo.date === customObject, "Custom objects copy correctly" );
|
ok( empty.foo && empty.foo.date === customObject, "Custom objects copy correctly" );
|
||||||
|
|
||||||
var ret = jQuery.extend(true, { foo: 4 }, { foo: new Number(5) } );
|
var ret = jQuery.extend(true, { foo: 4 }, { foo: new Number(5) } );
|
||||||
ok( ret.foo == 5, "Wrapped numbers copy correctly" );
|
ok( ret.foo == 5, "Wrapped numbers copy correctly" );
|
||||||
|
|
||||||
|
@ -849,10 +849,10 @@ test("jQuery.makeArray", function(){
|
||||||
|
|
||||||
test("jQuery.isEmptyObject", function(){
|
test("jQuery.isEmptyObject", function(){
|
||||||
expect(2);
|
expect(2);
|
||||||
|
|
||||||
equals(true, jQuery.isEmptyObject({}), "isEmptyObject on empty object literal" );
|
equals(true, jQuery.isEmptyObject({}), "isEmptyObject on empty object literal" );
|
||||||
equals(false, jQuery.isEmptyObject({a:1}), "isEmptyObject on non-empty object literal" );
|
equals(false, jQuery.isEmptyObject({a:1}), "isEmptyObject on non-empty object literal" );
|
||||||
|
|
||||||
// What about this ?
|
// What about this ?
|
||||||
// equals(true, jQuery.isEmptyObject(null), "isEmptyObject on null" );
|
// equals(true, jQuery.isEmptyObject(null), "isEmptyObject on null" );
|
||||||
});
|
});
|
||||||
|
@ -878,23 +878,23 @@ test("jQuery.proxy", function(){
|
||||||
|
|
||||||
test("jQuery.parseJSON", function(){
|
test("jQuery.parseJSON", function(){
|
||||||
expect(8);
|
expect(8);
|
||||||
|
|
||||||
equals( jQuery.parseJSON(), null, "Nothing in, null out." );
|
equals( jQuery.parseJSON(), null, "Nothing in, null out." );
|
||||||
equals( jQuery.parseJSON( null ), null, "Nothing in, null out." );
|
equals( jQuery.parseJSON( null ), null, "Nothing in, null out." );
|
||||||
equals( jQuery.parseJSON( "" ), null, "Nothing in, null out." );
|
equals( jQuery.parseJSON( "" ), null, "Nothing in, null out." );
|
||||||
|
|
||||||
same( jQuery.parseJSON("{}"), {}, "Plain object parsing." );
|
same( jQuery.parseJSON("{}"), {}, "Plain object parsing." );
|
||||||
same( jQuery.parseJSON('{"test":1}'), {"test":1}, "Plain object parsing." );
|
same( jQuery.parseJSON('{"test":1}'), {"test":1}, "Plain object parsing." );
|
||||||
|
|
||||||
same( jQuery.parseJSON('\n{"test":1}'), {"test":1}, "Make sure leading whitespaces are handled." );
|
same( jQuery.parseJSON('\n{"test":1}'), {"test":1}, "Make sure leading whitespaces are handled." );
|
||||||
|
|
||||||
try {
|
try {
|
||||||
jQuery.parseJSON("{a:1}");
|
jQuery.parseJSON("{a:1}");
|
||||||
ok( false, "Test malformed JSON string." );
|
ok( false, "Test malformed JSON string." );
|
||||||
} catch( e ) {
|
} catch( e ) {
|
||||||
ok( true, "Test malformed JSON string." );
|
ok( true, "Test malformed JSON string." );
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
jQuery.parseJSON("{'a':1}");
|
jQuery.parseJSON("{'a':1}");
|
||||||
ok( false, "Test malformed JSON string." );
|
ok( false, "Test malformed JSON string." );
|
||||||
|
@ -904,48 +904,48 @@ test("jQuery.parseJSON", function(){
|
||||||
});
|
});
|
||||||
|
|
||||||
test("jQuery._Deferred()", function() {
|
test("jQuery._Deferred()", function() {
|
||||||
|
|
||||||
expect( 10 );
|
expect( 10 );
|
||||||
|
|
||||||
var deferred,
|
var deferred,
|
||||||
object,
|
object,
|
||||||
test;
|
test;
|
||||||
|
|
||||||
deferred = jQuery._Deferred();
|
deferred = jQuery._Deferred();
|
||||||
|
|
||||||
test = false;
|
test = false;
|
||||||
|
|
||||||
deferred.complete( function( value ) {
|
deferred.complete( function( value ) {
|
||||||
equals( value , "value" , "Test pre-resolve callback" );
|
equals( value , "value" , "Test pre-resolve callback" );
|
||||||
test = true;
|
test = true;
|
||||||
} );
|
} );
|
||||||
|
|
||||||
deferred.resolve( "value" );
|
deferred.resolve( "value" );
|
||||||
|
|
||||||
ok( test , "Test pre-resolve callbacks called right away" );
|
ok( test , "Test pre-resolve callbacks called right away" );
|
||||||
|
|
||||||
test = false;
|
test = false;
|
||||||
|
|
||||||
deferred.complete( function( value ) {
|
deferred.complete( function( value ) {
|
||||||
equals( value , "value" , "Test post-resolve callback" );
|
equals( value , "value" , "Test post-resolve callback" );
|
||||||
test = true;
|
test = true;
|
||||||
} );
|
} );
|
||||||
|
|
||||||
ok( test , "Test post-resolve callbacks called right away" );
|
ok( test , "Test post-resolve callbacks called right away" );
|
||||||
|
|
||||||
deferred.cancel();
|
deferred.cancel();
|
||||||
|
|
||||||
test = true;
|
test = true;
|
||||||
|
|
||||||
deferred.complete( function() {
|
deferred.complete( function() {
|
||||||
ok( false , "Cancel was ignored" );
|
ok( false , "Cancel was ignored" );
|
||||||
test = false;
|
test = false;
|
||||||
} );
|
} );
|
||||||
|
|
||||||
ok( test , "Test cancel" );
|
ok( test , "Test cancel" );
|
||||||
|
|
||||||
deferred = jQuery._Deferred().resolve();
|
deferred = jQuery._Deferred().resolve();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
deferred.complete( function() {
|
deferred.complete( function() {
|
||||||
throw "Error";
|
throw "Error";
|
||||||
|
@ -956,77 +956,77 @@ test("jQuery._Deferred()", function() {
|
||||||
strictEqual( e , "Error" , "Test deferred propagates exceptions");
|
strictEqual( e , "Error" , "Test deferred propagates exceptions");
|
||||||
deferred.complete();
|
deferred.complete();
|
||||||
}
|
}
|
||||||
|
|
||||||
test = "";
|
test = "";
|
||||||
deferred = jQuery._Deferred().complete( function() {
|
deferred = jQuery._Deferred().complete( function() {
|
||||||
|
|
||||||
test += "A";
|
test += "A";
|
||||||
|
|
||||||
}, function() {
|
}, function() {
|
||||||
|
|
||||||
test += "B";
|
test += "B";
|
||||||
|
|
||||||
} ).resolve();
|
} ).resolve();
|
||||||
|
|
||||||
strictEqual( test , "AB" , "Test multiple complete parameters" );
|
strictEqual( test , "AB" , "Test multiple complete parameters" );
|
||||||
|
|
||||||
test = "";
|
test = "";
|
||||||
|
|
||||||
deferred.complete( function() {
|
deferred.complete( function() {
|
||||||
|
|
||||||
deferred.complete( function() {
|
deferred.complete( function() {
|
||||||
|
|
||||||
test += "C";
|
test += "C";
|
||||||
|
|
||||||
} );
|
} );
|
||||||
|
|
||||||
test += "A";
|
test += "A";
|
||||||
|
|
||||||
}, function() {
|
}, function() {
|
||||||
|
|
||||||
test += "B";
|
test += "B";
|
||||||
} );
|
} );
|
||||||
|
|
||||||
strictEqual( test , "ABC" , "Test complete callbacks order" );
|
strictEqual( test , "ABC" , "Test complete callbacks order" );
|
||||||
|
|
||||||
deferred = jQuery._Deferred();
|
deferred = jQuery._Deferred();
|
||||||
|
|
||||||
deferred.fire( jQuery , [ document ] ).complete( function( doc ) {
|
deferred.fire( jQuery , [ document ] ).complete( function( doc ) {
|
||||||
ok( this === jQuery && arguments.length === 1 && doc === document , "Test fire context & args" );
|
ok( this === jQuery && arguments.length === 1 && doc === document , "Test fire context & args" );
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test("jQuery.Deferred()", function() {
|
test("jQuery.Deferred()", function() {
|
||||||
|
|
||||||
expect( 4 );
|
expect( 4 );
|
||||||
|
|
||||||
jQuery.Deferred( function( defer ) {
|
jQuery.Deferred( function( defer ) {
|
||||||
strictEqual( this , defer , "Defer passed as this & first argument" );
|
strictEqual( this , defer , "Defer passed as this & first argument" );
|
||||||
this.resolve( "done" );
|
this.resolve( "done" );
|
||||||
}).then( function( value ) {
|
}).then( function( value ) {
|
||||||
strictEqual( value , "done" , "Passed function executed" );
|
strictEqual( value , "done" , "Passed function executed" );
|
||||||
});
|
});
|
||||||
|
|
||||||
jQuery.Deferred().resolve().then( function() {
|
jQuery.Deferred().resolve().then( function() {
|
||||||
ok( true , "Success on resolve" );
|
ok( true , "Success on resolve" );
|
||||||
}, function() {
|
}, function() {
|
||||||
ok( false , "Error on resolve" );
|
ok( false , "Error on resolve" );
|
||||||
});
|
});
|
||||||
|
|
||||||
jQuery.Deferred().reject().then( function() {
|
jQuery.Deferred().reject().then( function() {
|
||||||
ok( false , "Success on reject" );
|
ok( false , "Success on reject" );
|
||||||
}, function() {
|
}, function() {
|
||||||
ok( true , "Error on reject" );
|
ok( true , "Error on reject" );
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test("jQuery.when()", function() {
|
test("jQuery.when()", function() {
|
||||||
|
|
||||||
expect( 21 );
|
expect( 21 );
|
||||||
|
|
||||||
// Some other objects
|
// Some other objects
|
||||||
jQuery.each( {
|
jQuery.each( {
|
||||||
|
|
||||||
"an empty string": "",
|
"an empty string": "",
|
||||||
"a non-empty string": "some string",
|
"a non-empty string": "some string",
|
||||||
"zero": 0,
|
"zero": 0,
|
||||||
|
@ -1036,17 +1036,17 @@ test("jQuery.when()", function() {
|
||||||
"null": null,
|
"null": null,
|
||||||
"undefined": undefined,
|
"undefined": undefined,
|
||||||
"a plain object": {}
|
"a plain object": {}
|
||||||
|
|
||||||
} , function( message , value ) {
|
} , function( message , value ) {
|
||||||
|
|
||||||
ok( jQuery.isFunction( jQuery.when( value ).then( function( resolveValue ) {
|
ok( jQuery.isFunction( jQuery.when( value ).then( function( resolveValue ) {
|
||||||
strictEqual( resolveValue , value , "Test the promise was resolved with " + message );
|
strictEqual( resolveValue , value , "Test the promise was resolved with " + message );
|
||||||
} ).promise ) , "Test " + message + " triggers the creation of a new Promise" );
|
} ).promise ) , "Test " + message + " triggers the creation of a new Promise" );
|
||||||
|
|
||||||
} );
|
} );
|
||||||
|
|
||||||
var cache, i;
|
var cache, i;
|
||||||
|
|
||||||
for( i = 1 ; i < 4 ; i++ ) {
|
for( i = 1 ; i < 4 ; i++ ) {
|
||||||
jQuery.when( cache || jQuery.Deferred( function() {
|
jQuery.when( cache || jQuery.Deferred( function() {
|
||||||
this.resolve( i );
|
this.resolve( i );
|
||||||
|
|
Loading…
Reference in a new issue