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