// will result in `undefined` for elem = this[ 0 ] which will
// throw an exception if an attempt to read a data cache is made.
if ( elem && value === undefined ) {
+
// Attempt to get data from the cache
// with the key as-is
data = dataUser.get( elem, key );
}
camelKey = jQuery.camelCase( key );
+
// Attempt to get data from the cache
// with the key camelized
data = dataUser.get( elem, camelKey );
// Set the data...
camelKey = jQuery.camelCase( key );
- this.each(function() {
+ this.each( function() {
+
// First, attempt to store a copy or reference of any
// data that might've been store with a camelCased key.
var data = dataUser.get( this, camelKey );
// *... In the case of properties that might _actually_
// have dashes, we need to also store a copy of that
// unchanged property.
- if ( key.indexOf("-") > -1 && data !== undefined ) {
+ if ( key.indexOf( "-" ) > -1 && data !== undefined ) {
dataUser.set( this, key, value );
}
- });
+ } );
}, null, value, arguments.length > 1, null, true );
},
value: value,
writable: true,
configurable: true
- });
+ } );
}
return owner[ this.expando ];
},
- cache: function( owner, initial ) {
+ cache: function( owner ) {
+
// We can accept data for non-element nodes in modern browsers,
// but we should not, see #8335.
// Always return an empty object.
// Handle: [ owner, { properties } ] args
} else {
+
// Copy the properties one-by-one to the cache object
for ( prop in data ) {
cache[ prop ] = data[ prop ];
get: function( owner, key ) {
return key === undefined ?
this.cache( owner ) :
- owner[ this.expando ] && owner[ this.expando ][ key ]
+ owner[ this.expando ] && owner[ this.expando ][ key ];
},
access: function( owner, key, value ) {
var stored;
+
// In cases where either:
//
// 1. No key was specified
// 2. The data stored at the key
//
if ( key === undefined ||
- ((key && typeof key === "string") && value === undefined) ) {
+ ( ( key && typeof key === "string" ) && value === undefined ) ) {
stored = this.get( owner, key );
return stored !== undefined ?
- stored : this.get( owner, jQuery.camelCase(key) );
+ stored : this.get( owner, jQuery.camelCase( key ) );
}
// When the key is not a string, or both a key and value
this.register( owner );
} else {
+
// Support array or space separated string of keys
if ( jQuery.isArray( key ) ) {
+
// If "name" is an array of keys...
// When data is initially created, via ("key", "val") signature,
// keys will be converted to camelCase.
name = key.concat( key.map( jQuery.camelCase ) );
} else {
camel = jQuery.camelCase( key );
+
// Try the string as a key before any manipulation
if ( key in cache ) {
name = [ key, camel ];
} else {
+
// If a key with the spaces exists, use it.
// Otherwise, create an array by matching non-whitespace
name = camel;
"./callbacks"
], function( jQuery, slice ) {
-jQuery.extend({
+jQuery.extend( {
Deferred: function( func ) {
var tuples = [
+
// action, add listener, listener list, final state
- [ "resolve", "done", jQuery.Callbacks("once memory"), "resolved" ],
- [ "reject", "fail", jQuery.Callbacks("once memory"), "rejected" ],
- [ "notify", "progress", jQuery.Callbacks("memory") ]
+ [ "resolve", "done", jQuery.Callbacks( "once memory" ), "resolved" ],
+ [ "reject", "fail", jQuery.Callbacks( "once memory" ), "rejected" ],
+ [ "notify", "progress", jQuery.Callbacks( "memory" ) ]
],
state = "pending",
promise = {
},
then: function( /* fnDone, fnFail, fnProgress */ ) {
var fns = arguments;
- return jQuery.Deferred(function( newDefer ) {
+ return jQuery.Deferred( function( newDefer ) {
jQuery.each( tuples, function( i, tuple ) {
var fn = jQuery.isFunction( fns[ i ] ) && fns[ i ];
+
// deferred[ done | fail | progress ] for forwarding actions to newDefer
- deferred[ tuple[1] ](function() {
+ deferred[ tuple[ 1 ] ]( function() {
var returned = fn && fn.apply( this, arguments );
if ( returned && jQuery.isFunction( returned.promise ) ) {
returned.promise()
fns = null;
} ).promise();
},
+
// Get a promise for this deferred
// If obj is provided, the promise aspect is added to the object
promise: function( obj ) {
stateString = tuple[ 3 ];
// promise[ done | fail | progress ] = list.add
- promise[ tuple[1] ] = list.add;
+ promise[ tuple[ 1 ] ] = list.add;
// Handle state
if ( stateString ) {
- list.add(function() {
+ list.add( function() {
+
// state = [ resolved | rejected ]
state = stateString;
}
// deferred[ resolve | reject | notify ]
- deferred[ tuple[0] ] = function() {
- deferred[ tuple[0] + "With" ]( this === deferred ? promise : this, arguments );
+ deferred[ tuple[ 0 ] ] = function() {
+ deferred[ tuple[ 0 ] + "With" ]( this === deferred ? promise : this, arguments );
return this;
};
- deferred[ tuple[0] + "With" ] = list.fireWith;
- });
+ deferred[ tuple[ 0 ] + "With" ] = list.fireWith;
+ } );
+
// Make the deferred a promise
promise.promise( deferred );
if ( arguments.length ) {
return options === undefined ?
this :
- this.each(function( i ) {
+ this.each( function( i ) {
jQuery.offset.setOffset( this, options, i );
- });
+ } );
}
var docElem, win,
},
unwrap: function() {
- return this.parent().each(function() {
+ return this.parent().each( function() {
if ( !jQuery.nodeName( this, "body" ) ) {
jQuery( this ).replaceWith( this.childNodes );
}
- }).end();
+ } ).end();
}
} );
-{bad: toTheBone}
+{bad: toTheBone;}
// Tests are always loaded async
QUnit.config.autostart = false;
this.loadTests = function() {
+
// Leverage QUnit URL parsing to detect testSwarm environment and "basic" testing mode
var loadSwarm = ( QUnit.urlParams[ "swarmURL" ] + "" ).indexOf( "http" ) === 0,
basicTests = ( QUnit.urlParams[ "module" ] + "" ) === "basic";
require( [ "data/testrunner.js" ], function() {
var i = 0,
tests = [
+
// A special module with basic tests, meant for
// not fully supported environments like Android 2.3,
// jsdom or PhantomJS. We run it everywhere, though,
} else {
// No built-in support for binary data, but it's easy to add via a prefilter
- jQuery.ajaxPrefilter( "arraybuffer", function ( s ) {
+ jQuery.ajaxPrefilter( "arraybuffer", function( s ) {
s.xhrFields = { responseType: "arraybuffer" };
s.responseFields.arraybuffer = "response";
s.converters[ "binary arraybuffer" ] = true;
- });
+ } );
ajaxTest( "gh-2498 - jQuery.ajax() - binary data shouldn't throw an exception", 2, function( assert ) {
return {
url: url( "data/ajax/content-type.php" ),
data: {
"content-type": "test/jsontest",
- "response": JSON.stringify({test: "test"})
+ "response": JSON.stringify( { test: "test" } )
},
success: function( result ) {
assert.strictEqual(
QUnit.test( "image.prop( 'tabIndex' )", function( assert ) {
assert.expect( 1 );
- var image = jQuery("<img src='data/1x1.jpg' />")
- .appendTo("#qunit-fixture");
- assert.equal( image.prop("tabIndex" ), -1, "tabIndex on image" );
+ var image = jQuery( "<img src='data/1x1.jpg' />" )
+ .appendTo( "#qunit-fixture" );
+ assert.equal( image.prop( "tabIndex" ), -1, "tabIndex on image" );
} );
QUnit.test( "prop('tabindex', value)", function( assert ) {
}
if ( jQuery.fn.offset ) {
expected++;
- attrObj["offset"] = { "top": 1, "left": 1 };
+ attrObj[ "offset" ] = { "top": 1, "left": 1 };
}
if ( jQuery.fn.css ) {
expected += 2;
assert.equal( div.length, 4, "Correct number of elements generated for div hr code b" );
assert.equal( div.parent().length, 0, "Make sure that the generated HTML has no parent." );
- assert.equal( jQuery( [ 1,2,3 ] ).get( 1 ), 2, "Test passing an array to the factory" );
+ assert.equal( jQuery( [ 1, 2, 3 ] ).get( 1 ), 2, "Test passing an array to the factory" );
assert.equal( jQuery( document.body ).get( 0 ), jQuery( "body" ).get( 0 ), "Test passing an html node to the factory" );
elem = jQuery( "\n\n<em>world</em>" )[ 0 ];
assert.equal( elem.nodeName.toLowerCase(), "em", "leading newlines" );
- elem = jQuery("<div/>", attrObj );
+ elem = jQuery( "<div/>", attrObj );
if ( jQuery.fn.width ) {
assert.equal( elem[ 0 ].style.width, "10px", "jQuery() quick setter width" );
}
if ( jQuery.fn.offset ) {
- equal( elem[0].style.top, "1px", "jQuery() quick setter offset");
+ assert.equal( elem[ 0 ].style.top, "1px", "jQuery() quick setter offset" );
}
if ( jQuery.fn.css ) {
} );
QUnit.test( "type for `Symbol`", function( assert ) {
+
// Prevent reference errors
- if( typeof Symbol !== "function" ) {
+ if ( typeof Symbol !== "function" ) {
assert.expect( 0 );
return;
}
assert.equal( jQuery.type( Symbol() ), "symbol", "Symbol" );
assert.equal( jQuery.type( Object( Symbol() ) ), "symbol", "Symbol" );
-});
+} );
QUnit.asyncTest( "isPlainObject", function( assert ) {
assert.expect( 15 );
assert.equal( jQuery.isPlainObject( Object( Symbol() ) ), false, "Symbol inside an object" );
} );
-
QUnit.test( "isFunction", function( assert ) {
assert.expect( 19 );
assert.ok( !result, "empty NodeList treated like array" );
result = jQuery.map( Array( 4 ), function( v, k ) {
- return k % 2 ? k : [ k,k,k ];
+ return k % 2 ? k : [ k, k, k ];
} );
assert.equal( result.join( "" ), "00012223", "Array results flattened (#2616)" );
} );
[],
"Satisfying elements absent, Array-like object used, and grep explicitly uninverted"
);
-});
+} );
QUnit.test( "jQuery.extend(Object, Object)", function( assert ) {
assert.expect( 28 );
QUnit.test( "jQuery.extend(Object, Object {created with \"defineProperties\"})", function( assert ) {
assert.expect( 2 );
- var definedObj = Object.defineProperties({}, {
+ var definedObj = Object.defineProperties( {}, {
"enumerableProp": {
- get: function () {
+ get: function() {
return true;
},
enumerable: true
},
"nonenumerableProp": {
- get: function () {
+ get: function() {
return true;
}
}
- }),
+ } ),
accessorObj = {};
jQuery.extend( accessorObj, definedObj );
assert.deepEqual( seen, [ 1, 2 ], "Broken array iteration" );
seen = [];
- jQuery.each( { "a": 1, "b": 2,"c": 3 }, function( k, v ) {
+ jQuery.each( { "a": 1, "b": 2, "c": 3 }, function( k, v ) {
seen.push( v );
return false;
} );
assert.equal( ( function() { return jQuery.makeArray( arguments ); } )( 1, 2 ).join( "" ), "12", "Pass makeArray an arguments array" );
- assert.equal( jQuery.makeArray( [ 1,2,3 ] ).join( "" ), "123", "Pass makeArray a real array" );
+ assert.equal( jQuery.makeArray( [ 1, 2, 3 ] ).join( "" ), "123", "Pass makeArray a real array" );
assert.equal( jQuery.makeArray().length, 0, "Pass nothing to makeArray and expect an empty array" );
var prop, i, l, metadata, elem,
obj, obj2, check, num, num2,
parseJSON = jQuery.parseJSON,
- div = jQuery("<div>"),
- child = jQuery("<div data-myobj='old data' data-ignored=\"DOM\" data-other='test'></div>"),
- dummy = jQuery("<div data-myobj='old data' data-ignored=\"DOM\" data-other='test'></div>");
+ div = jQuery( "<div>" ),
+ child = jQuery( "<div data-myobj='old data' data-ignored=\"DOM\" data-other='test'></div>" ),
+ dummy = jQuery( "<div data-myobj='old data' data-ignored=\"DOM\" data-other='test'></div>" );
assert.equal( div.data( "attr" ), undefined, "Check for non-existing data-attr attribute" );
div.remove();
- child.appendTo("#qunit-fixture");
- assert.equal( child.data("myobj"), "old data", "Value accessed from data-* attribute");
+ child.appendTo( "#qunit-fixture" );
+ assert.equal( child.data( "myobj" ), "old data", "Value accessed from data-* attribute" );
child.data( "myobj", "replaced" );
assert.equal( child.data( "myobj" ), "replaced", "Original data overwritten" );
break;
case 3:
assert.equal( jQuery( elem ).data( "number" ), true, "Check number property" );
- assert.deepEqual( jQuery( elem ).data( "stuff" ), [ 2,8 ], "Check stuff property" );
+ assert.deepEqual( jQuery( elem ).data( "stuff" ), [ 2, 8 ], "Check stuff property" );
break;
default:
assert.ok( false, [ "Assertion failed on index ", index, ", with data" ].join( "" ) );
assert.deepEqual( b.data( "long-param" ), { a: 2 }, "data with property long-param was found, 2" );
} );
-QUnit.test(".data supports interoperable hyphenated/camelCase get/set of properties with arbitrary non-null|NaN|undefined values", function( assert ) {
+QUnit.test( ".data supports interoperable hyphenated/camelCase get/set of properties with arbitrary non-null|NaN|undefined values", function( assert ) {
var div = jQuery( "<div/>", { id: "hyphened" } ).appendTo( "#qunit-fixture" ),
datas = {
"non-empty": "a string",
} );
QUnit.test( ".removeData supports removal of hyphenated properties via array (#12786)", function( assert ) {
- expect( 4 );
+ assert.expect( 4 );
var div, plain, compare;
// From batch assignment .data({ "a-a": 1 })
"a-a": 1,
+
// From property, value assignment .data( "b-b", 1 )
"bB": 1
};
assert.strictEqual( div[ 0 ][ key ], undefined, "Expando was not removed when there was no more data" );
}
}
-});
+} );
QUnit.test( "Check that the expando is removed when there's no more data on non-nodes", function( assert ) {
assert.expect( 1 );
var key,
- obj = jQuery( {key: 42} );
+ obj = jQuery( { key: 42 } );
obj.data( "some", "data" );
assert.equal( obj.data( "some" ), "data", "Data is added" );
obj.removeData( "some" );
assert.strictEqual( defer.pipe, defer.then, "pipe is an alias of then" );
- createDeferred().resolve().done(function() {
+ createDeferred().resolve().done( function() {
assert.ok( true, "Success on resolve" );
assert.strictEqual( this.state(), "resolved", "Deferred is resolved (state)" );
- }).fail(function() {
+ } ).fail( function() {
assert.ok( false, "Error on resolve" );
- }).always(function() {
+ } ).always( function() {
assert.ok( true, "Always callback on resolve" );
- });
+ } );
- createDeferred().reject().done(function() {
+ createDeferred().reject().done( function() {
assert.ok( false, "Success on reject" );
- }).fail(function() {
+ } ).fail( function() {
assert.ok( true, "Error on reject" );
assert.strictEqual( this.state(), "rejected", "Deferred is rejected (state)" );
- }).always(function() {
+ } ).always( function() {
assert.ok( true, "Always callback on reject" );
- });
+ } );
- createDeferred(function( defer ) {
+ createDeferred( function( defer ) {
assert.ok( this === defer, "Defer passed as this & first argument" );
- this.resolve("done");
- }).done(function( value ) {
+ this.resolve( "done" );
+ } ).done( function( value ) {
assert.strictEqual( value, "done", "Passed function executed" );
- });
+ } );
- createDeferred(function( defer ) {
+ createDeferred( function( defer ) {
var promise = defer.promise(),
func = function() {},
funcPromise = defer.promise( func );
var value1, value2, value3,
defer = jQuery.Deferred(),
- piped = defer.then(function( a, b ) {
+ piped = defer.then( function( a, b ) {
return a * b;
- });
+ } );
- piped.done(function( result ) {
+ piped.done( function( result ) {
value3 = result;
- });
+ } );
- defer.done(function( a, b ) {
+ defer.done( function( a, b ) {
value1 = a;
value2 = b;
- });
+ } );
defer.resolve( 2, 3 );
assert.strictEqual( value2, 3, "second resolve value ok" );
assert.strictEqual( value3, 6, "result of filter ok" );
- jQuery.Deferred().reject().then(function() {
+ jQuery.Deferred().reject().then( function() {
assert.ok( false, "then should not be called on reject" );
- });
+ } );
- jQuery.Deferred().resolve().then( jQuery.noop ).done(function( value ) {
+ jQuery.Deferred().resolve().then( jQuery.noop ).done( function( value ) {
assert.strictEqual( value, undefined, "then done callback can return undefined/null" );
- });
+ } );
} );
QUnit.test( "jQuery.Deferred.then - filtering (fail)", function( assert ) {
defer = jQuery.Deferred(),
piped = defer.then( null, function( a, b ) {
return a * b;
- });
+ } );
- piped.fail(function( result ) {
+ piped.fail( function( result ) {
value3 = result;
- });
+ } );
- defer.fail(function( a, b ) {
+ defer.fail( function( a, b ) {
value1 = a;
value2 = b;
- });
+ } );
defer.reject( 2, 3 );
- strictEqual( value1, 2, "first reject value ok" );
- strictEqual( value2, 3, "second reject value ok" );
- strictEqual( value3, 6, "result of filter ok" );
+ assert.strictEqual( value1, 2, "first reject value ok" );
+ assert.strictEqual( value2, 3, "second reject value ok" );
+ assert.strictEqual( value3, 6, "result of filter ok" );
jQuery.Deferred().resolve().then( null, function() {
- ok( false, "then should not be called on resolve" );
- });
+ assert.ok( false, "then should not be called on resolve" );
+ } );
- jQuery.Deferred().reject().then( null, jQuery.noop ).fail(function( value ) {
- strictEqual( value, undefined, "then fail callback can return undefined/null" );
- });
-});
+ jQuery.Deferred().reject().then( null, jQuery.noop ).fail( function( value ) {
+ assert.strictEqual( value, undefined, "then fail callback can return undefined/null" );
+ } );
+} );
QUnit.test( "jQuery.Deferred.then - filtering (progress)", function( assert ) {
assert.expect( 3 );
assert.strictEqual( value1, 2, "first progress value ok" );
assert.strictEqual( value2, 3, "second progress value ok" );
assert.strictEqual( value3, 6, "result of filter ok" );
-});
+} );
QUnit.test( "jQuery.Deferred.then - deferred (done)", function( assert ) {
assert.expect( 3 );
assert.strictEqual( value1, 2, "first resolve value ok" );
assert.strictEqual( value2, 3, "second resolve value ok" );
assert.strictEqual( value3, 6, "result of filter ok" );
-});
+} );
QUnit.test( "jQuery.Deferred.then - deferred (fail)", function( assert ) {
assert.expect( 3 );
assert.strictEqual( value1, 2, "first reject value ok" );
assert.strictEqual( value2, 3, "second reject value ok" );
assert.strictEqual( value3, 6, "result of filter ok" );
-});
+} );
QUnit.test( "jQuery.Deferred.then - deferred (progress)", function( assert ) {
assert.expect( 3 );
assert.strictEqual( value1, 2, "first progress value ok" );
assert.strictEqual( value2, 3, "second progress value ok" );
assert.strictEqual( value3, 6, "result of filter ok" );
-});
+} );
QUnit.test( "jQuery.Deferred.then - context", function( assert ) {
assert.expect( 7 );
jQuery.Deferred().resolveWith( context, [ 2 ] ).then( function( value ) {
return value * 3;
- } ).done(function( value ) {
+ } ).done( function( value ) {
assert.strictEqual( this, context, "custom context correctly propagated" );
assert.strictEqual( value, 6, "proper value received" );
- });
+ } );
- jQuery.Deferred().resolve().then(function() {
- return jQuery.Deferred().resolveWith(context);
- }).done(function() {
+ jQuery.Deferred().resolve().then( function() {
+ return jQuery.Deferred().resolveWith( context );
+ } ).done( function() {
assert.strictEqual( this, context, "custom context of returned deferred correctly propagated" );
- });
+ } );
defer = jQuery.Deferred();
piped = defer.then( function( value ) {
defer.resolve( 2 );
- piped.done(function( value ) {
+ piped.done( function( value ) {
assert.strictEqual( this, piped, "default context gets updated to latest promise in the chain" );
assert.strictEqual( value, 6, "proper value received" );
- });
+ } );
defer2 = jQuery.Deferred();
piped2 = defer2.then();
defer2.resolve( 2 );
- piped2.done(function( value ) {
+ piped2.done( function( value ) {
assert.strictEqual( this, piped2, "default context gets updated to latest promise in the chain (without passing function)" );
assert.strictEqual( value, 2, "proper value received (without passing function)" );
- });
-});
+ } );
+} );
QUnit.test( "jQuery.when", function( assert ) {
assert.expect( 37 );
- jQuery.each({
+ jQuery.each( {
"an empty string": "",
"a non-empty string": "some string",
"zero": 0,
}, function( message, value ) {
assert.ok(
jQuery.isFunction(
- jQuery.when( value ).done(function( resolveValue ) {
+ jQuery.when( value ).done( function( resolveValue ) {
assert.strictEqual( this, window, "Context is the global object with " + message );
assert.strictEqual( resolveValue, value, "Test the promise was resolved with " + message );
- }).promise
+ } ).promise
),
"Test " + message + " triggers the creation of a new Promise"
);
- });
+ } );
assert.ok(
jQuery.isFunction(
- jQuery.when().done(function( resolveValue ) {
+ jQuery.when().done( function( resolveValue ) {
assert.strictEqual( this, window, "Test the promise was resolved with window as its context" );
assert.strictEqual( resolveValue, undefined, "Test the promise was resolved with no parameter" );
- }).promise
+ } ).promise
),
"Test calling when with no parameter triggers the creation of a new Promise"
);
var cache,
context = {};
- jQuery.when( jQuery.Deferred().resolveWith( context ) ).done(function() {
+ jQuery.when( jQuery.Deferred().resolveWith( context ) ).done( function() {
assert.strictEqual( this, context, "when( promise ) propagates context" );
- });
+ } );
- jQuery.each([ 1, 2, 3 ], function( k, i ) {
+ jQuery.each( [ 1, 2, 3 ], function( k, i ) {
- jQuery.when( cache || jQuery.Deferred(function() {
+ jQuery.when( cache || jQuery.Deferred( function() {
this.resolve( i );
- })
- ).done(function( value ) {
+ } )
+ ).done( function( value ) {
assert.strictEqual( value, 1, "Function executed" + ( i > 1 ? " only once" : "" ) );
cache = value;
- });
+ } );
- });
+ } );
} );
QUnit.test( "jQuery.when - joined", function( assert ) {
context1 = defer1 && jQuery.isFunction( defer1.promise ) ? defer1.promise() : undefined,
context2 = defer2 && jQuery.isFunction( defer2.promise ) ? defer2.promise() : undefined;
- jQuery.when( defer1, defer2 ).done(function( a, b ) {
+ jQuery.when( defer1, defer2 ).done( function( a, b ) {
if ( shouldResolve ) {
assert.deepEqual( [ a, b ], expected, code + " => resolve" );
assert.strictEqual( this[ 0 ], context1, code + " => first context OK" );
assert.strictEqual( this[ 1 ], context2, code + " => second context OK" );
} else {
- ok( false, code + " => resolve" );
+ assert.ok( false, code + " => resolve" );
}
- }).fail(function( a, b ) {
+ } ).fail( function( a, b ) {
if ( shouldError ) {
assert.deepEqual( [ a, b ], expected, code + " => reject" );
} else {
- ok( false, code + " => reject" );
+ assert.ok( false, code + " => reject" );
}
- }).progress(function( a, b ) {
+ } ).progress( function( a, b ) {
assert.deepEqual( [ a, b ], expectedNotify, code + " => progress" );
assert.strictEqual( this[ 0 ], expectedNotify[ 0 ] ? context1 : undefined, code + " => first context OK" );
assert.strictEqual( this[ 1 ], expectedNotify[ 1 ] ? context2 : undefined, code + " => second context OK" );
- });
- });
- });
+ } );
+ } );
+ } );
deferreds.futureSuccess.resolve( 1 );
deferreds.futureError.reject( 0 );
-});
+} );
QUnit.test( "jQuery.when - resolved", function( assert ) {
assert.expect( 6 );
b = jQuery.Deferred().notify( 2 ).resolve( 5 ),
c = jQuery.Deferred().notify( 3 ).resolve( 6 );
- jQuery.when( a, b, c ).progress(function( a, b, c ) {
+ jQuery.when( a, b, c ).progress( function( a, b, c ) {
assert.strictEqual( a, 1, "first notify value ok" );
assert.strictEqual( b, 2, "second notify value ok" );
assert.strictEqual( c, 3, "third notify value ok" );
- }).done(function( a, b, c ) {
+ } ).done( function( a, b, c ) {
assert.strictEqual( a, 4, "first resolve value ok" );
assert.strictEqual( b, 5, "second resolve value ok" );
assert.strictEqual( c, 6, "third resolve value ok" );
- }).fail(function() {
+ } ).fail( function() {
assert.ok( false, "Error on resolve" );
- });
+ } );
-});
+} );
QUnit.module( "deprecated", { teardown: moduleTeardown } );
-
QUnit.test( "bind/unbind", function( assert ) {
assert.expect( 4 );
assert.equal( e.type, "click", "correct event type" );
assert.equal( e.data.bindData, 19, "correct trigger data" );
assert.equal( trig, 42, "correct bind data" );
- assert.equal( e.target.nodeName.toLowerCase(), "b" , "correct element" );
+ assert.equal( e.target.nodeName.toLowerCase(), "b", "correct element" );
} )
.trigger( "click", [ 42 ] )
.unbind( "click" )
markup
.delegate( "b", "click", function( e ) {
assert.equal( e.type, "click", "correct event type" );
- assert.equal( e.target.nodeName.toLowerCase(), "b" , "correct element" );
+ assert.equal( e.target.nodeName.toLowerCase(), "b", "correct element" );
} )
.find( "b" )
.trigger( "click" )
.end()
.undelegate( "b", "click" )
.remove();
-} );
\ No newline at end of file
+} );
assert.equal( $divChild.height(), $divNormal.height(), "child of a hidden element height() is wrong see #9441" );
assert.equal( $divChild.innerHeight(), $divNormal.innerHeight(), "child of a hidden element innerHeight() is wrong see #9441" );
assert.equal( $divChild.outerHeight(), $divNormal.outerHeight(), "child of a hidden element outerHeight() is wrong see #9441" );
- assert.equal( $divChild.outerHeight(true), $divNormal.outerHeight( true ), "child of a hidden element outerHeight( true ) is wrong see #9300" );
+ assert.equal( $divChild.outerHeight( true ), $divNormal.outerHeight( true ), "child of a hidden element outerHeight( true ) is wrong see #9300" );
// tests that child div of an unconnected div works the same as a normal div
assert.equal( $divUnconnected.width(), $divNormal.width(), "unconnected element width() is wrong see #9441" );
assert.equal( $divUnconnected.height(), $divNormal.height(), "unconnected element height() is wrong see #9441" );
assert.equal( $divUnconnected.innerHeight(), $divNormal.innerHeight(), "unconnected element innerHeight() is wrong see #9441" );
assert.equal( $divUnconnected.outerHeight(), $divNormal.outerHeight(), "unconnected element outerHeight() is wrong see #9441" );
- assert.equal( $divUnconnected.outerHeight(true), $divNormal.outerHeight( true ), "unconnected element outerHeight( true ) is wrong see #9300" );
+ assert.equal( $divUnconnected.outerHeight( true ), $divNormal.outerHeight( true ), "unconnected element outerHeight( true ) is wrong see #9300" );
// teardown html
$divHiddenParent.remove();
assert.equal( $divChild.height(), $divNormal.height(), "child of a hidden element height() is wrong see #10413" );
assert.equal( $divChild.innerHeight(), $divNormal.innerHeight(), "child of a hidden element innerHeight() is wrong see #10413" );
assert.equal( $divChild.outerHeight(), $divNormal.outerHeight(), "child of a hidden element outerHeight() is wrong see #10413" );
- assert.equal( $divChild.outerHeight(true), $divNormal.outerHeight( true ), "child of a hidden element outerHeight( true ) is wrong see #10413" );
+ assert.equal( $divChild.outerHeight( true ), $divNormal.outerHeight( true ), "child of a hidden element outerHeight( true ) is wrong see #10413" );
// tests that child div of an unconnected div works the same as a normal div
assert.equal( $divUnconnected.width(), $divNormal.width(), "unconnected element width() is wrong see #10413" );
assert.equal( $divUnconnected.height(), $divNormal.height(), "unconnected element height() is wrong see #10413" );
assert.equal( $divUnconnected.innerHeight(), $divNormal.innerHeight(), "unconnected element innerHeight() is wrong see #10413" );
assert.equal( $divUnconnected.outerHeight(), $divNormal.outerHeight(), "unconnected element outerHeight() is wrong see #10413" );
- assert.equal( $divUnconnected.outerHeight(true), $divNormal.outerHeight( true ), "unconnected element outerHeight( true ) is wrong see #10413" );
+ assert.equal( $divUnconnected.outerHeight( true ), $divNormal.outerHeight( true ), "unconnected element outerHeight( true ) is wrong see #10413" );
// teardown html
$divHiddenParent.remove();
QUnit.test( "setters with and without box-sizing:border-box", function( assert ) {
assert.expect( 60 );
- var parent = jQuery( "#foo" ).css({ width: "200px", height: "200px", "font-size": "16px" }),
+ var parent = jQuery( "#foo" ).css( { width: "200px", height: "200px", "font-size": "16px" } ),
el_bb = jQuery( "<div style='margin:5px;padding:1px;border:2px solid black;box-sizing:border-box;'></div>" ).appendTo( parent ),
el = jQuery( "<div style='margin:5px;padding:1px;border:2px solid black;'></div>" ).appendTo( parent );
assert.expect( 2 );
var div,
- hiddendiv = jQuery("div.hidden");
+ hiddendiv = jQuery( "div.hidden" );
hiddendiv.hide().show();
- assert.equal( hiddendiv.css("display"), "block", "Make sure a pre-hidden div is visible." );
+ assert.equal( hiddendiv.css( "display" ), "block", "Make sure a pre-hidden div is visible." );
- div = jQuery("<div>").hide().appendTo("#qunit-fixture").show();
+ div = jQuery( "<div>" ).hide().appendTo( "#qunit-fixture" ).show();
assert.equal( div.css( "display" ), "block", "Make sure pre-hidden divs show" );
assert.expectJqData( this, div, "olddisplay" );
// #show-tests * is set display: none in CSS
- jQuery("#qunit-fixture").append("<div id='show-tests'><div><p><a href='#'></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div><table id='test-table'></table>");
+ jQuery( "#qunit-fixture" ).append( "<div id='show-tests'><div><p><a href='#'></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div><table id='test-table'></table>" );
old = jQuery( "#test-table" ).show().css( "display" ) !== "table";
jQuery( "#test-table" ).remove();
assert.expect( 15 );
// #show-tests * is set display: none in CSS
- jQuery("#qunit-fixture").append("<div id='show-tests'><div><p><a href='#'></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div><table id='test-table'></table>");
+ jQuery( "#qunit-fixture" ).append( "<div id='show-tests'><div><p><a href='#'></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div><table id='test-table'></table>" );
var test,
old = jQuery( "#test-table" ).show().css( "display" ) !== "table";
- jQuery("#test-table").remove();
+ jQuery( "#test-table" ).remove();
// Note: inline elements are expected to be inline-block
// because we're showing width/height
// Can't animate width/height inline
// See #14344
test = {
- "div" : "block",
- "p" : "block",
- "a" : "inline-block",
- "code" : "inline-block",
- "pre" : "block",
- "span" : "inline-block",
- "table" : old ? "block" : "table",
- "thead" : old ? "block" : "table-header-group",
- "tbody" : old ? "block" : "table-row-group",
- "tr" : old ? "block" : "table-row",
- "th" : old ? "block" : "table-cell",
- "td" : old ? "block" : "table-cell",
- "ul" : "block",
- "li" : old ? "block" : "list-item"
+ "div": "block",
+ "p": "block",
+ "a": "inline-block",
+ "code": "inline-block",
+ "pre": "block",
+ "span": "inline-block",
+ "table": old ? "block" : "table",
+ "thead": old ? "block" : "table-header-group",
+ "tbody": old ? "block" : "table-row-group",
+ "tr": old ? "block" : "table-row",
+ "th": old ? "block" : "table-cell",
+ "td": old ? "block" : "table-cell",
+ "ul": "block",
+ "li": old ? "block" : "list-item"
};
- jQuery.each(test, function(selector, expected) {
- var elem = jQuery(selector, "#show-tests").show(1, function() {
- assert.equal( elem.css("display"), expected, "Show using correct display type for " + selector );
- });
- });
+ jQuery.each( test, function( selector, expected ) {
+ var elem = jQuery( selector, "#show-tests" ).show( 1, function() {
+ assert.equal( elem.css( "display" ), expected, "Show using correct display type for " + selector );
+ } );
+ } );
this.clock.tick( 10 );
jQuery( "#show-tests" ).remove();
assert.expect( 3 );
// #show-tests * is set display: none in CSS
- jQuery("#qunit-fixture").append("<div id='show-tests'><span style='position:absolute;'>foo</span></div>");
+ jQuery( "#qunit-fixture" ).append( "<div id='show-tests'><span style='position:absolute;'>foo</span></div>" );
var $span = jQuery( "#show-tests span" ),
displayNone = $span.css( "display" ),
assert.expect( 11 );
var $elem,
- $elems = jQuery( [ { a:0 },{ a:0 } ] ),
+ $elems = jQuery( [ { a:0 }, { a:0 } ] ),
counter = 0;
assert.equal( jQuery.timers.length, 0, "Make sure no animation was running from another test" );
if ( t_w === "hide" ) {num++;}
if ( t_o.constructor === Number ) {num += 2;}
if ( t_w.constructor === Number ) {num += 2;}
- if ( t_h.constructor === Number ) {num +=2;}
+ if ( t_h.constructor === Number ) {num += 2;}
assert.expect( num );
elem.animate( anim, 50 );
- jQuery.when( elem ).done(function( elem ) {
+ jQuery.when( elem ).done( function( elem ) {
var cur_o, cur_w, cur_h, old_h;
elem = elem[ 0 ];
show: [ 1 ],
animate: [ { width: "show" } ]
},
- $divTest = jQuery("<div>test</div>"),
+ $divTest = jQuery( "<div>test</div>" ),
+
// parentNode = null
- $divEmpty = jQuery("<div/>"),
- $divNone = jQuery("<div style='display: none;'/>"),
- $divInline = jQuery("<div style='display: inline;'/>"),
+ $divEmpty = jQuery( "<div/>" ),
+ $divNone = jQuery( "<div style='display: none;'/>" ),
+ $divInline = jQuery( "<div style='display: inline;'/>" ),
clock = this.clock;
assert.strictEqual( $divTest.show()[ 0 ].style.display, "block", "set display with show() for element with parentNode = document fragment" );
assert.expectJqData( env, $divNone[ 0 ], "olddisplay" );
jQuery.each( methods, function( name, opt ) {
- jQuery.each([
+ jQuery.each( [
// parentNode = document fragment
- jQuery("<div>test</div>"),
+ jQuery( "<div>test</div>" ),
// parentNode = null
- jQuery("<div/>")
+ jQuery( "<div/>" )
], function() {
- var callback = [function () {
+ var callback = [ function() {
assert.strictEqual( this.style.display, "block", "set display to block with " + name );
assert.expectJqData( env, this, "olddisplay" );
- }];
+ } ];
jQuery.fn[ name ].apply( this, opt.concat( callback ) );
- });
- });
+ } );
+ } );
clock.tick( 400 );
} );
this.clock.tick( 10 );
} );
-QUnit.test("Animation callbacks (#11797)", function( assert ) {
+QUnit.test( "Animation callbacks (#11797)", function( assert ) {
assert.expect( 16 );
var prog = 0,
always: function() {
assert.step( 5 );
}
- }).finish();
+ } ).finish();
this.clock.tick( dur + 10 );
} );
clock.tick( 800 );
} );
-QUnit.test( "Animation should go to its end state if document.hidden = true", function(assert) {
- assert.expect(1);
+QUnit.test( "Animation should go to its end state if document.hidden = true", function( assert ) {
+ assert.expect( 1 );
var height;
if ( Object.defineProperty ) {
get: function() {
return true;
}
- });
+ } );
} catch ( e ) {}
} else {
document.hidden = true;
}
if ( document.hidden ) {
- height = jQuery( "#qunit-fixture" ).animate({ height: 500 } ).height();
+ height = jQuery( "#qunit-fixture" ).animate( { height: 500 } ).height();
assert.equal( height, 500, "Animation should happen immediately if document.hidden = true" );
jQuery( document ).removeProp( "hidden" );
} else {
assert.ok( true, "Can't run the test since we can't reproduce correct environment for it" );
}
-});
+} );
QUnit.test( "jQuery.easing._default (gh-2218)", function( assert ) {
assert.expect( 2 );
if ( jQuery.fn.click ) {
- QUnit.test("trigger() shortcuts", function( assert ) {
+ QUnit.test( "trigger() shortcuts", function( assert ) {
assert.expect( 6 );
var counter, clickCounter,
- elem = jQuery("<li><a href='#'>Change location</a></li>").prependTo("#firstUL");
- elem.find("a").on("click", function() {
- var close = jQuery("spanx", this); // same with jQuery(this).find("span");
+ elem = jQuery( "<li><a href='#'>Change location</a></li>" ).prependTo( "#firstUL" );
+ elem.find( "a" ).on( "click", function() {
+ var close = jQuery( "spanx", this ); // same with jQuery(this).find("span");
assert.equal( close.length, 0, "Context element does not exist, length must be zero" );
- assert.ok( !close[0], "Context element does not exist, direct access to element must return undefined" );
+ assert.ok( !close[ 0 ], "Context element does not exist, direct access to element must return undefined" );
return false;
- }).click();
+ } ).click();
// manually clean up detached elements
elem.remove();
- jQuery("#check1").click(function() {
+ jQuery( "#check1" ).click( function() {
assert.ok( true, "click event handler for checkbox gets fired twice, see #815" );
- }).click();
+ } ).click();
counter = 0;
- jQuery("#firstp")[0].onclick = function() {
+ jQuery( "#firstp" )[ 0 ].onclick = function() {
counter++;
};
- jQuery("#firstp").click();
+ jQuery( "#firstp" ).click();
assert.equal( counter, 1, "Check that click, triggers onclick event handler also" );
clickCounter = 0;
- jQuery("#simon1")[0].onclick = function() {
+ jQuery( "#simon1" )[ 0 ].onclick = function() {
clickCounter++;
};
- jQuery("#simon1").click();
+ jQuery( "#simon1" ).click();
assert.equal( clickCounter, 1, "Check that click, triggers onclick event handler on an a tag also" );
- elem = jQuery("<img />").load(function(){
- assert.ok( true, "Trigger the load event, using the shortcut .load() (#2819)");
- }).load();
+ elem = jQuery( "<img />" ).load( function() {
+ assert.ok( true, "Trigger the load event, using the shortcut .load() (#2819)" );
+ } ).load();
// manually clean up detached elements
elem.remove();
// test that special handlers do not blow up with VML elements (#7071)
- jQuery("<xml:namespace ns='urn:schemas-microsoft-com:vml' prefix='v' />").appendTo("head");
- jQuery("<v:oval id='oval' style='width:100pt;height:75pt;' fillcolor='red'> </v:oval>").appendTo("#form");
- jQuery("#oval").click().keydown();
- });
+ jQuery( "<xml:namespace ns='urn:schemas-microsoft-com:vml' prefix='v' />" ).appendTo( "head" );
+ jQuery( "<v:oval id='oval' style='width:100pt;height:75pt;' fillcolor='red'> </v:oval>" ).appendTo( "#form" );
+ jQuery( "#oval" ).click().keydown();
+ } );
}
-QUnit.test("trigger() bubbling", function( assert ) {
+QUnit.test( "trigger() bubbling", function( assert ) {
assert.expect( 18 );
var win = 0, doc = 0, html = 0, body = 0, main = 0, ap = 0;
//$child.on("foo", error );
event = new jQuery.Event( "foo" );
- $child.trigger( event, [ 1,2,3 ] ).off();
+ $child.trigger( event, [ 1, 2, 3 ] ).off();
assert.equal( event.result, "result", "Check event.result attribute" );
// Will error if it bubbles
.appendTo( $foo.find( "#sap" ) );
if ( !test() ) {
- fireNative( $comment[0], "DOMNodeInserted" );
+ fireNative( $comment[ 0 ], "DOMNodeInserted" );
}
} );
jQuery( "#donor-input" ).trigger( "focus" );
} );
-
QUnit[ jQuery.fn.click ? "test" : "skip" ]( "trigger() shortcuts", function( assert ) {
assert.expect( 5 );
var element = jQuery( "<select><option>Foo</option><option selected>Bar</option><option selected>Baz</option></select>" );
function getSelectedOptions( collection ) {
- return collection.find( "option" ).filter(function( option ) {
+ return collection.find( "option" ).filter( function( option ) {
return option.selected;
} );
}
assert.expect( 2 );
// Simulates a browser without gBCR on elements, we just want to return 0,0
- var result = jQuery({ ownerDocument: document }).offset();
+ var result = jQuery( { ownerDocument: document } ).offset();
assert.equal( result.top, 0, "Check top" );
assert.equal( result.left, 0, "Check left" );
-});
+} );
QUnit.test( "disconnected node", function( assert ) {
assert.expect( 2 );
// These tests are solely for master/compat consistency
// Retrieving offset on disconnected/hidden elements is not officially
// valid input, but will return zeros for back-compat
- equal( result.top, 0, "Check top" );
- equal( result.left, 0, "Check left" );
+ assert.equal( result.top, 0, "Check top" );
+ assert.equal( result.left, 0, "Check left" );
} );
QUnit.test( "hidden (display: none) element", function( assert ) {
assert.t( "ID selector with existing ID descendant", "#firstp #simon1", [ "simon1" ] );
assert.t( "ID selector with non-existent descendant", "#firstp #foobar", [] );
assert.t( "ID selector using UTF8", "#台北Táiběi", [ "台北Táiběi" ] );
- assert.t( "Multiple ID selectors using UTF8", "#台北Táiběi, #台北", [ "台北Táiběi","台北" ] );
+ assert.t( "Multiple ID selectors using UTF8", "#台北Táiběi, #台北", [ "台北Táiběi", "台北" ] );
assert.t( "Descendant ID selector using UTF8", "div #台北", [ "台北" ] );
assert.t( "Child ID selector using UTF8", "form > #台北", [ "台北" ] );
QUnit.test( "child and adjacent", function( assert ) {
assert.expect( 27 );
- assert.t( "Child", "p > a", [ "simon1","google","groups","mark","yahoo","simon" ] );
- assert.t( "Child", "p> a", [ "simon1","google","groups","mark","yahoo","simon" ] );
- assert.t( "Child", "p >a", [ "simon1","google","groups","mark","yahoo","simon" ] );
- assert.t( "Child", "p>a", [ "simon1","google","groups","mark","yahoo","simon" ] );
- assert.t( "Child w/ Class", "p > a.blog", [ "mark","simon" ] );
- assert.t( "All Children", "code > *", [ "anchor1","anchor2" ] );
- assert.t( "All Grandchildren", "p > * > *", [ "anchor1","anchor2" ] );
- assert.t( "Adjacent", "p + p", [ "ap","en","sap" ] );
+ assert.t( "Child", "p > a", [ "simon1", "google", "groups", "mark", "yahoo", "simon" ] );
+ assert.t( "Child", "p> a", [ "simon1", "google", "groups", "mark", "yahoo", "simon" ] );
+ assert.t( "Child", "p >a", [ "simon1", "google", "groups", "mark", "yahoo", "simon" ] );
+ assert.t( "Child", "p>a", [ "simon1", "google", "groups", "mark", "yahoo", "simon" ] );
+ assert.t( "Child w/ Class", "p > a.blog", [ "mark", "simon" ] );
+ assert.t( "All Children", "code > *", [ "anchor1", "anchor2" ] );
+ assert.t( "All Grandchildren", "p > * > *", [ "anchor1", "anchor2" ] );
+ assert.t( "Adjacent", "p + p", [ "ap", "en", "sap" ] );
assert.t( "Adjacent", "p#firstp + p", [ "ap" ] );
assert.t( "Adjacent", "p[lang=en] + p", [ "sap" ] );
assert.t( "Adjacent", "a.GROUPS + code + a", [ "mark" ] );
assert.t( "Attribute Equals", "#qunit-fixture a[rel=bookmark]", [ "simon1" ] );
assert.t( "Attribute Equals", "#qunit-fixture a[href='http://www.google.com/']", [ "google" ] );
assert.t( "Attribute Equals", "#qunit-fixture a[ rel = 'bookmark' ]", [ "simon1" ] );
- assert.t( "Attribute Equals Number", "#qunit-fixture option[value='1']", [ "option1b","option2b","option3b","option4b","option5c" ] );
+ assert.t( "Attribute Equals Number", "#qunit-fixture option[value='1']", [ "option1b", "option2b", "option3b", "option4b", "option5c" ] );
assert.t( "Attribute Equals Number", "#qunit-fixture li[tabIndex='-1']", [ "foodWithNegativeTabIndex" ] );
document.getElementById( "anchor2" ).href = "#2";
assert.t( "Attribute selector using UTF8", "span[lang=中文]", [ "台北" ] );
- assert.t( "Attribute Begins With", "a[href ^= 'http://www']", [ "google","yahoo" ] );
+ assert.t( "Attribute Begins With", "a[href ^= 'http://www']", [ "google", "yahoo" ] );
assert.t( "Attribute Ends With", "a[href $= 'org/']", [ "mark" ] );
- assert.t( "Attribute Contains", "a[href *= 'google']", [ "google","groups" ] );
+ assert.t( "Attribute Contains", "a[href *= 'google']", [ "google", "groups" ] );
if ( jQuery.find.compile ) {
- assert.t( "Empty values", "#select1 option[value!='']", [ "option1b","option1c","option1d" ] );
- assert.t( "Attribute Is Not Equal", "#ap a[hreflang!='en']", [ "google","groups","anchor1" ] );
+ assert.t( "Empty values", "#select1 option[value!='']", [ "option1b", "option1c", "option1d" ] );
+ assert.t( "Attribute Is Not Equal", "#ap a[hreflang!='en']", [ "google", "groups", "anchor1" ] );
assert.t( "Select options via :selected", "#select1 option:selected", [ "option1a" ] );
assert.t( "Select options via :selected", "#select2 option:selected", [ "option2d" ] );
assert.t( "Select options via :selected", "#select3 option:selected", [ "option3b", "option3c" ] );
assert.t( "Empty values", "#select1 option[value='']", [ "option1a" ] );
-
assert.t( "Grouped Form Elements", "input[name='foo[bar]']", [ "hidden2" ] );
// Make sure attribute value quoting works correctly. See jQuery #6093; #6428; #13894
assert.ok( "skip", ":input not supported in selector-native" );
}
-
// #11115
assert.ok( jQuery( "<input type='checkbox' checked='checked'/>" ).prop( "checked", false ).is( "[checked]" ),
"[checked] selects by attribute (positive)"
params = { "foo":"bar", "baz":42, "quux":"All your base are belong to us" };
assert.equal( jQuery.param( params ), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" );
- params = { "string":"foo","null":null,"undefined":undefined };
+ params = { "string":"foo", "null":null, "undefined":undefined };
assert.equal( jQuery.param( params ), "string=foo&null=&undefined=", "handle nulls and undefineds properly" );
params = { "someName": [ 1, 2, 3 ], "regularThing": "blah" };
params = { "foo": { "bar": "baz", "beep": 42, "quux": "All your base are belong to us" } };
assert.equal( jQuery.param( params ), "foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All+your+base+are+belong+to+us", "even more arrays" );
- params = { a:[ 1,2 ], b:{ c:3, d:[ 4,5 ], e:{ x:[ 6 ], y:7, z:[ 8,9 ] }, f:true, g:false, h:undefined }, i:[ 10,11 ], j:true, k:false, l:[ undefined,0 ], m:"cowboy hat?" };
+ params = { a:[ 1, 2 ], b:{ c:3, d:[ 4, 5 ], e:{ x:[ 6 ], y:7, z:[ 8, 9 ] }, f:true, g:false, h:undefined }, i:[ 10, 11 ], j:true, k:false, l:[ undefined, 0 ], m:"cowboy hat?" };
assert.equal( decodeURIComponent( jQuery.param( params ) ), "a[]=1&a[]=2&b[c]=3&b[d][]=4&b[d][]=5&b[e][x][]=6&b[e][y]=7&b[e][z][]=8&b[e][z][]=9&b[f]=true&b[g]=false&b[h]=&i[]=10&i[]=11&j=true&k=false&l[]=&l[]=0&m=cowboy+hat?", "huge structure" );
params = { "a": [ 0, [ 1, 2 ], [ 3, [ 4, 5 ], [ 6 ] ], { "b": [ 7, [ 8, 9 ], [ { "c": 10, "d": 11 } ], [ [ 12 ] ], [ [ [ 13 ] ] ], { "e": { "f": { "g": [ 14, [ 15 ] ] } } }, 16 ] }, 17 ] };
assert.equal( decodeURIComponent( jQuery.param( params ) ), "a[]=0&a[1][]=1&a[1][]=2&a[2][]=3&a[2][1][]=4&a[2][1][]=5&a[2][2][]=6&a[3][b][]=7&a[3][b][1][]=8&a[3][b][1][]=9&a[3][b][2][0][c]=10&a[3][b][2][0][d]=11&a[3][b][3][0][]=12&a[3][b][4][0][0][]=13&a[3][b][5][e][f][g][]=14&a[3][b][5][e][f][g][1][]=15&a[3][b][]=16&a[]=17", "nested arrays" );
- params = { "a":[ 1,2 ], "b":{ "c":3, "d":[ 4,5 ], "e":{ "x":[ 6 ], "y":7, "z":[ 8,9 ] }, "f":true, "g":false, "h":undefined }, "i":[ 10,11 ], "j":true, "k":false, "l":[ undefined,0 ], "m":"cowboy hat?" };
+ params = { "a":[ 1, 2 ], "b":{ "c":3, "d":[ 4, 5 ], "e":{ "x":[ 6 ], "y":7, "z":[ 8, 9 ] }, "f":true, "g":false, "h":undefined }, "i":[ 10, 11 ], "j":true, "k":false, "l":[ undefined, 0 ], "m":"cowboy hat?" };
assert.equal( jQuery.param( params, true ), "a=1&a=2&b=%5Bobject+Object%5D&i=10&i=11&j=true&k=false&l=&l=0&m=cowboy+hat%3F", "huge structure, forced traditional" );
- assert.equal( decodeURIComponent( jQuery.param( { "a": [ 1,2,3 ], "b[]": [ 4,5,6 ], "c[d]": [ 7,8,9 ], "e": { "f": [ 10 ], "g": [ 11,12 ], "h": 13 } } ) ), "a[]=1&a[]=2&a[]=3&b[]=4&b[]=5&b[]=6&c[d][]=7&c[d][]=8&c[d][]=9&e[f][]=10&e[g][]=11&e[g][]=12&e[h]=13", "Make sure params are not double-encoded." );
+ assert.equal( decodeURIComponent( jQuery.param( { "a": [ 1, 2, 3 ], "b[]": [ 4, 5, 6 ], "c[d]": [ 7, 8, 9 ], "e": { "f": [ 10 ], "g": [ 11, 12 ], "h": 13 } } ) ), "a[]=1&a[]=2&a[]=3&b[]=4&b[]=5&b[]=6&c[d][]=7&c[d][]=8&c[d][]=9&e[f][]=10&e[g][]=11&e[g][]=12&e[h]=13", "Make sure params are not double-encoded." );
// #7945
assert.equal( jQuery.param( { "jquery": "1.4.2" } ), "jquery=1.4.2", "Check that object with a jQuery property get serialized correctly" );
params = { "foo[bar]":"baz", "foo[beep]":42, "foo[quux]":"All your base are belong to us" };
assert.equal( jQuery.param( params ), "foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All+your+base+are+belong+to+us", "even more arrays" );
- params = { a:[ 1,2 ], b:{ c:3, d:[ 4,5 ], e:{ x:[ 6 ], y:7, z:[ 8,9 ] }, f:true, g:false, h:undefined }, i:[ 10,11 ], j:true, k:false, l:[ undefined,0 ], m:"cowboy hat?" };
+ params = { a:[ 1, 2 ], b:{ c:3, d:[ 4, 5 ], e:{ x:[ 6 ], y:7, z:[ 8, 9 ] }, f:true, g:false, h:undefined }, i:[ 10, 11 ], j:true, k:false, l:[ undefined, 0 ], m:"cowboy hat?" };
assert.equal( jQuery.param( params ), "a=1&a=2&b=%5Bobject+Object%5D&i=10&i=11&j=true&k=false&l=&l=0&m=cowboy+hat%3F", "huge structure" );
params = { "a": [ 0, [ 1, 2 ], [ 3, [ 4, 5 ], [ 6 ] ], { "b": [ 7, [ 8, 9 ], [ { "c": 10, d: 11 } ], [ [ 12 ] ], [ [ [ 13 ] ] ], { "e": { "f": { "g": [ 14, [ 15 ] ] } } }, 16 ] }, 17 ] };
assert.equal( jQuery.param( params ), "a=0&a=1%2C2&a=3%2C4%2C5%2C6&a=%5Bobject+Object%5D&a=17", "nested arrays (not possible when jQuery.param.traditional == true)" );
- params = { a:[ 1,2 ], b:{ c:3, d:[ 4,5 ], e:{ x:[ 6 ], y:7, z:[ 8,9 ] }, f:true, g:false, h:undefined }, i:[ 10,11 ], j:true, k:false, l:[ undefined,0 ], m:"cowboy hat?" };
+ params = { a:[ 1, 2 ], b:{ c:3, d:[ 4, 5 ], e:{ x:[ 6 ], y:7, z:[ 8, 9 ] }, f:true, g:false, h:undefined }, i:[ 10, 11 ], j:true, k:false, l:[ undefined, 0 ], m:"cowboy hat?" };
assert.equal( decodeURIComponent( jQuery.param( params, false ) ), "a[]=1&a[]=2&b[c]=3&b[d][]=4&b[d][]=5&b[e][x][]=6&b[e][y]=7&b[e][z][]=8&b[e][z][]=9&b[f]=true&b[g]=false&b[h]=&i[]=10&i[]=11&j=true&k=false&l[]=&l[]=0&m=cowboy+hat?", "huge structure, forced not traditional" );
params = { "param1": null };
assert.ok( true, "no ajax; skipping jQuery.support['" + i + "']" );
}
}
- });
+ } );
} )();