(function( jQuery ) {
-
+
var r20 = /%20/g,
rbracket = /\[\]$/,
rhash = /#.*$/,
// Slice function
sliceFunc = Array.prototype.slice,
-
+
// Keep a copy of the old load method
_load = jQuery.fn.load;
// 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,
i,
// Fake xhr
jXHR = {
-
+
readyState: 0,
-
+
// Caches the header
setRequestHeader: function(name,value) {
if ( state === 0 ) {
}
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 ];
}
}
return responseHeaders[ key.toLowerCase() ];
},
-
+
// Cancel the request
abort: function( statusText ) {
if ( transport && state !== 2 ) {
// 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;
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;
}
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,
"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 ];
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
}
}
}
-
+
// Attach deferreds
deferred.promise( jXHR );
jXHR.success = jXHR.complete;
// 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;
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);
done(0, "error", "" + e);
jXHR = false;
-
+
// Simply rethrow otherwise
} else {
jQuery.error(e);
}
}
}
-
+
return jXHR;
},
checked = {},
flag,
noSelect = structure !== "transports";
-
+
function initSearch( dataType ) {
flag = transportDataType !== dataType && ! checked[ dataType ];
-
+
if ( flag ) {
-
+
checked[ dataType ] = 1;
transportDataType = dataType;
list = s[ structure ][ dataType ];
return flag;
}
-
+
initSearch( dataTypes[ 0 ] );
for ( i = 0 ; ( noSelect || ! selected ) && i <= length ; i++ ) {
-
+
if ( i === length ) {
-
+
initSearch( "*" );
-
+
} else {
selected = list[ i ]( s , determineDataType );
// Add an element to one of the structures in ajaxSettings
function ajax_addElement( structure , args ) {
-
+
var i,
start = 0,
length = args.length,
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 );
}
}
}
-
+
return jQuery.ajax;
}
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 === "*" ) {
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
// Has the ready events already been bound?
readyBound = false,
-
+
// The deferred used on DOM ready
readyList,
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 );
},
// 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" );
jQuery.error( "Invalid JSON: " + data );
}
},
-
+
// Cross-browser xml parsing
// (xml & tmp used internally)
parseXML: function( data , xml , tmp ) {
xml.async = "false";
xml.loadXML( data );
}
-
+
tmp = xml.documentElement;
-
+
if ( ! tmp || ! tmp.nodeName || tmp.nodeName === "parsererror" ) {
jQuery.error( "Invalid XML: " + data );
}
-
+
return xml;
},
now: function() {
return (new Date()).getTime();
},
-
+
// Create a simple deferred (one callbacks list)
_Deferred: function() {
-
+
var // callbacks list
callbacks = [],
// stored [ context , args ]
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 );
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 );
}
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;
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 ) {
}
} );
-
+
// 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;
},
// 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) ) ) {
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 ) ) {
// 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 ) {
}
return responseContainer[ 0 ];
};
-
+
// Delegate to script transport
return "script";
}
accepts: {
script: "text/javascript, application/javascript"
},
-
+
contents: {
script: /javascript/
},
-
+
converters: {
"text script": jQuery.globalEval
}
// 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");
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" );
}
// 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 );
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 ) {
} 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)
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 );
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 =
:
status
);
-
+
// Guess response if needed & update datatype accordingly
if ( status >= 200 && status < 300 ) {
- response =
+ response =
determineDataType(
s,
xhr.getResponseHeader("content-type"),
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);
// #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 );
stop();
var i = 2;
-
+
if ( jQuery.ajax({
url: 'http://somewebsitethatdoesnotexist-67864863574657654.com',
success: function(){ ok( false , "success" ); },
ok( true , "no transport" );
if ( ! --i ) start();
}
-
+
if ( jQuery.ajax({
url: 'http://www.google.com',
success: function(){ ok( false , "success" ); },
ok( true , "no transport" );
if ( ! --i ) start();
}
-
+
});
test("jQuery ajax - atom+xml", 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,
// 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");
document.body.removeChild( iframe );
start();
};
-
+
var doc = iframe.contentDocument || iframe.contentWindow.document;
doc.open();
doc.write("<body onload='window.parent.iframeDone(Object);'>");
// 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");
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" );
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" );
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" );
});
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." );
});
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";
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,
"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 );