Commit e56de77d authored by Colin Snover's avatar Colin Snover

Cleaning up trailing whitespace again.

parent ae6655bc
This diff is collapsed.
......@@ -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 );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment