"../traversing",
"../manipulation",
"../selector",
+
// Optional event/alias dependency
"../event/alias"
], function( jQuery ) {
// http://weblogs.java.net/blog/driscoll/archive/2009/09/08/eval-javascript-global-context
globalEval: function( data ) {
if ( data && jQuery.trim( data ) ) {
+
// We use execScript on Internet Explorer
// We use an anonymous function so that context is window
// rather than jQuery in Firefox
// Inject the element directly into the jQuery object
this.length = 1;
- this[0] = elem;
+ this[ 0 ] = elem;
}
this.context = document;
// HANDLE: $(DOMElement)
} else if ( selector.nodeType ) {
- this.context = this[0] = selector;
+ this.context = this[ 0 ] = selector;
this.length = 1;
return this;
values[ index ] = jQuery._data( elem, "olddisplay" );
display = elem.style.display;
if ( show ) {
+
// Reset the inline display of this element to learn if it is
// being hidden by cascaded rules or not
if ( !values[ index ] && display === "none" ) {
// in a stylesheet to whatever the default browser style is
// for such an element
if ( elem.style.display === "" && isHidden( elem ) ) {
- values[ index ] = jQuery._data( elem, "olddisplay", defaultDisplay(elem.nodeName) );
+ values[ index ] = jQuery._data( elem, "olddisplay", defaultDisplay( elem.nodeName ) );
}
} else {
hidden = isHidden( elem );
-define([
+define( [
"../core",
"../var/document",
"../manipulation" // appendTo
* @param {String} name nodeName of the element
* @param {Object} doc Document object
*/
+
// Called only from within defaultDisplay
function actualDisplay( name, doc ) {
var elem = jQuery( doc.createElement( name ) ).appendTo( doc.body ),
if ( display === "none" || !display ) {
// Use the already-created iframe if possible
- iframe = (iframe || jQuery( "<iframe frameborder='0' width='0' height='0'/>" ))
+ iframe = ( iframe || jQuery( "<iframe frameborder='0' width='0' height='0'/>" ) )
.appendTo( doc.documentElement );
// Always write a new HTML skeleton so Webkit and Firefox don't choke on reuse
}
return defaultDisplay;
-});
+} );
for ( name in obj ) {
// if the public data object is empty, the private is still empty
- if ( name === "data" && jQuery.isEmptyObject( obj[name] ) ) {
+ if ( name === "data" && jQuery.isEmptyObject( obj[ name ] ) ) {
continue;
}
if ( name !== "toJSON" ) {
// Avoid doing any more work than we need to when trying to get data on an
// object that has no data at all
- if ( (!id || !cache[id] || (!pvt && !cache[id].data)) &&
+ if ( ( !id || !cache[ id ] || ( !pvt && !cache[ id ].data ) ) &&
data === undefined && typeof name === "string" ) {
return;
}
if ( name in thisCache ) {
name = [ name ];
} else {
- name = name.split(" ");
+ name = name.split( " " );
}
}
} else {
+
// If "name" is an array of keys...
// When data is initially created, via ("key", "val") signature,
// keys will be converted to camelCase.
i = name.length;
while ( i-- ) {
- delete thisCache[ name[i] ];
+ delete thisCache[ name[ i ] ];
}
// If there is no data left in the cache, we want to continue
"./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 ( values === progressValues ) {
deferred.notifyWith( contexts, values );
- } else if ( !(--remaining) ) {
+ } else if ( !( --remaining ) ) {
deferred.resolveWith( contexts, values );
}
};
// height/width overflow pass
if ( elem.nodeType === 1 && ( "height" in props || "width" in props ) ) {
+
// Make sure that nothing sneaks out
// Record all 3 overflow attributes because IE does not
// change the overflow attribute when overflowX and
if ( hidden ) {
jQuery( elem ).show();
} else {
- anim.done(function() {
+ anim.done( function() {
jQuery( elem ).hide();
- });
+ } );
}
- anim.done(function() {
+ anim.done( function() {
var prop;
jQuery._removeData( elem, "fxshow" );
for ( prop in orig ) {
jQuery.style( elem, prop, orig[ prop ] );
}
- });
+ } );
for ( prop in orig ) {
tween = createTween( hidden ? dataShow[ prop ] : 0, prop, anim );
}
// If this is a noop like .hide().hide(), restore an overwritten display value
- } else if ( (display === "none" ? defaultDisplay( elem.nodeName ) : display) === "inline" ) {
+ } else if ( ( display === "none" ? defaultDisplay( elem.nodeName ) : display ) === "inline" ) {
style.display = display;
}
}
"../event"
], function( jQuery ) {
-jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblclick " +
+jQuery.each( ( "blur focus focusin focusout load resize scroll unload click dblclick " +
"mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +
- "change select submit keydown keypress keyup error contextmenu").split(" "),
+ "change select submit keydown keypress keyup error contextmenu" ).split( " " ),
function( i, name ) {
// Handle event binding
return jQuery.nodeName( elem, "table" ) &&
jQuery.nodeName( content.nodeType !== 11 ? content : content.firstChild, "tr" ) ?
- elem.getElementsByTagName("tbody")[0] ||
- elem.appendChild( elem.ownerDocument.createElement("tbody") ) :
+ elem.getElementsByTagName( "tbody" )[ 0 ] ||
+ elem.appendChild( elem.ownerDocument.createElement( "tbody" ) ) :
elem;
}
jQuery.fn.extend( {
wrapAll: function( html ) {
if ( jQuery.isFunction( html ) ) {
- return this.each(function(i) {
- jQuery(this).wrapAll( html.call(this, i) );
- });
+ return this.each( function( i ) {
+ jQuery( this ).wrapAll( html.call( this, i ) );
+ } );
}
- if ( this[0] ) {
+ if ( this[ 0 ] ) {
+
// The elements to wrap the target around
- var wrap = jQuery( html, this[0].ownerDocument ).eq(0).clone(true);
+ var wrap = jQuery( html, this[ 0 ].ownerDocument ).eq( 0 ).clone( true );
- if ( this[0].parentNode ) {
- wrap.insertBefore( this[0] );
+ if ( this[ 0 ].parentNode ) {
+ wrap.insertBefore( this[ 0 ] );
}
wrap.map( function() {
-{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,
assert.ok( true, "success" );
},
fail: function() {
- if (jQuery.support.cors === false) {
+ if ( jQuery.support.cors === false ) {
assert.ok( true, "fail" );
}
},
} );
test( "#11743 - jQuery.ajax() - script, throws exception", 1, function() {
- throws(function() {
- jQuery.ajax({
+ throws( function() {
+ jQuery.ajax( {
url: "data/badjson.js",
dataType: "script",
"throws": true,
+
// TODO find a way to test this asynchronously, too
async: false,
+
// Global events get confused by the exception
global: false,
success: function() {
error: function() {
ok( false, "Error." );
}
- });
+ } );
}, "exception bubbled" );
- });
+ } );
jQuery.each( [ "method", "type" ], function( _, globalOption ) {
function request( assert, option ) {
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 ) {
assert.strictEqual( cb.has(), true, "Check if unique list has callback function(s) attached" );
cb.lock();
strictEqual( cb.has(), false, "locked() list is empty and returns false" );
-});
+} );
QUnit.test( "jQuery.Callbacks() - adding a string doesn't cause a stack overflow", 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;
// Basic constructor's behavior
equal( jQuery().length, 0, "jQuery() === jQuery([])" );
- equal( jQuery(undefined).length, 0, "jQuery(undefined) === jQuery([])" );
- equal( jQuery(null).length, 0, "jQuery(null) === jQuery([])" );
- equal( jQuery("").length, 0, "jQuery('') === jQuery([])" );
- equal( jQuery("#").length, 0, "jQuery('#') === jQuery([])" );
+ equal( jQuery( undefined ).length, 0, "jQuery(undefined) === jQuery([])" );
+ equal( jQuery( null ).length, 0, "jQuery(null) === jQuery([])" );
+ equal( jQuery( "" ).length, 0, "jQuery('') === jQuery([])" );
+ equal( jQuery( "#" ).length, 0, "jQuery('#') === jQuery([])" );
- equal( jQuery(obj).selector, "div", "jQuery(jQueryObj) == jQueryObj" );
+ equal( jQuery( obj ).selector, "div", "jQuery(jQueryObj) == jQueryObj" );
// can actually yield more than one, when iframes are included, the window is an array as well
assert.equal( jQuery( window ).length, 1, "Correct number of elements generated for jQuery(window)" );
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");
+ equal( elem[ 0 ].style.top, "1px", "jQuery() quick setter offset" );
}
if ( jQuery.fn.css ) {
equal( test.selector, "", "Body Selector" );
equal( test.context, document.body, "Body Context" );
- test = jQuery("#qunit-fixture");
+ test = jQuery( "#qunit-fixture" );
equal( test.selector, "#qunit-fixture", "#qunit-fixture Selector" );
equal( test.context, document, "#qunit-fixture Context" );
- test = jQuery("#notfoundnono");
+ test = jQuery( "#notfoundnono" );
equal( test.selector, "#notfoundnono", "#notfoundnono Selector" );
equal( test.context, document, "#notfoundnono Context" );
equal( test.selector, "#qunit-fixture", "#qunit-fixture Selector" );
equal( test.context, document.body, "#qunit-fixture Context" );
- test = jQuery( document.body ).find("#qunit-fixture");
+ test = jQuery( document.body ).find( "#qunit-fixture" );
equal( test.selector, "#qunit-fixture", "#qunit-fixture find Selector" );
equal( test.context, document.body, "#qunit-fixture find Context" );
-});
+} );
QUnit.test( "globalEval", function( assert ) {
expect( 2 );
- Globals.register("globalEvalTest");
+ Globals.register( "globalEvalTest" );
jQuery.globalEval( "var globalEvalTest = 2;" );
assert.equal( window.globalEvalTest, 2, "Test variable declarations are global" );
} );
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( 16 );
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 );
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" );
"Make sure that a string z-index is returned from css('z-index') (#14432)." );
} );
-
QUnit.test( "css() explicit and relative values", function( assert ) {
assert.expect( 29 );
hiddendiv = jQuery( "div.hidden" );
hiddendiv.hide();
- equal( hiddendiv.css("display"), "none", "Non-detached div hidden" );
+ equal( hiddendiv.css( "display" ), "none", "Non-detached div hidden" );
hiddendiv.show();
- equal( hiddendiv.css("display"), "block", "Pre-hidden div shown" );
+ equal( hiddendiv.css( "display" ), "block", "Pre-hidden div shown" );
- div = jQuery("<div>").hide();
- equal( div.css("display"), "none", "Detached div hidden" );
- div.appendTo("#qunit-fixture").show();
- equal( div.css("display"), "block", "Pre-hidden div shown" );
+ div = jQuery( "<div>" ).hide();
+ equal( div.css( "display" ), "none", "Detached div hidden" );
+ div.appendTo( "#qunit-fixture" ).show();
+ equal( div.css( "display" ), "block", "Pre-hidden div shown" );
} );
assert.expect( 18 );
var hiddendiv, div, pass, test;
- hiddendiv = jQuery("div.hidden");
+ hiddendiv = jQuery( "div.hidden" );
assert.equal( jQuery.css( hiddendiv[ 0 ], "display" ), "none", "hiddendiv is display: none" );
assert.ok( pass, "Show" );
// #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>");
+ 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>" );
test = {
"div": "block",
jQuery( "<div>test</div> text <span>test</span>" ).hide().remove();
} );
-test("show() resolves correct default display #8099", function() {
- expect(7);
- var tt8099 = jQuery("<tt/>").appendTo("body"),
- dfn8099 = jQuery("<dfn/>", { "html": "foo"}).appendTo("body");
+test( "show() resolves correct default display #8099", function() {
+ expect( 7 );
+ var tt8099 = jQuery( "<tt/>" ).appendTo( "body" ),
+ dfn8099 = jQuery( "<dfn/>", { "html": "foo" } ).appendTo( "body" );
- equal( tt8099.css("display"), "none", "default display override for all tt" );
- equal( tt8099.show().css("display"), "inline", "Correctly resolves display:inline" );
+ equal( tt8099.css( "display" ), "none", "default display override for all tt" );
+ equal( tt8099.show().css( "display" ), "inline", "Correctly resolves display:inline" );
- equal( jQuery("#foo").hide().show().css("display"), "block", "Correctly resolves display:block after hide/show" );
+ equal( jQuery( "#foo" ).hide().show().css( "display" ), "block", "Correctly resolves display:block after hide/show" );
- equal( tt8099.hide().css("display"), "none", "default display override for all tt" );
- equal( tt8099.show().css("display"), "inline", "Correctly resolves display:inline" );
+ equal( tt8099.hide().css( "display" ), "none", "default display override for all tt" );
+ equal( tt8099.show().css( "display" ), "inline", "Correctly resolves display:inline" );
- equal( dfn8099.css("display"), "none", "default display override for all dfn" );
- equal( dfn8099.show().css("display"), "inline", "Correctly resolves display:inline" );
+ equal( dfn8099.css( "display" ), "none", "default display override for all dfn" );
+ equal( dfn8099.show().css( "display" ), "inline", "Correctly resolves display:inline" );
tt8099.remove();
dfn8099.remove();
-});
+} );
QUnit.test( "show() resolves correct default display for detached nodes", function( assert ) {
assert.expect( 13 );
var div, span, tr, trDisplay;
- div = jQuery("<div class='hidden'>");
- div.show().appendTo("#qunit-fixture");
- equal( div.css("display"), "block", "Make sure a detached, pre-hidden( through stylesheets ) div is visible." );
+ div = jQuery( "<div class='hidden'>" );
+ div.show().appendTo( "#qunit-fixture" );
+ equal( div.css( "display" ), "block", "Make sure a detached, pre-hidden( through stylesheets ) div is visible." );
- div = jQuery("<div style='display: none'>");
- div.show().appendTo("#qunit-fixture");
- equal( div.css("display"), "block", "Make sure a detached, pre-hidden( through inline style ) div is visible." );
+ div = jQuery( "<div style='display: none'>" );
+ div.show().appendTo( "#qunit-fixture" );
+ equal( div.css( "display" ), "block", "Make sure a detached, pre-hidden( through inline style ) div is visible." );
- span = jQuery("<span class='hidden'/>");
- span.show().appendTo("#qunit-fixture");
- equal( span.css("display"), "inline", "Make sure a detached, pre-hidden( through stylesheets ) span has default display." );
+ span = jQuery( "<span class='hidden'/>" );
+ span.show().appendTo( "#qunit-fixture" );
+ equal( span.css( "display" ), "inline", "Make sure a detached, pre-hidden( through stylesheets ) span has default display." );
- span = jQuery("<span style='display: inline'/>");
- span.show().appendTo("#qunit-fixture");
- equal( span.css("display"), "inline", "Make sure a detached, pre-hidden( through inline style ) span has default display." );
+ span = jQuery( "<span style='display: inline'/>" );
+ span.show().appendTo( "#qunit-fixture" );
+ equal( span.css( "display" ), "inline", "Make sure a detached, pre-hidden( through inline style ) span has default display." );
- div = jQuery("<div><div class='hidden'></div></div>").children("div");
- div.show().appendTo("#qunit-fixture");
- equal( div.css("display"), "block", "Make sure a detached, pre-hidden( through stylesheets ) div inside another visible div is visible." );
+ div = jQuery( "<div><div class='hidden'></div></div>" ).children( "div" );
+ div.show().appendTo( "#qunit-fixture" );
+ equal( div.css( "display" ), "block", "Make sure a detached, pre-hidden( through stylesheets ) div inside another visible div is visible." );
- div = jQuery("<div><div style='display: none'></div></div>").children("div");
- div.show().appendTo("#qunit-fixture");
- equal( div.css("display"), "block", "Make sure a detached, pre-hidden( through inline style ) div inside another visible div is visible." );
+ div = jQuery( "<div><div style='display: none'></div></div>" ).children( "div" );
+ div.show().appendTo( "#qunit-fixture" );
+ equal( div.css( "display" ), "block", "Make sure a detached, pre-hidden( through inline style ) div inside another visible div is visible." );
div = jQuery( "div.hidden" );
div.detach().show();
- equal( div.css("display"), "block", "Make sure a detached( through detach() ), pre-hidden div is visible." );
+ equal( div.css( "display" ), "block", "Make sure a detached( through detach() ), pre-hidden div is visible." );
div.remove();
- span = jQuery("<span>");
- span.appendTo("#qunit-fixture").detach().show().appendTo("#qunit-fixture" );
- equal( span.css("display"), "inline", "Make sure a detached( through detach() ), pre-hidden span has default display." );
+ span = jQuery( "<span>" );
+ span.appendTo( "#qunit-fixture" ).detach().show().appendTo( "#qunit-fixture" );
+ equal( span.css( "display" ), "inline", "Make sure a detached( through detach() ), pre-hidden span has default display." );
span.remove();
- div = jQuery("<div>");
- div.show().appendTo("#qunit-fixture");
+ div = jQuery( "<div>" );
+ div.show().appendTo( "#qunit-fixture" );
ok( !!div.get( 0 ).style.display, "Make sure not hidden div has a inline style." );
div.remove();
- div = jQuery( document.createElement("div") );
- div.show().appendTo("#qunit-fixture");
- equal( div.css("display"), "block", "Make sure a pre-created element has default display." );
+ div = jQuery( document.createElement( "div" ) );
+ div.show().appendTo( "#qunit-fixture" );
+ equal( div.css( "display" ), "block", "Make sure a pre-created element has default display." );
div.remove();
- div = jQuery("<div style='display: inline'/>");
- div.show().appendTo("#qunit-fixture");
- equal( div.css("display"), "inline", "Make sure that element has same display when it was created." );
+ div = jQuery( "<div style='display: inline'/>" );
+ div.show().appendTo( "#qunit-fixture" );
+ equal( div.css( "display" ), "inline", "Make sure that element has same display when it was created." );
div.remove();
- tr = jQuery("<tr/>");
- jQuery("#table").append( tr );
+ tr = jQuery( "<tr/>" );
+ jQuery( "#table" ).append( tr );
trDisplay = tr.css( "display" );
tr.detach().hide().show();
equal( tr[ 0 ].style.display, trDisplay, "For detached tr elements, display should always be like for attached trs" );
tr.remove();
- span = jQuery("<span/>").hide().show();
+ span = jQuery( "<span/>" ).hide().show();
equal( span[ 0 ].style.display, "inline", "For detached span elements, display should always be inline" );
span.remove();
} );
-test("show() resolves correct default display #10227", 4, function() {
+test( "show() resolves correct default display #10227", 4, function() {
var htmlDisplay,
html = jQuery( document.documentElement ),
body = jQuery( "body" );
body.append( "<p class='ddisplay'>a<style>body{display:none}</style></p>" );
- equal( body.css("display"), "none", "Initial display for body element: none" );
+ equal( body.css( "display" ), "none", "Initial display for body element: none" );
body.show();
- equal( body.css("display"), "block", "Correct display for body element: block" );
+ equal( body.css( "display" ), "block", "Correct display for body element: block" );
body.append( "<p class='ddisplay'>a<style>html{display:none}</style></p>" );
- equal( html.css("display"), "none", "Initial display for html element: none" );
+ equal( html.css( "display" ), "none", "Initial display for html element: none" );
html.show();
htmlDisplay = html.css( "display" );
jQuery._removeData( body[ 0 ] );
jQuery._removeData( html[ 0 ] );
jQuery( ".ddisplay" ).remove();
-});
+} );
-test("show() resolves correct default display when iframe display:none #12904", function() {
- expect(2);
+test( "show() resolves correct default display when iframe display:none #12904", function() {
+ expect( 2 );
var ddisplay = jQuery(
"<p id='ddisplay'>a<style>p{display:none}iframe{display:none !important}</style></p>"
- ).appendTo("body");
+ ).appendTo( "body" );
- equal( ddisplay.css("display"), "none", "Initial display: none" );
+ equal( ddisplay.css( "display" ), "none", "Initial display: none" );
ddisplay.show();
- equal( ddisplay.css("display"), "block", "Correct display: block" );
+ equal( ddisplay.css( "display" ), "block", "Correct display: block" );
ddisplay.remove();
-});
+} );
QUnit.test( "toggle()", function( assert ) {
assert.expect( 9 );
var div = jQuery( "<div style='display:none'></div>" ).appendTo( "#qunit-fixture" );
assert.equal( div.css( "display" ), "none", "Element is hidden by default" );
div.hide();
- ok( !jQuery._data(div, "olddisplay"), "olddisplay is undefined after hiding an already-hidden element" );
+ ok( !jQuery._data( div, "olddisplay" ), "olddisplay is undefined after hiding an already-hidden element" );
div.show();
assert.equal( div.css( "display" ), "block", "Show a double-hidden element" );
assert.equal( $div.css( "marginRight" ), "0px",
"marginRight correctly calculated with a width and display block" );
- $div.css({
+ $div.css( {
position: "absolute",
top: 0,
left: 0,
width: "100px"
- });
- $child.css({
+ } );
+ $child.css( {
width: "50px",
margin: "auto"
- });
+ } );
assert.equal( $child.css( "marginLeft" ), "25px", "auto margins are computed to pixels" );
-});
+} );
QUnit.test( "box model properties incorrectly returning % instead of px, see #10639 and #12088", function( assert ) {
assert.expect( 2 );
}
);
-QUnit.test("certain css values of 'normal' should be convertable to a number, see #8627", function( assert ) {
- expect ( 3 );
+QUnit.test( "certain css values of 'normal' should be convertable to a number, see #8627", function( assert ) {
+ expect( 3 );
var el = jQuery( "<div style='letter-spacing:normal;font-weight:normal;'>test</div>" ).appendTo( "#qunit-fixture" );
assert.t( "Is Visible", "#qunit-fixture div:visible:lt(2)", [ "foo", "nothiddendiv" ] );
assert.t( "Is Not Hidden", "#qunit-fixture:hidden", [] );
- assert.t( "Is Hidden", "#form input:hidden", [ "hidden1","hidden2" ] );
+ assert.t( "Is Hidden", "#form input:hidden", [ "hidden1", "hidden2" ] );
$a = jQuery( "<a href='#'><h1>Header</h1></a>" ).appendTo( "#qunit-fixture" );
assert.ok( $a.is( ":visible" ), "Anchor tag with flow content is visible (gh-2227)" );
name: "backgroundAttachment",
value: [ "fixed" ],
expected: [ "scroll" ]
- },{
+ }, {
name: "backgroundColor",
value: [ "rgb(255, 0, 0)", "rgb(255,0,0)", "#ff0000" ],
expected: [ "transparent" ]
} );
asyncTest( "Make sure initialized display value for disconnected nodes is correct (#13310)", 4, function() {
- var display = jQuery("#display").css("display"),
- div = jQuery("<div/>");
+ var display = jQuery( "#display" ).css( "display" ),
+ div = jQuery( "<div/>" );
- equal( div.css( "display", "inline" ).hide().show().appendTo("body").css( "display" ), "inline", "Initialized display value has returned" );
+ equal( div.css( "display", "inline" ).hide().show().appendTo( "body" ).css( "display" ), "inline", "Initialized display value has returned" );
div.remove();
div.css( "display", "none" ).hide();
equal( jQuery._data( div[ 0 ], "olddisplay" ), undefined, "olddisplay is undefined after hiding a detached and hidden element" );
div.remove();
- div.css( "display", "inline-block" ).hide().appendTo("body").fadeIn(function() {
+ div.css( "display", "inline-block" ).hide().appendTo( "body" ).fadeIn( function() {
equal( div.css( "display" ), "inline-block", "Initialized display value has returned" );
div.remove();
start();
- });
+ } );
- equal( jQuery._data( jQuery("#display").css( "display", "inline" ).hide()[ 0 ], "olddisplay" ), display,
+ equal( jQuery._data( jQuery( "#display" ).css( "display", "inline" ).hide()[ 0 ], "olddisplay" ), display,
"display: * !Important value should used as initialized display" );
- jQuery._removeData( jQuery("#display")[ 0 ] );
-});
+ jQuery._removeData( jQuery( "#display" )[ 0 ] );
+} );
QUnit.test( "show() after hide() should always set display to initial value (#14750)", 1, function( assert ) {
var div = jQuery( "<div />" ),
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>" );
- equal( div.data("attr"), undefined, "Check for non-existing data-attr attribute" );
+ equal( div.data( "attr" ), undefined, "Check for non-existing data-attr attribute" );
- div.attr("data-attr", "exists");
- equal( div.data("attr"), "exists", "Check for existing data-attr attribute" );
+ div.attr( "data-attr", "exists" );
+ equal( div.data( "attr" ), "exists", "Check for existing data-attr attribute" );
- div.attr("data-attr", "exists2");
- equal( div.data("attr"), "exists", "Check that updates to data- don't update .data()" );
+ div.attr( "data-attr", "exists2" );
+ equal( div.data( "attr" ), "exists", "Check that updates to data- don't update .data()" );
- div.data("attr", "internal").attr("data-attr", "external");
- equal( div.data("attr"), "internal", "Check for .data('attr') precedence (internal > external data-* attribute)" );
+ div.data( "attr", "internal" ).attr( "data-attr", "external" );
+ equal( div.data( "attr" ), "internal", "Check for .data('attr') precedence (internal > external data-* attribute)" );
div.remove();
- child.appendTo("#qunit-fixture");
- equal( child.data("myobj"), "old data", "Value accessed from data-* attribute");
+ child.appendTo( "#qunit-fixture" );
+ equal( child.data( "myobj" ), "old data", "Value accessed from data-* attribute" );
child.data( "myobj", "replaced" );
assert.equal(
jQuery( elem ).data( "number" ), true, "Check number property"
);
assert.deepEqual(
- jQuery( elem ).data( "stuff" ), [ 2,8 ], "Check stuff property"
+ jQuery( elem ).data( "stuff" ), [ 2, 8 ], "Check stuff property"
);
break;
default:
}
);
+test( "jQuery.data supports interoperable hyphenated/camelCase get/set of properties with arbitrary non-null|NaN|undefined values", function() {
-test("jQuery.data supports interoperable hyphenated/camelCase get/set of properties with arbitrary non-null|NaN|undefined values", function() {
-
- var div = jQuery("<div/>", { id: "hyphened" }).appendTo("#qunit-fixture"),
+ var div = jQuery( "<div/>", { id: "hyphened" } ).appendTo( "#qunit-fixture" ),
datas = {
"non-empty": "a string",
"empty-string": "",
"an-object": {},
"bool-true": true,
"bool-false": false,
+
// JSHint enforces double quotes,
// but JSON strings need double quotes to parse
// so we need escaped double quotes here
deepEqual( div.data( key ), val, "get: " + key );
deepEqual( div.data( jQuery.camelCase( key ) ), val, "get: " + jQuery.camelCase( key ) );
- });
-});
+ } );
+} );
test( ".removeData supports removal of hyphenated properties via array (#12786)", function() {
expect( 4 );
var div, plain, compare;
- div = jQuery("<div>").appendTo("#qunit-fixture");
- plain = jQuery({});
+ div = jQuery( "<div>" ).appendTo( "#qunit-fixture" );
+ plain = jQuery( {} );
// When data is batch assigned (via plain object), the properties
// are not camel cased as they are with (property, value) calls
compare = {
+
// From batch assignment .data({ "a-a": 1 })
"a-a": 1,
+
// From property, value assignment .data( "b-b", 1 )
"bB": 1
};
// Mixed assignment
- div.data({ "a-a": 1 }).data( "b-b", 1 );
- plain.data({ "a-a": 1 }).data( "b-b", 1 );
+ div.data( { "a-a": 1 } ).data( "b-b", 1 );
+ plain.data( { "a-a": 1 } ).data( "b-b", 1 );
deepEqual( div.data(), compare, "Data appears as expected. (div)" );
deepEqual( plain.data(), compare, "Data appears as expected. (plain)" );
- div.removeData([ "a-a", "b-b" ]);
- plain.removeData([ "a-a", "b-b" ]);
+ div.removeData( [ "a-a", "b-b" ] );
+ plain.removeData( [ "a-a", "b-b" ] );
// NOTE: Timo's proposal for "propEqual" (or similar) would be nice here
deepEqual( div.data(), {}, "Data is empty. (div)" );
deepEqual( plain.data(), {}, "Data is empty. (plain)" );
-});
+} );
// Test originally by Moschel
QUnit.test( "Triggering the removeData should not throw exceptions. (#10080)", function( assert ) {
module( "deferred", {
teardown: moduleTeardown
-});
+} );
jQuery.each( [ "", " - new operator" ], function( _, withNew ) {
strictEqual( defer.pipe, defer.then, "pipe is an alias of then" );
- createDeferred().resolve().done(function() {
+ createDeferred().resolve().done( function() {
ok( true, "Success on resolve" );
strictEqual( this.state(), "resolved", "Deferred is resolved (state)" );
- }).fail(function() {
+ } ).fail( function() {
ok( false, "Error on resolve" );
- }).always(function() {
+ } ).always( function() {
ok( true, "Always callback on resolve" );
- });
+ } );
- createDeferred().reject().done(function() {
+ createDeferred().reject().done( function() {
ok( false, "Success on reject" );
- }).fail(function() {
+ } ).fail( function() {
ok( true, "Error on reject" );
strictEqual( this.state(), "rejected", "Deferred is rejected (state)" );
- }).always(function() {
+ } ).always( function() {
ok( true, "Always callback on reject" );
- });
+ } );
- createDeferred(function( defer ) {
+ createDeferred( function( defer ) {
ok( this === defer, "Defer passed as this & first argument" );
- this.resolve("done");
- }).done(function( value ) {
+ this.resolve( "done" );
+ } ).done( function( value ) {
strictEqual( value, "done", "Passed function executed" );
- });
+ } );
- createDeferred(function( defer ) {
+ createDeferred( function( defer ) {
var promise = defer.promise(),
func = function() {},
funcPromise = defer.promise( func );
if ( promise[ key ] !== func[ key ] ) {
strictEqual( func[ key ], promise[ key ], key + " is the same" );
}
- });
- });
+ } );
+ } );
jQuery.expandedEach = jQuery.each;
- jQuery.expandedEach( "resolve reject".split(" "), function( _, change ) {
- createDeferred(function( defer ) {
+ jQuery.expandedEach( "resolve reject".split( " " ), function( _, change ) {
+ createDeferred( function( defer ) {
strictEqual( defer.state(), "pending", "pending after creation" );
var checked = 0;
- defer.progress(function( value ) {
+ defer.progress( function( value ) {
strictEqual( value, checked, "Progress: right value (" + value + ") received" );
- });
+ } );
for ( checked = 0; checked < 3; checked++ ) {
defer.notify( checked );
}
defer[ change ]();
notStrictEqual( defer.state(), "pending", "not pending after " + change );
defer.notify();
- });
- });
- });
-});
-
+ } );
+ } );
+ } );
+} );
test( "jQuery.Deferred - chainability", function() {
expect( 10 );
jQuery.expandedEach = jQuery.each;
- jQuery.expandedEach( "resolve reject notify resolveWith rejectWith notifyWith done fail progress always".split(" "), function( _, method ) {
+ jQuery.expandedEach( "resolve reject notify resolveWith rejectWith notifyWith done fail progress always".split( " " ), function( _, method ) {
var object = {
m: defer[ method ]
};
strictEqual( object.m(), object, method + " is chainable" );
- });
-});
+ } );
+} );
test( "jQuery.Deferred.then - filtering (done)", function() {
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 );
strictEqual( value2, 3, "second resolve value ok" );
strictEqual( value3, 6, "result of filter ok" );
- jQuery.Deferred().reject().then(function() {
+ jQuery.Deferred().reject().then( function() {
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 ) {
strictEqual( value, undefined, "then done callback can return undefined/null" );
- });
-});
+ } );
+} );
test( "jQuery.Deferred.then - filtering (fail)", function() {
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 );
jQuery.Deferred().resolve().then( null, function() {
ok( false, "then should not be called on resolve" );
- });
+ } );
- jQuery.Deferred().reject().then( null, jQuery.noop ).fail(function( value ) {
+ jQuery.Deferred().reject().then( null, jQuery.noop ).fail( function( value ) {
strictEqual( value, undefined, "then fail callback can return undefined/null" );
- });
-});
+ } );
+} );
test( "jQuery.Deferred.then - filtering (progress)", function() {
defer = jQuery.Deferred(),
piped = defer.then( null, null, function( a, b ) {
return a * b;
- });
+ } );
- piped.progress(function( result ) {
+ piped.progress( function( result ) {
value3 = result;
- });
+ } );
- defer.progress(function( a, b ) {
+ defer.progress( function( a, b ) {
value1 = a;
value2 = b;
- });
+ } );
defer.notify( 2, 3 );
strictEqual( value1, 2, "first progress value ok" );
strictEqual( value2, 3, "second progress value ok" );
strictEqual( value3, 6, "result of filter ok" );
-});
+} );
test( "jQuery.Deferred.then - deferred (done)", function() {
var value1, value2, value3,
defer = jQuery.Deferred(),
- piped = defer.then(function( a, b ) {
- return jQuery.Deferred(function( defer ) {
+ piped = defer.then( function( a, b ) {
+ return jQuery.Deferred( function( defer ) {
defer.reject( a * b );
- });
- });
+ } );
+ } );
- piped.fail(function( result ) {
+ piped.fail( function( result ) {
value3 = result;
- });
+ } );
- defer.done(function( a, b ) {
+ defer.done( function( a, b ) {
value1 = a;
value2 = b;
- });
+ } );
defer.resolve( 2, 3 );
strictEqual( value1, 2, "first resolve value ok" );
strictEqual( value2, 3, "second resolve value ok" );
strictEqual( value3, 6, "result of filter ok" );
-});
+} );
test( "jQuery.Deferred.then - deferred (fail)", function() {
var value1, value2, value3,
defer = jQuery.Deferred(),
piped = defer.then( null, function( a, b ) {
- return jQuery.Deferred(function( defer ) {
+ return jQuery.Deferred( function( defer ) {
defer.resolve( a * b );
- });
- });
+ } );
+ } );
- piped.done(function( result ) {
+ piped.done( 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" );
-});
+} );
test( "jQuery.Deferred.then - deferred (progress)", function() {
var value1, value2, value3,
defer = jQuery.Deferred(),
piped = defer.then( null, null, function( a, b ) {
- return jQuery.Deferred(function( defer ) {
+ return jQuery.Deferred( function( defer ) {
defer.resolve( a * b );
- });
- });
+ } );
+ } );
- piped.done(function( result ) {
+ piped.done( function( result ) {
value3 = result;
- });
+ } );
- defer.progress(function( a, b ) {
+ defer.progress( function( a, b ) {
value1 = a;
value2 = b;
- });
+ } );
defer.notify( 2, 3 );
strictEqual( value1, 2, "first progress value ok" );
strictEqual( value2, 3, "second progress value ok" );
strictEqual( value3, 6, "result of filter ok" );
-});
+} );
test( "jQuery.Deferred.then - context", function() {
var defer, piped, defer2, piped2,
context = {};
- jQuery.Deferred().resolveWith( context, [ 2 ] ).then(function( value ) {
+ jQuery.Deferred().resolveWith( context, [ 2 ] ).then( function( value ) {
return value * 3;
- }).done(function( value ) {
+ } ).done( function( value ) {
strictEqual( this, context, "custom context correctly propagated" );
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() {
strictEqual( this, context, "custom context of returned deferred correctly propagated" );
- });
+ } );
defer = jQuery.Deferred();
- piped = defer.then(function( value ) {
+ piped = defer.then( function( value ) {
return value * 3;
- });
+ } );
defer.resolve( 2 );
- piped.done(function( value ) {
+ piped.done( function( value ) {
strictEqual( this, piped, "default context gets updated to latest promise in the chain" );
strictEqual( value, 6, "proper value received" );
- });
+ } );
defer2 = jQuery.Deferred();
piped2 = defer2.then();
defer2.resolve( 2 );
- piped2.done(function( value ) {
+ piped2.done( function( value ) {
strictEqual( this, piped2, "default context gets updated to latest promise in the chain (without passing function)" );
strictEqual( value, 2, "proper value received (without passing function)" );
- });
-});
+ } );
+} );
test( "jQuery.when", function() {
expect( 37 );
// Some other objects
- jQuery.each({
+ jQuery.each( {
"an empty string": "",
"a non-empty string": "some string",
"zero": 0,
}, function( message, value ) {
ok(
jQuery.isFunction(
- jQuery.when( value ).done(function( resolveValue ) {
+ jQuery.when( value ).done( function( resolveValue ) {
strictEqual( this, window, "Context is the global object with " + message );
strictEqual( resolveValue, value, "Test the promise was resolved with " + message );
- }).promise
+ } ).promise
),
"Test " + message + " triggers the creation of a new Promise"
);
- });
+ } );
ok(
jQuery.isFunction(
- jQuery.when().done(function( resolveValue ) {
+ jQuery.when().done( function( resolveValue ) {
strictEqual( this, window, "Test the promise was resolved with window as its context" );
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() {
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 ) {
strictEqual( value, 1, "Function executed" + ( i > 1 ? " only once" : "" ) );
cache = value;
- });
+ } );
- });
-});
+ } );
+} );
test( "jQuery.when - joined", function() {
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 ) {
deepEqual( [ a, b ], expected, code + " => resolve" );
strictEqual( this[ 0 ], context1, code + " => first context OK" );
} else {
ok( false, code + " => resolve" );
}
- }).fail(function( a, b ) {
+ } ).fail( function( a, b ) {
if ( shouldError ) {
deepEqual( [ a, b ], expected, code + " => reject" );
} else {
ok( false, code + " => reject" );
}
- }).progress(function( a, b ) {
+ } ).progress( function( a, b ) {
deepEqual( [ a, b ], expectedNotify, code + " => progress" );
strictEqual( this[ 0 ], expectedNotify[ 0 ] ? context1 : undefined, code + " => first context OK" );
strictEqual( this[ 1 ], expectedNotify[ 1 ] ? context2 : undefined, code + " => second context OK" );
- });
- });
- });
+ } );
+ } );
+ } );
deferreds.futureSuccess.resolve( 1 );
deferreds.futureError.reject( 0 );
-});
+} );
test( "jQuery.when - resolved", function() {
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 ) {
strictEqual( a, 1, "first notify value ok" );
strictEqual( b, 2, "second notify value ok" );
strictEqual( c, 3, "third notify value ok" );
- }).done(function( a, b, c ) {
+ } ).done( function( a, b, c ) {
strictEqual( a, 4, "first resolve value ok" );
strictEqual( b, 5, "second resolve value ok" );
strictEqual( c, 6, "third resolve value ok" );
- }).fail(function() {
+ } ).fail( function() {
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( jQuery( window ).width(), document.documentElement.clientWidth, "Window width is equal to width reported by window/document." );
- QUnit.expectJqData( this, $div[0], "olddisplay" );
+ QUnit.expectJqData( this, $div[ 0 ], "olddisplay" );
}
QUnit.test( "width()", function( assert ) {
assert.equal( jQuery( window ).height(), document.documentElement.clientHeight, "Window width is equal to width reported by window/document." );
- QUnit.expectJqData( this, $div[0], "olddisplay" );
+ QUnit.expectJqData( this, $div[ 0 ], "olddisplay" );
}
QUnit.test( "height()", function( assert ) {
div.remove();
QUnit.expectJqData( this, $div[ 0 ], "olddisplay" );
-});
+} );
QUnit.test( "innerHeight()", function( assert ) {
assert.expect( 6 );
div.remove();
QUnit.expectJqData( this, $div[ 0 ], "olddisplay" );
-});
+} );
QUnit.test( "outerWidth()", function( assert ) {
assert.expect( 11 );
div.remove();
QUnit.expectJqData( this, $div[ 0 ], "olddisplay" );
-});
+} );
QUnit.test( "child of a hidden elem (or unconnected node) has accurate inner/outer/Width()/Height() see #9441 #9300", function( assert ) {
assert.expect( 16 );
equal( $divChild.height(), $divNormal.height(), "child of a hidden element height() is wrong see #9441" );
equal( $divChild.innerHeight(), $divNormal.innerHeight(), "child of a hidden element innerHeight() is wrong see #9441" );
equal( $divChild.outerHeight(), $divNormal.outerHeight(), "child of a hidden element outerHeight() is wrong see #9441" );
- equal( $divChild.outerHeight(true), $divNormal.outerHeight( true ), "child of a hidden element outerHeight( true ) is wrong see #9300" );
+ 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" );
equal( $divUnconnected.height(), $divNormal.height(), "unconnected element height() is wrong see #9441" );
equal( $divUnconnected.innerHeight(), $divNormal.innerHeight(), "unconnected element innerHeight() is wrong see #9441" );
equal( $divUnconnected.outerHeight(), $divNormal.outerHeight(), "unconnected element outerHeight() is wrong see #9441" );
- equal( $divUnconnected.outerHeight(true), $divNormal.outerHeight( true ), "unconnected element outerHeight( true ) is wrong see #9300" );
+ equal( $divUnconnected.outerHeight( true ), $divNormal.outerHeight( true ), "unconnected element outerHeight( true ) is wrong see #9300" );
// teardown html
$divHiddenParent.remove();
equal( $divChild.height(), $divNormal.height(), "child of a hidden element height() is wrong see #10413" );
equal( $divChild.innerHeight(), $divNormal.innerHeight(), "child of a hidden element innerHeight() is wrong see #10413" );
equal( $divChild.outerHeight(), $divNormal.outerHeight(), "child of a hidden element outerHeight() is wrong see #10413" );
- equal( $divChild.outerHeight(true), $divNormal.outerHeight( true ), "child of a hidden element outerHeight( true ) is wrong see #10413" );
+ 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" );
equal( $divUnconnected.height(), $divNormal.height(), "unconnected element height() is wrong see #10413" );
equal( $divUnconnected.innerHeight(), $divNormal.innerHeight(), "unconnected element innerHeight() is wrong see #10413" );
equal( $divUnconnected.outerHeight(), $divNormal.outerHeight(), "unconnected element outerHeight() is wrong see #10413" );
- equal( $divUnconnected.outerHeight(true), $divNormal.outerHeight( true ), "unconnected element outerHeight( true ) is wrong see #10413" );
+ equal( $divUnconnected.outerHeight( true ), $divNormal.outerHeight( true ), "unconnected element outerHeight( true ) is wrong see #10413" );
// teardown html
$divHiddenParent.remove();
div.remove();
QUnit.expectJqData( this, $div[ 0 ], "olddisplay" );
-});
+} );
QUnit.test( "passing undefined is a setter #5571", function( assert ) {
assert.expect( 4 );
-(function() {
+( function() {
// Can't test what ain't there
if ( !jQuery.fx ) {
return;
}
-module("effects", {
+module( "effects", {
setup: function() {
this.clock = sinon.useFakeTimers( 505877050 );
this._oldInterval = jQuery.fx.interval;
jQuery.fx.interval = this._oldInterval;
return moduleTeardown.apply( this, arguments );
}
-});
+} );
QUnit.test( "sanity check", function( assert ) {
assert.expect( 1 );
assert.equal( jQuery( "#dl:visible, #qunit-fixture:visible, #foo:visible" ).length, 3, "QUnit state is correct for testing effects" );
} );
-test("show() basic", 2, function() {
+test( "show() basic", 2, function() {
var div,
- hiddendiv = jQuery("div.hidden");
+ hiddendiv = jQuery( "div.hidden" );
hiddendiv.hide().show();
- equal( hiddendiv.css("display"), "block", "Make sure a pre-hidden div is visible." );
+ 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();
- equal( div.css("display"), "block", "Make sure pre-hidden divs show" );
+ equal( div.css( "display" ), "block", "Make sure pre-hidden divs show" );
// Clean up the detached node
div.remove();
QUnit.expectJqData( this, hiddendiv, "olddisplay" );
-});
+} );
-test("show()", 27, function () {
+test( "show()", 27, function() {
var div, speeds, test,
displaysActual, displaysExpected,
- hiddendiv = jQuery("div.hidden");
+ hiddendiv = jQuery( "div.hidden" );
- equal(jQuery.css( hiddendiv[0], "display"), "none", "hiddendiv is display: none");
+ equal( jQuery.css( hiddendiv[ 0 ], "display" ), "none", "hiddendiv is display: none" );
- hiddendiv.css("display", "block");
- equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block");
+ hiddendiv.css( "display", "block" );
+ equal( jQuery.css( hiddendiv[ 0 ], "display" ), "block", "hiddendiv is display: block" );
hiddendiv.show();
- equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block");
+ equal( jQuery.css( hiddendiv[ 0 ], "display" ), "block", "hiddendiv is display: block" );
- hiddendiv.css("display","");
+ hiddendiv.css( "display", "" );
displaysActual = [];
displaysExpected = [];
- div = jQuery("#fx-queue div").slice(0, 4);
- div.show().each(function() {
- notEqual(this.style.display, "none", "don't change any <div> with display block");
- });
+ div = jQuery( "#fx-queue div" ).slice( 0, 4 );
+ div.show().each( function() {
+ notEqual( this.style.display, "none", "don't change any <div> with display block" );
+ } );
speeds = {
"null speed": null,
"false speed": false
};
- jQuery.each(speeds, function(name, speed) {
+ jQuery.each( speeds, function( name, speed ) {
var pass = true;
- div.hide().show(speed).each(function() {
+ div.hide().show( speed ).each( function() {
if ( this.style.display === "none" ) {
pass = false;
}
- });
- ok( pass, "Show with " + name);
- });
+ } );
+ ok( pass, "Show with " + name );
+ } );
- jQuery.each(speeds, function(name, speed) {
+ jQuery.each( speeds, function( name, speed ) {
var pass = true;
- div.hide().show(speed, function() {
+ div.hide().show( speed, function() {
pass = false;
- });
+ } );
ok( pass, "Show with " + name + " does not call animate callback" );
- });
+ } );
// Tolerate data from show()/hide()
QUnit.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>");
+ 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>" );
test = {
- "div" : "block",
- "p" : "block",
- "a" : "inline",
- "code" : "inline",
- "pre" : "block",
- "span" : "inline",
- "table" : "table",
- "thead" : "table-header-group",
- "tbody" : "table-row-group",
- "tr" : "table-row",
- "th" : "table-cell",
- "td" : "table-cell",
- "ul" : "block",
- "li" : "list-item"
+ "div": "block",
+ "p": "block",
+ "a": "inline",
+ "code": "inline",
+ "pre": "block",
+ "span": "inline",
+ "table": "table",
+ "thead": "table-header-group",
+ "tbody": "table-row-group",
+ "tr": "table-row",
+ "th": "table-cell",
+ "td": "table-cell",
+ "ul": "block",
+ "li": "list-item"
};
- jQuery.each(test, function(selector, expected) {
- var elem = jQuery(selector, "#show-tests").show();
- 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();
+ equal( elem.css( "display" ), expected, "Show using correct display type for " + selector );
+ } );
- jQuery("#show-tests").remove();
+ jQuery( "#show-tests" ).remove();
// Make sure that showing or hiding a text node doesn't cause an error
- jQuery("<div>test</div> text <span>test</span>").show().remove();
- jQuery("<div>test</div> text <span>test</span>").hide().remove();
-});
-
-test("show(Number) - other displays", function() {
- expect(15);
+ jQuery( "<div>test</div> text <span>test</span>" ).show().remove();
+ jQuery( "<div>test</div> text <span>test</span>" ).hide().remove();
+} );
+test( "show(Number) - other displays", function() {
+ 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>");
+ 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>" );
// Note: inline elements are expected to be inline-block
// because we're showing width/height
// Can't animate width/height inline
// See #14344
var test = {
- "div" : "block",
- "p" : "block",
- "a" : "inline-block",
- "code" : "inline-block",
- "pre" : "block",
- "span" : "inline-block",
- "table" : "table",
- "thead" : "table-header-group",
- "tbody" : "table-row-group",
- "tr" : "table-row",
- "th" : "table-cell",
- "td" : "table-cell",
- "ul" : "block",
- "li" : "list-item"
+ "div": "block",
+ "p": "block",
+ "a": "inline-block",
+ "code": "inline-block",
+ "pre": "block",
+ "span": "inline-block",
+ "table": "table",
+ "thead": "table-header-group",
+ "tbody": "table-row-group",
+ "tr": "table-row",
+ "th": "table-cell",
+ "td": "table-cell",
+ "ul": "block",
+ "li": "list-item"
};
- jQuery.each(test, function(selector, expected) {
- var elem = jQuery(selector, "#show-tests").show(1, function() {
- 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() {
+ equal( elem.css( "display" ), expected, "Show using correct display type for " + selector );
+ } );
+ } );
this.clock.tick( 10 );
- jQuery("#show-tests").remove();
-});
+ jQuery( "#show-tests" ).remove();
+} );
// Supports #7397
-test("Persist correct display value", function() {
- expect(3);
+test( "Persist correct display value", function() {
+ 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"),
+ var $span = jQuery( "#show-tests span" ),
+ displayNone = $span.css( "display" ),
display = "",
clock = this.clock;
$span.show();
- display = $span.css("display");
+ display = $span.css( "display" );
$span.hide();
- $span.fadeIn(100, function() {
- equal($span.css("display"), display, "Expecting display: " + display);
- $span.fadeOut(100, function () {
- equal($span.css("display"), displayNone, "Expecting display: " + displayNone);
- $span.fadeIn(100, function() {
- equal($span.css("display"), display, "Expecting display: " + display);
- });
- });
- });
+ $span.fadeIn( 100, function() {
+ equal( $span.css( "display" ), display, "Expecting display: " + display );
+ $span.fadeOut( 100, function() {
+ equal( $span.css( "display" ), displayNone, "Expecting display: " + displayNone );
+ $span.fadeIn( 100, function() {
+ equal( $span.css( "display" ), display, "Expecting display: " + display );
+ } );
+ } );
+ } );
clock.tick( 300 );
QUnit.expectJqData( this, $span, "olddisplay" );
-});
+} );
-test("animate(Hash, Object, Function)", function() {
- expect(1);
- var hash = {opacity: "show"},
- hashCopy = jQuery.extend({}, hash);
- jQuery("#foo").animate(hash, 0, function() {
+test( "animate(Hash, Object, Function)", function() {
+ expect( 1 );
+ var hash = { opacity: "show" },
+ hashCopy = jQuery.extend( {}, hash );
+ jQuery( "#foo" ).animate( hash, 0, function() {
equal( hash.opacity, hashCopy.opacity, "Check if animate changed the hash parameter" );
- });
-});
+ } );
+} );
-test("animate relative values", function() {
+test( "animate relative values", function() {
var value = 40,
clock = this.clock,
bases = [ "%", "px", "em" ],
adjustments = [ "px", "em" ],
- container = jQuery("<div></div>")
- .css({ position: "absolute", height: "50em", width: "50em" }),
+ container = jQuery( "<div></div>" )
+ .css( { position: "absolute", height: "50em", width: "50em" } ),
animations = bases.length * adjustments.length;
expect( 2 * animations );
jQuery.each( adjustments, function( _, adjustUnit ) {
var base = value + baseUnit,
adjust = { height: "+=2" + adjustUnit, width: "-=2" + adjustUnit },
- elem = jQuery("<div></div>")
- .appendTo( container.clone().appendTo("#qunit-fixture") )
- .css({
+ elem = jQuery( "<div></div>" )
+ .appendTo( container.clone().appendTo( "#qunit-fixture" ) )
+ .css( {
position: "absolute",
height: base,
width: value + adjustUnit
- }),
+ } ),
baseScale = elem[ 0 ].offsetHeight / value,
adjustScale = elem[ 0 ].offsetWidth / value;
equal( this.offsetWidth, value * baseScale - 2 * adjustScale,
baseUnit + "-=" + adjustUnit );
- });
+ } );
clock.tick( 100 );
- });
- });
-});
+ } );
+ } );
+} );
-test("animate negative height", function() {
- expect(1);
- jQuery("#foo").animate({ height: -100 }, 100, function() {
+test( "animate negative height", function() {
+ expect( 1 );
+ jQuery( "#foo" ).animate( { height: -100 }, 100, function() {
equal( this.offsetHeight, 0, "Verify height." );
- });
+ } );
this.clock.tick( 100 );
-});
+} );
-test("animate negative margin", function() {
- expect(1);
- jQuery("#foo").animate({ "marginTop": -100 }, 100, function() {
- equal( jQuery(this).css("marginTop"), "-100px", "Verify margin." );
- });
+test( "animate negative margin", function() {
+ expect( 1 );
+ jQuery( "#foo" ).animate( { "marginTop": -100 }, 100, function() {
+ equal( jQuery( this ).css( "marginTop" ), "-100px", "Verify margin." );
+ } );
this.clock.tick( 100 );
-});
+} );
-test("animate negative margin with px", function() {
- expect(1);
- jQuery("#foo").animate({ marginTop: "-100px" }, 100, function() {
- equal( jQuery(this).css("marginTop"), "-100px", "Verify margin." );
- });
+test( "animate negative margin with px", function() {
+ expect( 1 );
+ jQuery( "#foo" ).animate( { marginTop: "-100px" }, 100, function() {
+ equal( jQuery( this ).css( "marginTop" ), "-100px", "Verify margin." );
+ } );
this.clock.tick( 100 );
-});
+} );
-test("animate negative padding", function() {
- expect(1);
- jQuery("#foo").animate({ "paddingBottom": -100 }, 100, function() {
- equal( jQuery(this).css("paddingBottom"), "0px", "Verify paddingBottom." );
- });
+test( "animate negative padding", function() {
+ expect( 1 );
+ jQuery( "#foo" ).animate( { "paddingBottom": -100 }, 100, function() {
+ equal( jQuery( this ).css( "paddingBottom" ), "0px", "Verify paddingBottom." );
+ } );
this.clock.tick( 100 );
-});
+} );
-test("animate block as inline width/height", function() {
- expect(3);
+test( "animate block as inline width/height", function() {
+ expect( 3 );
- var span = jQuery("<span>").css("display", "inline-block").appendTo("body");
+ var span = jQuery( "<span>" ).css( "display", "inline-block" ).appendTo( "body" );
span.remove();
- jQuery("#foo").css({ display: "inline", width: "", height: "" }).animate({ width: 42, height: 42 }, 100, function() {
- equal( jQuery(this).css("display"), "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
+ jQuery( "#foo" ).css( { display: "inline", width: "", height: "" } ).animate( { width: 42, height: 42 }, 100, function() {
+ equal( jQuery( this ).css( "display" ), "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
equal( this.offsetWidth, 42, "width was animated" );
equal( this.offsetHeight, 42, "height was animated" );
- });
+ } );
this.clock.tick( 100 );
-});
+} );
-test("animate native inline width/height", function() {
- expect(3);
+test( "animate native inline width/height", function() {
+ expect( 3 );
- var span = jQuery("<span>").css("display", "inline-block").appendTo("body");
+ var span = jQuery( "<span>" ).css( "display", "inline-block" ).appendTo( "body" );
span.remove();
- jQuery("#foo").css({ display: "", width: "", height: "" })
- .append("<span>text</span>")
- .children("span")
- .animate({ width: 42, height: 42 }, 100, function() {
- equal( jQuery(this).css("display"), "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
+ jQuery( "#foo" ).css( { display: "", width: "", height: "" } )
+ .append( "<span>text</span>" )
+ .children( "span" )
+ .animate( { width: 42, height: 42 }, 100, function() {
+ equal( jQuery( this ).css( "display" ), "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
equal( this.offsetWidth, 42, "width was animated" );
equal( this.offsetHeight, 42, "height was animated" );
- });
+ } );
this.clock.tick( 100 );
-});
+} );
test( "animate block width/height", function() {
expect( 3 );
- jQuery("<div>").appendTo("#qunit-fixture").css({
+ jQuery( "<div>" ).appendTo( "#qunit-fixture" ).css( {
display: "block",
width: 20,
height: 20,
paddingLeft: 60
- }).animate({
+ } ).animate( {
width: 42,
height: 42
}, {
}
},
complete: function() {
- equal( jQuery( this ).css("display"), "block", "inline-block was not set on block element when animating width/height" );
+ equal( jQuery( this ).css( "display" ), "block", "inline-block was not set on block element when animating width/height" );
equal( jQuery( this ).width(), 42, "width was animated" );
equal( jQuery( this ).height(), 42, "height was animated" );
}
- });
+ } );
this.clock.tick( 100 );
-});
+} );
test( "animate table width/height", function() {
- expect(1);
+ expect( 1 );
- jQuery( "#table" ).animate({ width: 42, height: 42 }, 100, function() {
+ jQuery( "#table" ).animate( { width: 42, height: 42 }, 100, function() {
equal( jQuery( this ).css( "display" ), "table", "display mode is correct" );
- });
+ } );
this.clock.tick( 100 );
-});
+} );
-test("animate table-row width/height", function() {
- expect(3);
- var tr = jQuery("#table")
- .attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 })
- .html("<tr style='height:42px;'><td style='padding:0;'><div style='width:20px;height:20px;'></div></td></tr>")
- .find("tr");
+test( "animate table-row width/height", function() {
+ expect( 3 );
+ var tr = jQuery( "#table" )
+ .attr( { "cellspacing": 0, "cellpadding": 0, "border": 0 } )
+ .html( "<tr style='height:42px;'><td style='padding:0;'><div style='width:20px;height:20px;'></div></td></tr>" )
+ .find( "tr" );
- tr.animate({ width: 10, height: 10 }, 100, function() {
+ tr.animate( { width: 10, height: 10 }, 100, function() {
equal( jQuery( this ).css( "display" ), "table-row", "display mode is correct" );
equal( this.offsetWidth, 20, "width animated to shrink wrap point" );
equal( this.offsetHeight, 20, "height animated to shrink wrap point" );
- });
+ } );
this.clock.tick( 100 );
-});
+} );
-test("animate table-cell width/height", function() {
- expect(3);
+test( "animate table-cell width/height", function() {
+ expect( 3 );
var td = jQuery( "#table" )
- .attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 })
+ .attr( { "cellspacing": 0, "cellpadding": 0, "border": 0 } )
.html( "<tr><td style='width:42px;height:42px;padding:0;'><div style='width:20px;height:20px;'></div></td></tr>" )
.find( "td" );
- td.animate({ width: 10, height: 10 }, 100, function() {
+ td.animate( { width: 10, height: 10 }, 100, function() {
equal( jQuery( this ).css( "display" ), "table-cell", "display mode is correct" );
equal( this.offsetWidth, 20, "width animated to shrink wrap point" );
equal( this.offsetHeight, 20, "height animated to shrink wrap point" );
- });
+ } );
this.clock.tick( 100 );
-});
+} );
-test("animate percentage(%) on width/height", function() {
+test( "animate percentage(%) on width/height", function() {
expect( 2 );
- var $div = jQuery("<div style='position:absolute;top:-999px;left:-999px;width:60px;height:60px;'><div style='width:50%;height:50%;'></div></div>")
- .appendTo("#qunit-fixture").children("div");
+ var $div = jQuery( "<div style='position:absolute;top:-999px;left:-999px;width:60px;height:60px;'><div style='width:50%;height:50%;'></div></div>" )
+ .appendTo( "#qunit-fixture" ).children( "div" );
- $div.animate({ width: "25%", height: "25%" }, 13, function() {
- var $this = jQuery(this);
- equal( $this.css("width"), "15px", "Width was animated to 15px rather than 25px");
- equal( $this.css("height"), "15px", "Height was animated to 15px rather than 25px");
- });
+ $div.animate( { width: "25%", height: "25%" }, 13, function() {
+ var $this = jQuery( this );
+ equal( $this.css( "width" ), "15px", "Width was animated to 15px rather than 25px" );
+ equal( $this.css( "height" ), "15px", "Height was animated to 15px rather than 25px" );
+ } );
this.clock.tick( 20 );
-});
+} );
-test("animate resets overflow-x and overflow-y when finished", function() {
- expect(2);
- jQuery("#foo")
- .css({ display: "block", width: 20, height: 20, overflowX: "visible", overflowY: "auto" })
- .animate({ width: 42, height: 42 }, 100, function() {
+test( "animate resets overflow-x and overflow-y when finished", function() {
+ expect( 2 );
+ jQuery( "#foo" )
+ .css( { display: "block", width: 20, height: 20, overflowX: "visible", overflowY: "auto" } )
+ .animate( { width: 42, height: 42 }, 100, function() {
equal( this.style.overflowX, "visible", "overflow-x is visible" );
equal( this.style.overflowY, "auto", "overflow-y is auto" );
- });
+ } );
this.clock.tick( 100 );
-});
+} );
/* // This test ends up being flaky depending upon the CPU load
test("animate option (queue === false)", function () {
expect( 2 );
var foo = jQuery( "#foo" );
- foo.animate({
+ foo.animate( {
fontSize: "2em"
}, {
queue: false,
complete: function() {
ok( true, "Animation Completed" );
}
- });
+ } );
this.clock.tick( 10 );
equal( foo.queue().length, 0, "Queue is empty" );
-});
+} );
test( "animate option { queue: true }", function() {
expect( 2 );
var foo = jQuery( "#foo" );
- foo.animate({
+ foo.animate( {
fontSize: "2em"
}, {
queue: true,
complete: function() {
ok( true, "Animation Completed" );
}
- });
+ } );
notEqual( foo.queue().length, 0, "Default queue is not empty" );
//clear out existing timers before next test
this.clock.tick( 10 );
-});
+} );
test( "animate option { queue: 'name' }", function() {
expect( 5 );
var foo = jQuery( "#foo" ),
- origWidth = parseFloat( foo.css("width") ),
+ origWidth = parseFloat( foo.css( "width" ) ),
order = [];
foo.animate( { width: origWidth + 100 }, {
// second callback function
order.push( 2 );
- equal( parseFloat( foo.css("width") ), origWidth + 100, "Animation ended" );
- equal( foo.queue("name").length, 1, "Queue length of 'name' queue" );
+ equal( parseFloat( foo.css( "width" ) ), origWidth + 100, "Animation ended" );
+ equal( foo.queue( "name" ).length, 1, "Queue length of 'name' queue" );
}
- }).queue( "name", function() {
+ } ).queue( "name", function() {
// last callback function
deepEqual( order, [ 1, 2 ], "Callbacks in expected order" );
- });
-
+ } );
// this is the first callback function that should be called
order.push( 1 );
- equal( parseFloat( foo.css("width") ), origWidth, "Animation does not start on its own." );
- equal( foo.queue("name").length, 2, "Queue length of 'name' queue" );
+ equal( parseFloat( foo.css( "width" ) ), origWidth, "Animation does not start on its own." );
+ equal( foo.queue( "name" ).length, 2, "Queue length of 'name' queue" );
foo.dequeue( "name" );
this.clock.tick( 10 );
-});
+} );
-test("animate with no properties", function() {
- expect(2);
+test( "animate with no properties", function() {
+ expect( 2 );
var foo,
- divs = jQuery("div"),
+ divs = jQuery( "div" ),
count = 0;
- divs.animate({}, function(){
+ divs.animate( {}, function() {
count++;
- });
+ } );
equal( divs.length, count, "Make sure that callback is called for each element in the set." );
+ foo = jQuery( "#foo" );
- foo = jQuery("#foo");
-
- foo.animate({});
- foo.animate({top: 10}, 100, function(){
+ foo.animate( {} );
+ foo.animate( { top: 10 }, 100, function() {
ok( true, "Animation was properly dequeued." );
- });
+ } );
this.clock.tick( 100 );
-});
-
-test("animate duration 0", function() {
- expect(11);
+} );
+test( "animate duration 0", function() {
+ expect( 11 );
var $elem,
- $elems = jQuery([{ a:0 },{ a:0 }]),
+ $elems = jQuery( [ { a:0 }, { a:0 } ] ),
counter = 0;
equal( jQuery.timers.length, 0, "Make sure no animation was running from another test" );
- $elems.eq(0).animate( {a:1}, 0, function(){
+ $elems.eq( 0 ).animate( { a:1 }, 0, function() {
ok( true, "Animate a simple property." );
counter++;
- });
+ } );
// Failed until [6115]
equal( jQuery.timers.length, 0, "Make sure synchronic animations are not left on jQuery.timers" );
equal( counter, 1, "One synchronic animations" );
- $elems.animate( { a:2 }, 0, function(){
+ $elems.animate( { a:2 }, 0, function() {
ok( true, "Animate a second simple property." );
counter++;
- });
+ } );
equal( counter, 3, "Multiple synchronic animations" );
- $elems.eq(0).animate( {a:3}, 0, function(){
+ $elems.eq( 0 ).animate( { a:3 }, 0, function() {
ok( true, "Animate a third simple property." );
counter++;
- });
- $elems.eq(1).animate( {a:3}, 200, function(){
+ } );
+ $elems.eq( 1 ).animate( { a:3 }, 200, function() {
counter++;
+
// Failed until [6115]
equal( counter, 5, "One synchronic and one asynchronic" );
- });
+ } );
this.clock.tick( 200 );
- $elem = jQuery("<div />");
- $elem.show(0, function(){
- ok(true, "Show callback with no duration");
- });
- $elem.hide(0, function(){
- ok(true, "Hide callback with no duration");
- });
+ $elem = jQuery( "<div />" );
+ $elem.show( 0, function() {
+ ok( true, "Show callback with no duration" );
+ } );
+ $elem.hide( 0, function() {
+ ok( true, "Hide callback with no duration" );
+ } );
// manually clean up detached elements
$elem.remove();
-});
+} );
-test("animate hyphenated properties", function() {
- expect(1);
+test( "animate hyphenated properties", function() {
+ expect( 1 );
- jQuery("#foo")
- .css("font-size", 10)
- .animate({"font-size": 20}, 200, function() {
+ jQuery( "#foo" )
+ .css( "font-size", 10 )
+ .animate( { "font-size": 20 }, 200, function() {
equal( this.style.fontSize, "20px", "The font-size property was animated." );
- });
+ } );
+
// FIXME why is this double only when run with other tests
this.clock.tick( 400 );
-});
+} );
-test("animate non-element", function() {
- expect(1);
+test( "animate non-element", function() {
+ expect( 1 );
var obj = { test: 0 };
- jQuery(obj).animate({test: 200}, 200, function(){
+ jQuery( obj ).animate( { test: 200 }, 200, function() {
equal( obj.test, 200, "The custom property should be modified." );
- });
+ } );
this.clock.tick( 200 );
-});
+} );
-test("stop()", function() {
+test( "stop()", function() {
expect( 4 );
var $one, $two,
- $foo = jQuery("#foo"),
+ $foo = jQuery( "#foo" ),
w = 0,
nw;
.animate( { "width": "show" }, 1500 );
this.clock.tick( 100 );
- nw = $foo.css("width");
+ nw = $foo.css( "width" );
notEqual( parseFloat( nw ), w, "An animation occurred " + nw + " " + w + "px" );
$foo.stop();
- nw = $foo.css("width");
+ nw = $foo.css( "width" );
notEqual( parseFloat( nw ), w, "Stop didn't reset the animation " + nw + " " + w + "px" );
this.clock.tick( 100 );
$foo.removeData();
- $foo.removeData(undefined, true);
- equal( nw, $foo.css("width"), "The animation didn't continue" );
+ $foo.removeData( undefined, true );
+ equal( nw, $foo.css( "width" ), "The animation didn't continue" );
- $one = jQuery("#fadein");
- $two = jQuery("#show");
- $one.fadeTo(100, 0, function() {
+ $one = jQuery( "#fadein" );
+ $two = jQuery( "#show" );
+ $one.fadeTo( 100, 0, function() {
$one.stop();
- });
+ } );
this.clock.tick( 100 );
- $two.fadeTo(100, 0, function() {
- equal( $two.css("opacity"), "0", "Stop does not interfere with animations on other elements (#6641)" );
+ $two.fadeTo( 100, 0, function() {
+ equal( $two.css( "opacity" ), "0", "Stop does not interfere with animations on other elements (#6641)" );
+
// Reset styles
- $one.add( $two ).css("opacity", "");
- });
+ $one.add( $two ).css( "opacity", "" );
+ } );
this.clock.tick( 100 );
-});
+} );
-test("stop() - several in queue", function() {
+test( "stop() - several in queue", function() {
expect( 5 );
var nw, $foo = jQuery( "#foo" );
// default duration is 400ms, so 800px ensures we aren't 0 or 1 after 1ms
$foo.hide().css( "width", 800 );
- $foo.animate({ "width": "show" }, 400, "linear");
- $foo.animate({ "width": "hide" });
- $foo.animate({ "width": "show" });
+ $foo.animate( { "width": "show" }, 400, "linear" );
+ $foo.animate( { "width": "hide" } );
+ $foo.animate( { "width": "show" } );
this.clock.tick( 1 );
$foo.stop( true );
equal( $foo.queue().length, 0, "0 in the queue" );
-});
+} );
-test("stop(clearQueue)", function() {
- expect(4);
+test( "stop(clearQueue)", function() {
+ expect( 4 );
- var $foo = jQuery("#foo"),
+ var $foo = jQuery( "#foo" ),
w = 0,
nw;
- $foo.hide().css( "width", 200 ).css("width");
+ $foo.hide().css( "width", 200 ).css( "width" );
- $foo.animate({ "width": "show" }, 1000);
- $foo.animate({ "width": "hide" }, 1000);
- $foo.animate({ "width": "show" }, 1000);
+ $foo.animate( { "width": "show" }, 1000 );
+ $foo.animate( { "width": "hide" }, 1000 );
+ $foo.animate( { "width": "show" }, 1000 );
this.clock.tick( 100 );
- nw = $foo.css("width");
- ok( parseFloat( nw ) !== w, "An animation occurred " + nw + " " + w + "px");
- $foo.stop(true);
+ nw = $foo.css( "width" );
+ ok( parseFloat( nw ) !== w, "An animation occurred " + nw + " " + w + "px" );
+ $foo.stop( true );
- nw = $foo.css("width");
- ok( parseFloat( nw ) !== w, "Stop didn't reset the animation " + nw + " " + w + "px");
+ nw = $foo.css( "width" );
+ ok( parseFloat( nw ) !== w, "Stop didn't reset the animation " + nw + " " + w + "px" );
equal( $foo.queue().length, 0, "The animation queue was cleared" );
this.clock.tick( 100 );
- equal( nw, $foo.css("width"), "The animation didn't continue" );
-});
+ equal( nw, $foo.css( "width" ), "The animation didn't continue" );
+} );
-test("stop(clearQueue, gotoEnd)", function() {
- expect(1);
+test( "stop(clearQueue, gotoEnd)", function() {
+ expect( 1 );
- var $foo = jQuery("#foo"),
+ var $foo = jQuery( "#foo" ),
w = 0,
nw;
- $foo.hide().css( "width", 200 ).css("width");
+ $foo.hide().css( "width", 200 ).css( "width" );
- $foo.animate({ width: "show" }, 1000);
- $foo.animate({ width: "hide" }, 1000);
- $foo.animate({ width: "show" }, 1000);
- $foo.animate({ width: "hide" }, 1000);
+ $foo.animate( { width: "show" }, 1000 );
+ $foo.animate( { width: "hide" }, 1000 );
+ $foo.animate( { width: "show" }, 1000 );
+ $foo.animate( { width: "hide" }, 1000 );
this.clock.tick( 100 );
- nw = $foo.css("width");
- ok( parseFloat( nw ) !== w, "An animation occurred " + nw + " " + w + "px");
- $foo.stop(false, true);
+ nw = $foo.css( "width" );
+ ok( parseFloat( nw ) !== w, "An animation occurred " + nw + " " + w + "px" );
+ $foo.stop( false, true );
+
+ nw = $foo.css( "width" );
- nw = $foo.css("width");
// Disabled, being flaky
//equal( nw, 1, "Stop() reset the animation" );
this.clock.tick( 100 );
+
// Disabled, being flaky
//equal( $foo.queue().length, 2, "The next animation continued" );
- $foo.stop(true);
-});
+ $foo.stop( true );
+} );
test( "stop( queue, ..., ... ) - Stop single queues", function() {
expect( 3 );
var saved,
- foo = jQuery("#foo").css({ width: 200, height: 200 });
+ foo = jQuery( "#foo" ).css( { width: 200, height: 200 } );
- foo.animate({
+ foo.animate( {
width: 400
- },{
+ }, {
duration: 500,
complete: function() {
- equal( parseFloat( foo.css("width") ), 400, "Animation completed for standard queue" );
- equal( parseFloat( foo.css("height") ), saved, "Height was not changed after the second stop");
+ equal( parseFloat( foo.css( "width" ) ), 400, "Animation completed for standard queue" );
+ equal( parseFloat( foo.css( "height" ) ), saved, "Height was not changed after the second stop" );
}
- });
+ } );
- foo.animate({
+ foo.animate( {
height: 400
- },{
+ }, {
duration: 1000,
queue: "height"
- }).dequeue("height").stop( "height", false, true );
+ } ).dequeue( "height" ).stop( "height", false, true );
- equal( parseFloat( foo.css("height") ), 400, "Height was stopped with gotoEnd" );
+ equal( parseFloat( foo.css( "height" ) ), 400, "Height was stopped with gotoEnd" );
- foo.animate({
+ foo.animate( {
height: 200
- },{
+ }, {
duration: 1000,
queue: "height"
- }).dequeue( "height" ).stop( "height", false, false );
- saved = parseFloat( foo.css("height") );
+ } ).dequeue( "height" ).stop( "height", false, false );
+ saved = parseFloat( foo.css( "height" ) );
this.clock.tick( 500 );
-});
+} );
-test("toggle()", function() {
- expect(6);
- var x = jQuery("#foo");
- ok( x.is(":visible"), "is visible" );
+test( "toggle()", function() {
+ expect( 6 );
+ var x = jQuery( "#foo" );
+ ok( x.is( ":visible" ), "is visible" );
x.toggle();
- ok( x.is(":hidden"), "is hidden" );
+ ok( x.is( ":hidden" ), "is hidden" );
x.toggle();
- ok( x.is(":visible"), "is visible again" );
-
- x.toggle(true);
- ok( x.is(":visible"), "is visible" );
- x.toggle(false);
- ok( x.is(":hidden"), "is hidden" );
- x.toggle(true);
- ok( x.is(":visible"), "is visible again" );
-});
+ ok( x.is( ":visible" ), "is visible again" );
+
+ x.toggle( true );
+ ok( x.is( ":visible" ), "is visible" );
+ x.toggle( false );
+ ok( x.is( ":hidden" ), "is hidden" );
+ x.toggle( true );
+ ok( x.is( ":visible" ), "is visible again" );
+} );
test( "jQuery.fx.prototype.cur() - <1.8 Back Compat", 7, function() {
- var div = jQuery( "<div></div>" ).appendTo( "#qunit-fixture" ).css({
+ var div = jQuery( "<div></div>" ).appendTo( "#qunit-fixture" ).css( {
color: "#ABC",
border: "5px solid black",
left: "auto",
marginBottom: "-11000px"
- })[0];
+ } )[ 0 ];
equal(
( new jQuery.fx( div, {}, "color" ) ).cur(),
);
jQuery( div ).remove();
-});
+} );
-test("Overflow and Display", function() {
- expect(4);
+test( "Overflow and Display", function() {
+ expect( 4 );
var
- testClass = jQuery.makeTest("Overflow and Display")
- .addClass("overflow inline"),
- testStyle = jQuery.makeTest("Overflow and Display (inline style)")
- .css({ overflow: "visible", display: "inline" }),
+ testClass = jQuery.makeTest( "Overflow and Display" )
+ .addClass( "overflow inline" ),
+ testStyle = jQuery.makeTest( "Overflow and Display (inline style)" )
+ .css( { overflow: "visible", display: "inline" } ),
done = function() {
equal( jQuery.css( this, "overflow" ), "visible", "Overflow should be 'visible'" );
equal( jQuery.css( this, "display" ), "inline", "Display should be 'inline'" );
};
testClass.add( testStyle )
- .addClass("widewidth")
- .text("Some sample text.")
- .before("text before")
- .after("text after")
- .animate({ opacity: 0.5 }, "slow", done );
+ .addClass( "widewidth" )
+ .text( "Some sample text." )
+ .before( "text before" )
+ .after( "text after" )
+ .animate( { opacity: 0.5 }, "slow", done );
this.clock.tick( 600 );
-});
+} );
-jQuery.each({
+jQuery.each( {
"CSS Auto": function( elem, prop ) {
jQuery( elem ).addClass( "auto" + prop )
.text( "This is a long string of text." );
return 0;
}
}, function( fn, f ) {
- jQuery.each({
+ jQuery.each( {
"show": function( elem, prop ) {
jQuery( elem ).hide( ).addClass( "wide" + prop );
return "show";
return 0;
}
}, function( tn, t ) {
- test(fn + " to " + tn, function() {
+ test( fn + " to " + tn, function() {
var num, anim,
elem = jQuery.makeTest( fn + " to " + tn ),
t_w = t( elem, "width" ),
}
num = 0;
+
// TODO: uncrowd this
if ( t_h === "show" ) {num++;}
if ( t_w === "show" ) {num++;}
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;}
expect( num );
anim = { width: t_w, height: t_h, opacity: t_o };
- elem.animate(anim, 50);
+ 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 ];
ok( f_h === "" ? elem.style.height === f_h : elem.style.height.indexOf( f_h ) === 0, "Height must be reset to " + f_h + ": " + elem.style.height );
}
- cur_o = jQuery.style(elem, "opacity");
+ cur_o = jQuery.style( elem, "opacity" );
- if ( f_o !== jQuery.css(elem, "opacity") ) {
+ if ( f_o !== jQuery.css( elem, "opacity" ) ) {
f_o = f( elem, "opacity" );
}
if ( f_o === "" ) {
f_o = 1;
}
+
// See above
if ( cur_o === "" ) {
cur_o = 1;
if ( t_o.constructor === Number ) {
equal( cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o );
- ok( jQuery.css(elem, "opacity") !== "" || cur_o === t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o );
+ ok( jQuery.css( elem, "opacity" ) !== "" || cur_o === t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o );
}
if ( t_w.constructor === Number ) {
equal( elem.style.width, t_w + "px", "Final width should be " + t_w + ": " + elem.style.width );
- cur_w = jQuery.css( elem,"width" );
+ cur_w = jQuery.css( elem, "width" );
ok( elem.style.width !== "" || cur_w === t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w );
}
if ( t_h.constructor === Number ) {
equal( elem.style.height, t_h + "px", "Final height should be " + t_h + ": " + elem.style.height );
- cur_h = jQuery.css( elem,"height" );
+ cur_h = jQuery.css( elem, "height" );
ok( elem.style.height !== "" || cur_h === t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_h );
}
if ( t_h === "show" ) {
old_h = jQuery.css( elem, "height" );
- jQuery( elem ).append("<br/>Some more text<br/>and some more...");
+ jQuery( elem ).append( "<br/>Some more text<br/>and some more..." );
if ( /Auto/.test( fn ) ) {
notEqual( jQuery.css( elem, "height" ), old_h, "Make sure height is auto." );
// manually remove generated element
jQuery( elem ).remove();
- });
+ } );
this.clock.tick( 50 );
- });
- });
-});
+ } );
+ } );
+} );
-test("Effects chaining", function() {
+test( "Effects chaining", function() {
var remaining = 16,
props = [ "opacity", "height", "width", "display", "overflow" ],
setup = function( name, selector ) {
var $el = jQuery( selector );
- return $el.data( getProps( $el[0] ) ).data( "name", name );
+ return $el.data( getProps( $el[ 0 ] ) ).data( "name", name );
},
assert = function() {
var data = jQuery.data( this ),
var obj = {};
jQuery.each( props, function( i, prop ) {
obj[ prop ] = prop === "overflow" && hiddenOverflow ? "hidden" : el.style[ prop ] || jQuery.css( el, prop );
- });
+ } );
return obj;
};
expect( remaining );
- setup( ".fadeOut().fadeIn()", "#fadein div" ).fadeOut("fast").fadeIn( "fast", assert );
- setup( ".fadeIn().fadeOut()", "#fadeout div" ).fadeIn("fast").fadeOut( "fast", assert );
- setup( ".hide().show()", "#show div" ).hide("fast").show( "fast", assert );
- setup( ".show().hide()", "#hide div" ).show("fast").hide( "fast", assert );
- setup( ".show().hide(easing)", "#easehide div" ).show("fast").hide( "fast", "linear", assert );
- setup( ".toggle().toggle() - in", "#togglein div" ).toggle("fast").toggle( "fast", assert );
- setup( ".toggle().toggle() - out", "#toggleout div" ).toggle("fast").toggle( "fast", assert );
- setup( ".toggle().toggle(easing) - out", "#easetoggleout div" ).toggle("fast").toggle( "fast", "linear", assert );
- setup( ".slideDown().slideUp()", "#slidedown div" ).slideDown("fast").slideUp( "fast", assert );
- setup( ".slideUp().slideDown()", "#slideup div" ).slideUp("fast").slideDown( "fast", assert );
- setup( ".slideUp().slideDown(easing)", "#easeslideup div" ).slideUp("fast").slideDown( "fast", "linear", assert );
- setup( ".slideToggle().slideToggle() - in", "#slidetogglein div" ).slideToggle("fast").slideToggle( "fast", assert );
- setup( ".slideToggle().slideToggle() - out", "#slidetoggleout div" ).slideToggle("fast").slideToggle( "fast", assert );
- setup( ".fadeToggle().fadeToggle() - in", "#fadetogglein div" ).fadeToggle("fast").fadeToggle( "fast", assert );
- setup( ".fadeToggle().fadeToggle() - out", "#fadetoggleout div" ).fadeToggle("fast").fadeToggle( "fast", assert );
+ setup( ".fadeOut().fadeIn()", "#fadein div" ).fadeOut( "fast" ).fadeIn( "fast", assert );
+ setup( ".fadeIn().fadeOut()", "#fadeout div" ).fadeIn( "fast" ).fadeOut( "fast", assert );
+ setup( ".hide().show()", "#show div" ).hide( "fast" ).show( "fast", assert );
+ setup( ".show().hide()", "#hide div" ).show( "fast" ).hide( "fast", assert );
+ setup( ".show().hide(easing)", "#easehide div" ).show( "fast" ).hide( "fast", "linear", assert );
+ setup( ".toggle().toggle() - in", "#togglein div" ).toggle( "fast" ).toggle( "fast", assert );
+ setup( ".toggle().toggle() - out", "#toggleout div" ).toggle( "fast" ).toggle( "fast", assert );
+ setup( ".toggle().toggle(easing) - out", "#easetoggleout div" ).toggle( "fast" ).toggle( "fast", "linear", assert );
+ setup( ".slideDown().slideUp()", "#slidedown div" ).slideDown( "fast" ).slideUp( "fast", assert );
+ setup( ".slideUp().slideDown()", "#slideup div" ).slideUp( "fast" ).slideDown( "fast", assert );
+ setup( ".slideUp().slideDown(easing)", "#easeslideup div" ).slideUp( "fast" ).slideDown( "fast", "linear", assert );
+ setup( ".slideToggle().slideToggle() - in", "#slidetogglein div" ).slideToggle( "fast" ).slideToggle( "fast", assert );
+ setup( ".slideToggle().slideToggle() - out", "#slidetoggleout div" ).slideToggle( "fast" ).slideToggle( "fast", assert );
+ setup( ".fadeToggle().fadeToggle() - in", "#fadetogglein div" ).fadeToggle( "fast" ).fadeToggle( "fast", assert );
+ setup( ".fadeToggle().fadeToggle() - out", "#fadetoggleout div" ).fadeToggle( "fast" ).fadeToggle( "fast", assert );
setup( ".fadeTo(0.5).fadeTo(1.0, easing)", "#fadeto div" ).fadeTo( "fast", 0.5 ).fadeTo( "fast", 1.0, "linear", assert );
this.clock.tick( 400 );
-});
+} );
-jQuery.makeTest = function( text ){
- var elem = jQuery("<div></div>")
+jQuery.makeTest = function( text ) {
+ var elem = jQuery( "<div></div>" )
.attr( "id", "test" + jQuery.makeTest.id++ )
- .addClass("box");
+ .addClass( "box" );
- jQuery("<h4></h4>")
+ jQuery( "<h4></h4>" )
.text( text )
- .appendTo("#fx-tests")
+ .appendTo( "#fx-tests" )
.after( elem );
return elem;
jQuery.makeTest.id = 1;
-test("jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function () {
- expect(4);
+test( "jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function() {
+ expect( 4 );
- var $checkedtest = jQuery("#checkedtest");
- $checkedtest.hide().show("fast", function() {
- ok( jQuery("input[type='radio']", $checkedtest).first().attr("checked"), "Check first radio still checked." );
- ok( !jQuery("input[type='radio']", $checkedtest).last().attr("checked"), "Check last radio still NOT checked." );
- ok( jQuery("input[type='checkbox']", $checkedtest).first().attr("checked"), "Check first checkbox still checked." );
- ok( !jQuery("input[type='checkbox']", $checkedtest).last().attr("checked"), "Check last checkbox still NOT checked." );
- });
+ var $checkedtest = jQuery( "#checkedtest" );
+ $checkedtest.hide().show( "fast", function() {
+ ok( jQuery( "input[type='radio']", $checkedtest ).first().attr( "checked" ), "Check first radio still checked." );
+ ok( !jQuery( "input[type='radio']", $checkedtest ).last().attr( "checked" ), "Check last radio still NOT checked." );
+ ok( jQuery( "input[type='checkbox']", $checkedtest ).first().attr( "checked" ), "Check first checkbox still checked." );
+ ok( !jQuery( "input[type='checkbox']", $checkedtest ).last().attr( "checked" ), "Check last checkbox still NOT checked." );
+ } );
this.clock.tick( 200 );
-});
+} );
test( "interrupt toggle", function() {
expect( 24 );
longDuration = 2000,
shortDuration = 500,
remaining = 0,
- $elems = jQuery(".chain-test"),
+ $elems = jQuery( ".chain-test" ),
clock = this.clock,
finish = function() {
};
jQuery.each( { slideToggle: "height", fadeToggle: "opacity", toggle: "width" }, function( method, prop ) {
- var $methodElems = $elems.filter( "[id^='" + method.toLowerCase() + "']" ).each(function() {
+ var $methodElems = $elems.filter( "[id^='" + method.toLowerCase() + "']" ).each( function() {
+
// Don't end test until we're done with this element
remaining++;
// Expect olddisplay data from our .hide() call below
QUnit.expectJqData( env, this, "olddisplay" );
- });
+ } );
// Interrupt a hiding toggle
$methodElems[ method ]( longDuration );
- setTimeout(function() {
- $methodElems.stop().each(function() {
+ setTimeout( function() {
+ $methodElems.stop().each( function() {
notEqual( jQuery( this ).css( prop ), jQuery.data( this, "startVal" ), ".stop() before completion of hiding ." + method + "() - #" + this.id );
- });
+ } );
// Restore
$methodElems[ method ]( shortDuration, function() {
var id = this.id,
$elem = jQuery( this ),
- startVal = $elem.data("startVal");
+ startVal = $elem.data( "startVal" );
- $elem.removeData("startVal");
+ $elem.removeData( "startVal" );
equal( $elem.css( prop ), startVal, "original value restored by ." + method + "() - #" + id );
// Interrupt a showing toggle
$elem.hide()[ method ]( longDuration );
- setTimeout(function() {
+ setTimeout( function() {
$elem.stop();
notEqual( $elem.css( prop ), startVal, ".stop() before completion of showing ." + method + "() - #" + id );
$elem[ method ]( shortDuration, function() {
equal( $elem.css( prop ), startVal, "original value restored by ." + method + "() - #" + id );
finish();
- });
+ } );
}, shortDuration );
- });
+ } );
}, shortDuration );
- });
+ } );
clock.tick( longDuration );
// FIXME untangle the set timeouts
-});
+} );
test( "animate with per-property easing", function() {
ok( defaultTestCalled, "Easing function (_default) called" );
equal( props.a[ 1 ], "_test1", "animate does not change original props (per-property easing would be lost)" );
equal( props.b[ 1 ], "_test2", "animate does not change original props (per-property easing would be lost)" );
- });
+ } );
this.clock.tick( 400 );
-});
+} );
-test("animate with CSS shorthand properties", function(){
- expect(11);
+test( "animate with CSS shorthand properties", function() {
+ expect( 11 );
var easeAnimation_count = 0,
easeProperty_count = 0,
propsBasic = { "padding": "10 20 30" },
propsSpecial = { "padding": [ "1 2 3", "propertyScope" ] };
- jQuery.easing.animationScope = function(p) {
+ jQuery.easing.animationScope = function( p ) {
if ( p >= 1 ) {
easeAnimation_count++;
}
return p;
};
- jQuery.easing.propertyScope = function(p) {
+ jQuery.easing.propertyScope = function( p ) {
if ( p >= 1 ) {
easeProperty_count++;
}
return p;
};
- jQuery("#foo")
+ jQuery( "#foo" )
.animate( propsBasic, 200, "animationScope", function() {
equal( this.style.paddingTop, "10px", "padding-top was animated" );
equal( this.style.paddingLeft, "20px", "padding-left was animated" );
equal( this.style.paddingBottom, "30px", "padding-bottom was animated" );
equal( easeAnimation_count, 4, "per-animation default easing called for each property" );
easeAnimation_count = 0;
- })
+ } )
.animate( propsSpecial, 200, "animationScope", function() {
equal( this.style.paddingTop, "1px", "padding-top was animated again" );
equal( this.style.paddingLeft, "2px", "padding-left was animated again" );
equal( easeAnimation_count, 0, "per-animation default easing not called" );
equal( easeProperty_count, 4, "special easing called for each property" );
- jQuery(this).css("padding", "0");
+ jQuery( this ).css( "padding", "0" );
delete jQuery.easing.animationScope;
delete jQuery.easing.propertyScope;
- });
+ } );
this.clock.tick( 400 );
-});
-
-test("hide hidden elements, with animation (bug #7141)", function() {
- expect(3);
+} );
+test( "hide hidden elements, with animation (bug #7141)", function() {
+ expect( 3 );
- var div = jQuery("<div style='display:none'></div>").appendTo("#qunit-fixture");
- equal( div.css("display"), "none", "Element is hidden by default" );
- div.hide(1, function () {
- ok( !jQuery._data(div, "olddisplay"), "olddisplay is undefined after hiding an already-hidden element" );
- div.show(1, function () {
- equal( div.css("display"), "block", "Show a double-hidden element" );
- });
- });
+ var div = jQuery( "<div style='display:none'></div>" ).appendTo( "#qunit-fixture" );
+ equal( div.css( "display" ), "none", "Element is hidden by default" );
+ div.hide( 1, function() {
+ ok( !jQuery._data( div, "olddisplay" ), "olddisplay is undefined after hiding an already-hidden element" );
+ div.show( 1, function() {
+ equal( div.css( "display" ), "block", "Show a double-hidden element" );
+ } );
+ } );
this.clock.tick( 10 );
-});
+} );
-test("animate unit-less properties (#4966)", 2, function() {
+test( "animate unit-less properties (#4966)", 2, function() {
var div = jQuery( "<div style='z-index: 0; position: absolute;'></div>" ).appendTo( "#qunit-fixture" );
equal( div.css( "z-index" ), "0", "z-index is 0" );
- div.animate({ zIndex: 2 }, function() {
+ div.animate( { zIndex: 2 }, function() {
equal( div.css( "z-index" ), "2", "z-index is 2" );
- });
+ } );
this.clock.tick( 400 );
-});
+} );
test( "animate properties missing px w/ opacity as last (#9074)", 2, function() {
expect( 6 );
}
equal( cssInt( "marginLeft" ), 0, "Margin left is 0" );
equal( cssInt( "left" ), 0, "Left is 0" );
- div.animate({
+ div.animate( {
left: 200,
marginLeft: 200,
opacity: 0
- }, 2000);
+ }, 2000 );
this.clock.tick( 500 );
notEqual( l, 0, "Left is not 0 after partial animate" );
notEqual( l, 200, "Left is not 200 after partial animate" );
div.stop().remove();
-});
+} );
-test("callbacks should fire in correct order (#9100)", function() {
+test( "callbacks should fire in correct order (#9100)", function() {
expect( 1 );
var a = 1,
cb = 0;
- jQuery("<p data-operation='*2'></p><p data-operation='^2'></p>")
- .appendTo("#qunit-fixture")
+ jQuery( "<p data-operation='*2'></p><p data-operation='^2'></p>" )
+ .appendTo( "#qunit-fixture" )
+
// The test will always pass if no properties are animated or if the duration is 0
- .animate({ fontSize: 12 }, 13, function() {
- a *= jQuery(this).data("operation") === "*2" ? 2 : a;
+ .animate( { fontSize: 12 }, 13, function() {
+ a *= jQuery( this ).data( "operation" ) === "*2" ? 2 : a;
cb++;
if ( cb === 2 ) {
- equal( a, 4, "test value has been *2 and _then_ ^2");
+ equal( a, 4, "test value has been *2 and _then_ ^2" );
}
- });
+ } );
this.clock.tick( 20 );
-});
+} );
test( "callbacks that throw exceptions will be removed (#5684)", function() {
expect( 2 );
function TestException() {
}
- foo.animate({ height: 1 }, 1, function() {
+ foo.animate( { height: 1 }, 1, function() {
throw new TestException();
- });
+ } );
// this test thoroughly abuses undocumented methods - please feel free to update
// with any changes internally to these functions.
ok( true, "Test completed without throwing a second exception" );
-});
+} );
-test("animate will scale margin properties individually", function() {
+test( "animate will scale margin properties individually", function() {
expect( 2 );
- var foo = jQuery( "#foo" ).css({
+ var foo = jQuery( "#foo" ).css( {
"margin": 0,
"marginLeft": 100
- });
+ } );
ok( foo.css( "marginLeft" ) !== foo.css( "marginRight" ), "Sanity Check" );
- foo.animate({
+ foo.animate( {
"margin": 200
- }).stop();
+ } ).stop();
- ok( foo.css( "marginLeft") !== foo.css( "marginRight" ), "The margin properties are different");
+ ok( foo.css( "marginLeft" ) !== foo.css( "marginRight" ), "The margin properties are different" );
// clean up for next test
- foo.css({
+ foo.css( {
"marginLeft": "",
"marginRight": "",
"marginTop": "",
"marginBottom": ""
- });
-});
+ } );
+} );
+
+test( "Do not append px to 'fill-opacity' #9548", 1, function() {
+ var $div = jQuery( "<div>" ).appendTo( "#qunit-fixture" );
-test("Do not append px to 'fill-opacity' #9548", 1, function() {
- var $div = jQuery("<div>").appendTo("#qunit-fixture");
+ $div.css( "fill-opacity", 0 ).animate( { "fill-opacity": 1.0 }, 0, function() {
- $div.css("fill-opacity", 0).animate({ "fill-opacity": 1.0 }, 0, function () {
// Support: Android 2.3 (no support for fill-opacity)
if ( jQuery( this ).css( "fill-opacity" ) ) {
equal( jQuery( this ).css( "fill-opacity" ), 1, "Do not append px to 'fill-opacity'" );
ok( true, "No support for fill-opacity CSS property" );
}
$div.remove();
- });
-});
+ } );
+} );
-test("line-height animates correctly (#13855)", 12, function() {
+test( "line-height animates correctly (#13855)", 12, function() {
var t0,
clock = this.clock,
longDuration = 2000,
"<p style='line-height: 5000px;'>px</p>" +
"<p style='line-height: 5000%;'>percent</p>" +
"<p style='line-height: 100em;'>em</p>"
- ).appendTo("#qunit-fixture"),
+ ).appendTo( "#qunit-fixture" ),
initialHeight = jQuery.map( animated, function( el ) {
return jQuery( el ).height();
- }),
+ } ),
tolerance = 1.5;
// Delay start to improve test stability
- setTimeout(function() {
+ setTimeout( function() {
- t0 = +(new Date());
+ t0 = +( new Date() );
animated.animate( { "line-height": "hide" }, longDuration, "linear" );
- setTimeout(function() {
- var progress = ( (new Date()) - t0 ) / longDuration;
+ setTimeout( function() {
+ var progress = ( ( new Date() ) - t0 ) / longDuration;
- animated.each(function( i ) {
+ animated.each( function( i ) {
var label = jQuery.text( this ),
initial = initialHeight[ i ],
height = jQuery( this ).height(),
height + " < " + initial + " @ " + ( progress * 100 ) + "%" );
ok( height > lower, "hide " + label + ": lower bound; " +
height + " > " + lower + " @ " + ( progress * 100 ) + "%" );
- });
+ } );
- t0 = +(new Date());
+ t0 = +( new Date() );
animated.stop( true, true ).hide()
.animate( { "line-height": "show" }, longDuration, "linear" );
- setTimeout(function() {
- var progress = ( (new Date()) - t0 ) / longDuration;
+ setTimeout( function() {
+ var progress = ( ( new Date() ) - t0 ) / longDuration;
- animated.each(function( i ) {
+ animated.each( function( i ) {
var label = jQuery.text( this ),
initial = initialHeight[ i ],
height = jQuery( this ).height(),
upper = initial * progress * tolerance;
ok( height < upper, "show " + label + ": upper bound; " +
height + " < " + upper + " @ " + ( progress * 100 ) + "%" );
- });
+ } );
animated.stop( true, true );
}, shortDuration );
-clock.tick(shortDuration);
+clock.tick( shortDuration );
}, shortDuration );
-clock.tick(shortDuration);
+clock.tick( shortDuration );
}, 50 );
clock.tick( 50 );
-});
+} );
// Start 1.8 Animation tests
test( "jQuery.Animation( object, props, opts )", 4, function() {
"width": 200
};
- animation = jQuery.Animation( testObject, testDest, { "duration": 1 });
- animation.done(function() {
+ animation = jQuery.Animation( testObject, testDest, { "duration": 1 } );
+ animation.done( function() {
for ( var prop in testDest ) {
equal( testObject[ prop ], testDest[ prop ], "Animated: " + prop );
}
- animation.done(function() {
+ animation.done( function() {
deepEqual( testObject, testDest, "No unexpected properties" );
- });
- });
+ } );
+ } );
this.clock.tick( 10 );
-});
+} );
test( "Animate Option: step: function( percent, tween )", 1, function() {
var counter = {};
- jQuery( "#foo" ).animate({
+ jQuery( "#foo" ).animate( {
prop1: 1,
prop2: 2,
prop3: 3
duration: 1,
step: function( value, tween ) {
var calls = counter[ tween.prop ] = counter[ tween.prop ] || [];
+
// in case this is called multiple times for either, lets store it in
// 0 or 1 in the array
calls[ value === 0 ? 0 : 1 ] = value;
}
- }).queue( function( next ) {
+ } ).queue( function( next ) {
deepEqual( counter, {
- prop1: [0, 1],
- prop2: [0, 2],
- prop3: [0, 3]
- }, "Step function was called once at 0% and once at 100% for each property");
+ prop1: [ 0, 1 ],
+ prop2: [ 0, 2 ],
+ prop3: [ 0, 3 ]
+ }, "Step function was called once at 0% and once at 100% for each property" );
next();
- });
+ } );
this.clock.tick( 10 );
-});
+} );
test( "Animate callbacks have correct context", 2, function() {
var foo = jQuery( "#foo" );
- foo.animate({
+ foo.animate( {
height: 10
}, 10, function() {
equal( foo[ 0 ], this, "Complete callback after stop(true) `this` is element" );
- }).stop( true, true );
- foo.animate({
+ } ).stop( true, true );
+ foo.animate( {
height: 100
}, 10, function() {
equal( foo[ 0 ], this, "Complete callback `this` is element" );
- });
+ } );
this.clock.tick( 10 );
-});
+} );
test( "User supplied callback called after show when fx off (#8892)", 2, function() {
var foo = jQuery( "#foo" );
foo.fadeOut( 500, function() {
ok( jQuery( this ).is( ":hidden" ), "Element is hidden in callback" );
jQuery.fx.off = false;
- });
- });
+ } );
+ } );
this.clock.tick( 1000 );
-});
+} );
test( "animate should set display for disconnected nodes", function() {
expect( 18 );
fadeTo: [ "fast", 0.5 ],
slideDown: [ "fast" ],
show: [ 1 ],
- animate: [{ width: "show" }]
+ 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;
strictEqual( $divTest.show()[ 0 ].style.display, "block", "set display with show() for element with parentNode = document fragment" );
QUnit.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() {
strictEqual( this.style.display, "block", "set display to block with " + name );
QUnit.expectJqData( env, this, "olddisplay" );
- }];
+ } ];
jQuery.fn[ name ].apply( this, opt.concat( callback ) );
- });
- });
+ } );
+ } );
clock.tick( 400 );
-});
+} );
-test("Animation callback should not show animated element as :animated (#7157)", 1, function() {
+test( "Animation callback should not show animated element as :animated (#7157)", 1, function() {
var foo = jQuery( "#foo" );
- foo.animate({
+ foo.animate( {
opacity: 0
}, 100, function() {
- ok( !foo.is(":animated"), "The element is not animated" );
- });
+ ok( !foo.is( ":animated" ), "The element is not animated" );
+ } );
this.clock.tick( 100 );
-});
+} );
-test("Initial step callback should show element as :animated (#14623)", 1, function() {
+test( "Initial step callback should show element as :animated (#14623)", 1, function() {
var foo = jQuery( "#foo" );
- foo.animate({
+ foo.animate( {
opacity: 0
}, {
duration: 100,
step: function() {
- ok( foo.is(":animated"), "The element matches :animated inside step function" );
+ ok( foo.is( ":animated" ), "The element matches :animated inside step function" );
}
- });
+ } );
this.clock.tick( 1 );
foo.stop();
-});
+} );
test( "hide called on element within hidden parent should set display to none (#10045)", 3, function() {
- var hidden = jQuery(".hidden"),
- elems = jQuery("<div>hide</div><div>hide0</div><div>hide1</div>");
+ var hidden = jQuery( ".hidden" ),
+ elems = jQuery( "<div>hide</div><div>hide0</div><div>hide1</div>" );
hidden.append( elems );
elems.eq( 0 ).hide(),
elems.eq( 1 ).hide( 0 ),
elems.eq( 2 ).hide( 1 )
- ).done(function() {
+ ).done( function() {
strictEqual( elems.get( 0 ).style.display, "none", "hide() called on element within hidden parent should set display to none" );
strictEqual( elems.get( 1 ).style.display, "none", "hide( 0 ) called on element within hidden parent should set display to none" );
strictEqual( elems.get( 2 ).style.display, "none", "hide( 1 ) called on element within hidden parent should set display to none" );
elems.remove();
- });
+ } );
this.clock.tick( 10 );
-});
+} );
test( "hide, fadeOut and slideUp called on element width height and width = 0 should set display to none", 5, function() {
- var foo = jQuery("#foo"),
+ var foo = jQuery( "#foo" ),
i = 0,
elems = jQuery();
for ( ; i < 5; i++ ) {
- elems = elems.add("<div style='width:0;height:0;'></div>");
+ elems = elems.add( "<div style='width:0;height:0;'></div>" );
}
foo.append( elems );
elems.eq( 2 ).hide( 1 ),
elems.eq( 3 ).fadeOut(),
elems.eq( 4 ).slideUp()
- ).done(function() {
+ ).done( function() {
strictEqual( elems.get( 0 ).style.display, "none", "hide() called on element width height and width = 0 should set display to none" );
strictEqual( elems.get( 1 ).style.display, "none",
"hide( jQuery.noop ) called on element width height and width = 0 should set display to none" );
strictEqual( elems.get( 3 ).style.display, "none", "fadeOut() called on element width height and width = 0 should set display to none" );
strictEqual( elems.get( 4 ).style.display, "none", "slideUp() called on element width height and width = 0 should set display to none" );
- });
+ } );
this.clock.tick( 400 );
-});
+} );
test( "hide should not leave hidden inline elements visible (#14848)", 2, function() {
- var el = jQuery("#simon1");
+ var el = jQuery( "#simon1" );
el.hide( 1, function() {
equal( el.css( "display" ), "none", "hidden" );
el.hide( 1, function() {
equal( el.css( "display" ), "none", "still hidden" );
- });
- });
+ } );
+ } );
this.clock.tick( 100 );
-});
+} );
test( "Handle queue:false promises", 10, function() {
var foo = jQuery( "#foo" ).clone().addBack(),
step = 1;
- foo.animate({
+ foo.animate( {
top: 1
}, {
duration: 10,
complete: function() {
ok( step++ <= 2, "Step one or two" );
}
- }).animate({
+ } ).animate( {
bottom: 1
}, {
duration: 10,
ok( step > 2 && step < 5, "Step three or four" );
step++;
}
- });
+ } );
this.clock.tick( 10 );
foo.promise().done( function() {
equal( step++, 5, "steps 1-5: queue:false then queue:fx done" );
- foo.animate({
+ foo.animate( {
top: 10
}, {
duration: 10,
ok( step > 5 && step < 8, "Step six or seven" );
step++;
}
- }).animate({
+ } ).animate( {
bottom: 10
}, {
duration: 10,
ok( step > 7 && step < 10, "Step eight or nine" );
step++;
}
- }).promise().done( function() {
+ } ).promise().done( function() {
equal( step++, 10, "steps 6-10: queue:fx then queue:false" );
- });
+ } );
- });
+ } );
this.clock.tick( 10 );
-});
+} );
test( "multiple unqueued and promise", 4, function() {
var foo = jQuery( "#foo" ),
step = 1;
- foo.animate({
+ foo.animate( {
marginLeft: 300
}, {
duration: 500,
complete: function() {
strictEqual( step++, 2, "Step 2" );
}
- }).animate({
+ } ).animate( {
top: 100
}, {
duration: 1000,
complete: function() {
strictEqual( step++, 3, "Step 3" );
}
- }).animate({}, {
+ } ).animate( {}, {
duration: 2000,
queue: false,
complete: function() {
+
// no properties is a non-op and finishes immediately
strictEqual( step++, 1, "Step 1" );
}
- }).promise().done( function() {
+ } ).promise().done( function() {
strictEqual( step++, 4, "Step 4" );
- });
+ } );
this.clock.tick( 1000 );
-});
+} );
test( "animate does not change start value for non-px animation (#7109)", 1, function() {
- var parent = jQuery( "<div><div></div></div>" ).css({ width: 284, height: 1 }).appendTo( "#qunit-fixture" ),
- child = parent.children().css({ fontSize: "98.6in", width: "0.01em", height: 1 }),
+ var parent = jQuery( "<div><div></div></div>" ).css( { width: 284, height: 1 } ).appendTo( "#qunit-fixture" ),
+ child = parent.children().css( { fontSize: "98.6in", width: "0.01em", height: 1 } ),
actual = parseFloat( child.css( "width" ) ),
computed = [];
- child.animate({ width: "0%" }, {
+ child.animate( { width: "0%" }, {
duration: 1,
step: function() {
computed.push( parseFloat( child.css( "width" ) ) );
}
- }).queue( function( next ) {
+ } ).queue( function( next ) {
var ratio = computed[ 0 ] / actual;
- ok( ratio > 0.9 && ratio < 1.1 , "Starting width was close enough" );
+ ok( ratio > 0.9 && ratio < 1.1, "Starting width was close enough" );
next();
parent.remove();
- });
+ } );
this.clock.tick( 10 );
-});
+} );
test( "non-px animation handles non-numeric start (#11971)", 2, function() {
- var foo = jQuery("#foo"),
- initial = foo.css("backgroundPositionX");
+ var foo = jQuery( "#foo" ),
+ initial = foo.css( "backgroundPositionX" );
if ( !initial ) {
- expect(1);
+ expect( 1 );
ok( true, "Style property not understood" );
return;
}
- foo.animate({ backgroundPositionX: "42%" }, {
+ foo.animate( { backgroundPositionX: "42%" }, {
duration: 1,
progress: function( anim, percent ) {
if ( percent ) {
done: function() {
equal( jQuery.style( this, "backgroundPositionX" ), "42%", "End reached" );
}
- });
+ } );
this.clock.tick( 10 );
-});
+} );
QUnit.test( "Animation callbacks (#11797)", function( assert ) {
assert.expect( 16 );
test( "Animate properly sets overflow hidden when animating width/height (#12117)", 8, function() {
jQuery.each( [ "height", "width" ], function( _, prop ) {
jQuery.each( [ 100, 0 ], function( _, value ) {
- var div = jQuery("<div>").css( "overflow", "auto" ),
+ var div = jQuery( "<div>" ).css( "overflow", "auto" ),
props = {};
props[ prop ] = value;
div.animate( props, 1 );
div.stop();
equal( div.css( "overflow" ), "auto",
"overflow: auto restored after animating " + prop + " to " + value );
- });
- });
-});
+ } );
+ } );
+} );
test( "Each tick of the timer loop uses a fresh time (#12837)", function() {
var lastVal,
- tmp = jQuery({
+ tmp = jQuery( {
test: 0
- });
+ } );
expect( 3 );
- tmp.animate({
+ tmp.animate( {
test: 100
}, {
step: function( p, fx ) {
ok( fx.now !== lastVal, "Current value is not the last value: " + lastVal + " - " + fx.now );
lastVal = fx.now;
}
- });
+ } );
this.clock.tick( 1 );
// now that we have a new time, run another tick
jQuery.fx.tick();
tmp.stop();
-});
+} );
test( "Animations with 0 duration don't ease (#12273)", 1, function() {
jQuery.easing.test = function() {
ok( false, "Called easing" );
};
- jQuery( "#foo" ).animate({
+ jQuery( "#foo" ).animate( {
height: 100
}, {
duration: 0,
complete: function() {
equal( jQuery( this ).height(), 100, "Height is 100" );
}
- });
+ } );
delete jQuery.easing.test;
-});
+} );
+
+jQuery.map( [ "toggle", "slideToggle", "fadeToggle" ], function( method ) {
-jQuery.map([ "toggle", "slideToggle", "fadeToggle" ], function ( method ) {
// this test would look a lot better if we were using something to override
// the default timers
var duration = 1500;
function secondToggle() {
var stopped = parseFloat( element.css( check ) );
tested = false;
- element[ method ]({
+ element[ method ]( {
duration: duration,
step: function( p, fx ) {
if ( fx.pos > 0.1 && fx.prop === check && !tested ) {
element.stop();
}
}
- });
+ } );
}
var tested,
original,
check = method === "slideToggle" ? "height" : "opacity",
- element = jQuery("#foo").height( 200 );
+ element = jQuery( "#foo" ).height( 200 );
expect( 4 );
- element[ method ]({
+ element[ method ]( {
duration: duration,
easing: "linear",
step: function( p, fx ) {
}
},
always: secondToggle
- });
+ } );
+
//FIXME figure out why 470
this.clock.tick( 470 );
- });
-});
+ } );
+} );
test( "jQuery.fx.start & jQuery.fx.stop hook points", function() {
var oldStart = jQuery.fx.start,
oldStop = jQuery.fx.stop,
- foo = jQuery({ foo: 0 });
+ foo = jQuery( { foo: 0 } );
expect( 3 );
};
// calls start
- foo.animate({ foo: 1 }, { queue: false });
+ foo.animate( { foo: 1 }, { queue: false } );
+
// calls start
- foo.animate({ foo: 2 }, { queue: false });
+ foo.animate( { foo: 2 }, { queue: false } );
foo.stop();
+
// calls stop
jQuery.fx.tick();
// cleanup
jQuery.fx.start = oldStart;
jQuery.fx.stop = oldStop;
-});
+} );
test( ".finish() completes all queued animations", function() {
var animations = {
height: 100,
width: 100
},
- div = jQuery("<div>");
+ div = jQuery( "<div>" );
expect( 11 );
jQuery.each( animations, function( prop, value ) {
var anim = {};
anim[ prop ] = value;
+
// the delay shouldn't matter at all!
div.css( prop, 1 ).animate( anim, function() {
ok( true, "Called animation callback for " + prop );
- }).delay( 100 );
- });
+ } ).delay( 100 );
+ } );
equal( div.queue().length, 8, "8 animations in the queue" );
div.finish();
jQuery.each( animations, function( prop, value ) {
equal( parseFloat( div.css( prop ) ), value, prop + " finished at correct value" );
- });
+ } );
equal( div.queue().length, 0, "empty queue when done" );
- equal( div.is(":animated"), false, ":animated doesn't match" );
+ equal( div.is( ":animated" ), false, ":animated doesn't match" );
// cleanup
div.remove();
+
// leaves a "shadow timer" which does nothing around, need to force a tick
jQuery.fx.tick();
-});
+} );
test( ".finish( false ) - unqueued animations", function() {
var animations = {
height: 100,
width: 100
},
- div = jQuery("<div>");
+ div = jQuery( "<div>" );
expect( 10 );
complete: function() {
ok( true, "Called animation callback for " + prop );
}
- });
- });
+ } );
+ } );
equal( div.queue().length, 0, "0 animations in the queue" );
div.finish( false );
jQuery.each( animations, function( prop, value ) {
equal( parseFloat( div.css( prop ) ), value, prop + " finished at correct value" );
- });
- equal( div.is(":animated"), false, ":animated doesn't match" );
+ } );
+ equal( div.is( ":animated" ), false, ":animated doesn't match" );
// cleanup
div.remove();
+
// leaves a "shadow timer" which does nothing around, need to force a tick
jQuery.fx.tick();
-});
+} );
test( ".finish( \"custom\" ) - custom queue animations", function() {
var animations = {
height: 100,
width: 100
},
- div = jQuery("<div>");
+ div = jQuery( "<div>" );
expect( 11 );
complete: function() {
ok( true, "Called animation callback for " + prop );
}
- });
- });
+ } );
+ } );
equal( div.queue( "custom" ).length, 4, "4 animations in the queue" );
+
// start the first animation
div.dequeue( "custom" );
- equal( div.is(":animated"), true, ":animated matches" );
+ equal( div.is( ":animated" ), true, ":animated matches" );
div.finish( "custom" );
jQuery.each( animations, function( prop, value ) {
equal( parseFloat( div.css( prop ) ), value, prop + " finished at correct value" );
- });
- equal( div.is(":animated"), false, ":animated doesn't match" );
+ } );
+ equal( div.is( ":animated" ), false, ":animated doesn't match" );
// cleanup
div.remove();
+
// leaves a "shadow timer" which does nothing around, need to force a tick
jQuery.fx.tick();
-});
+} );
test( ".finish() calls finish of custom queue functions", function() {
function queueTester( next, hooks ) {
hooks.stop = function( gotoEnd ) {
inside++;
- equal( this, div[0] );
- ok( gotoEnd, "hooks.stop(true) called");
+ equal( this, div[ 0 ] );
+ ok( gotoEnd, "hooks.stop(true) called" );
};
}
var div = jQuery( "<div>" ),
equal( outside, 2, "2 finish callbacks" );
div.remove();
-});
+} );
test( ".finish() is applied correctly when multiple elements were animated (#13937)", function() {
expect( 3 );
- var elems = jQuery("<a>0</a><a>1</a><a>2</a>");
+ var elems = jQuery( "<a>0</a><a>1</a><a>2</a>" );
elems.animate( { opacity: 0 }, 1500 ).animate( { opacity: 1 }, 1500 );
- setTimeout(function() {
+ setTimeout( function() {
elems.eq( 1 ).finish();
ok( !elems.eq( 1 ).queue().length, "empty queue for .finish()ed element" );
ok( elems.eq( 0 ).queue().length, "non-empty queue for preceding element" );
}, 100 );
this.clock.tick( 1500 );
-});
+} );
test( "slideDown() after stop() (#13483)", 2, function() {
var ul = jQuery( "<ul style='height: 100px; display: block;'></ul>" )
- .appendTo("#qunit-fixture"),
+ .appendTo( "#qunit-fixture" ),
origHeight = ul.height(),
clock = this.clock;
ul.remove();
clock.tick( 10 );
- });
+ } );
clock.tick( 10 );
-});
+} );
test( "Respect display value on inline elements (#14824)", 2, function() {
var clock = this.clock,
jQuery( "#qunit-fixture" ).append( fromStyleSheet, fromStyleAttr );
- fromStyleSheet.slideUp(function() {
+ fromStyleSheet.slideUp( function() {
jQuery( this ).slideDown( function() {
equal( jQuery( this ).css( "display" ), "block",
"Respect previous display value (from stylesheet) on span element" );
- });
- });
+ } );
+ } );
fromStyleAttr.slideUp( function() {
jQuery( this ).slideDown( function() {
equal( jQuery( this ).css( "display" ), "block",
"Respect previous display value (from style attribute) on span element" );
- });
- });
+ } );
+ } );
clock.tick( 800 );
-});
+} );
-})();
+} )();
jQuery( "#simon1" ).click();
assert.equal( clickCounter, 1, "Check that click, triggers onclick event handler on an a tag also" );
- elem = jQuery("<img />").load(function(){
- ok( true, "Trigger the load event, using the shortcut .load() (#2819)");
- }).load();
+ elem = jQuery( "<img />" ).load( function() {
+ ok( true, "Trigger the load event, using the shortcut .load() (#2819)" );
+ } ).load();
// manually clean up detached elements
elem.remove();
//$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
} );
QUnit.test( ".off() removes the expando when there's no more data", function( assert ) {
+
// Support: IE 8 only
// IE 8 gets the expando removed via removeAttribute so the second assertion
// won't be reached.
assert.strictEqual( jQuery( "<p/>" ).appendTo( "<div/>" ).end().length, jQuery( "<p>test</p>" ).appendTo( "<div/>" ).end().length, "Elements created with createElement and with createDocumentFragment should be treated alike" );
} );
-
test( "html() - script exceptions bubble (#11743)", function() {
expect( 2 );
- throws(function() {
- jQuery("#qunit-fixture").html("<script>undefined(); ok( false, 'Exception not thrown' );</script>");
+ throws( function() {
+ jQuery( "#qunit-fixture" ).html( "<script>undefined(); ok( false, 'Exception not thrown' );</script>" );
ok( false, "Exception ignored" );
}, "Exception bubbled from inline script" );
if ( jQuery.ajax ) {
- throws(function() {
- jQuery("#qunit-fixture").html("<script src='data/badcall.js'></script>");
+ throws( function() {
+ jQuery( "#qunit-fixture" ).html( "<script src='data/badcall.js'></script>" );
ok( false, "Exception ignored" );
}, "Exception thrown in remote script" );
} else {
ok( true, "No jQuery.ajax" );
}
-});
+} );
QUnit.test( "checked state is cloned with clone()", function( assert ) {
the iframe window and the "jQuery" symbol is used to access any static methods.
*/
-test("empty set", function() {
- expect(2);
+test( "empty set", function() {
+ expect( 2 );
strictEqual( jQuery().offset(), undefined, "offset() returns undefined for empty set (#11962)" );
strictEqual( jQuery().position(), undefined, "position() returns undefined for empty set (#11962)" );
-});
+} );
-test("object without getBoundingClientRect", function() {
- expect(2);
+test( "object without getBoundingClientRect", function() {
+ 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();
equal( result.top, 0, "Check top" );
equal( result.left, 0, "Check left" );
-});
+} );
QUnit.test( "disconnected element", function( assert ) {
assert.expect( 2 );
QUnit.test( "chaining", function( assert ) {
assert.expect( 3 );
var coords = { "top": 1, "left": 1 };
- equal( jQuery("#absolute-1").offset(coords).selector, "#absolute-1", "offset(coords) returns jQuery object" );
- equal( jQuery("#non-existent").offset(coords).selector, "#non-existent", "offset(coords) with empty jQuery set returns jQuery object" );
- equal( jQuery("#absolute-1").offset(undefined).selector, "#absolute-1", "offset(undefined) returns jQuery object (#5571)" );
-});
+ equal( jQuery( "#absolute-1" ).offset( coords ).selector, "#absolute-1", "offset(coords) returns jQuery object" );
+ equal( jQuery( "#non-existent" ).offset( coords ).selector, "#non-existent", "offset(coords) with empty jQuery set returns jQuery object" );
+ equal( jQuery( "#absolute-1" ).offset( undefined ).selector, "#absolute-1", "offset(undefined) returns jQuery object (#5571)" );
+} );
QUnit.test( "offsetParent", function( assert ) {
assert.expect( 13 );
QUnit.module( "ready" );
-(function(){
+( function() {
var notYetReady, noEarlyExecution,
order = [],
args = {};
// Create an event handler.
function makeHandler( testId ) {
+
// When returned function is executed, push testId onto `order` array
// to ensure execution order. Also, store event handler arg to ensure
// the correct arg is being passed into the event handler.
}
// Bind to the ready event in every possible way.
- jQuery(makeHandler("a"));
- jQuery(document).ready(makeHandler("b"));
- jQuery(document).on("ready.readytest", makeHandler("c"));
+ jQuery( makeHandler( "a" ) );
+ jQuery( document ).ready( makeHandler( "b" ) );
+ jQuery( document ).on( "ready.readytest", makeHandler( "c" ) );
// Do it twice, just to be sure.
- jQuery(makeHandler("d"));
- jQuery(document).ready(makeHandler("e"));
- jQuery(document).on("ready.readytest", makeHandler("f"));
+ jQuery( makeHandler( "d" ) );
+ jQuery( document ).ready( makeHandler( "e" ) );
+ jQuery( document ).on( "ready.readytest", makeHandler( "f" ) );
noEarlyExecution = order.length === 0;
// This assumes that QUnit tests are run on DOM ready!
- QUnit.test("jQuery ready", function() {
- expect(10);
+ QUnit.test( "jQuery ready", function() {
+ expect( 10 );
- ok(noEarlyExecution, "Handlers bound to DOM ready should not execute before DOM ready");
+ ok( noEarlyExecution, "Handlers bound to DOM ready should not execute before DOM ready" );
// Ensure execution order.
- deepEqual(order, ["a", "b", "d", "e", "c", "f"], "Bound DOM ready handlers should execute in on-order, but those bound with jQuery(document).on( 'ready', fn ) will always execute last");
+ deepEqual( order, [ "a", "b", "d", "e", "c", "f" ], "Bound DOM ready handlers should execute in on-order, but those bound with jQuery(document).on( 'ready', fn ) will always execute last" );
// Ensure handler argument is correct.
- equal(args["a"], jQuery, "Argument passed to fn in jQuery( fn ) should be jQuery");
- equal(args["b"], jQuery, "Argument passed to fn in jQuery(document).ready( fn ) should be jQuery");
- ok(args["c"] instanceof jQuery.Event, "Argument passed to fn in jQuery(document).on( 'ready', fn ) should be an event object");
+ equal( args[ "a" ], jQuery, "Argument passed to fn in jQuery( fn ) should be jQuery" );
+ equal( args[ "b" ], jQuery, "Argument passed to fn in jQuery(document).ready( fn ) should be jQuery" );
+ ok( args[ "c" ] instanceof jQuery.Event, "Argument passed to fn in jQuery(document).on( 'ready', fn ) should be an event object" );
order = [];
// Now that the ready event has fired, again bind to the ready event
// in every possible way. These event handlers should execute immediately.
- jQuery(makeHandler("g"));
- equal(order.pop(), "g", "Event handler should execute immediately");
- equal(args["g"], jQuery, "Argument passed to fn in jQuery( fn ) should be jQuery");
+ jQuery( makeHandler( "g" ) );
+ equal( order.pop(), "g", "Event handler should execute immediately" );
+ equal( args[ "g" ], jQuery, "Argument passed to fn in jQuery( fn ) should be jQuery" );
- jQuery(document).ready(makeHandler("h"));
- equal(order.pop(), "h", "Event handler should execute immediately");
- equal(args["h"], jQuery, "Argument passed to fn in jQuery(document).ready( fn ) should be jQuery");
+ jQuery( document ).ready( makeHandler( "h" ) );
+ equal( order.pop(), "h", "Event handler should execute immediately" );
+ equal( args[ "h" ], jQuery, "Argument passed to fn in jQuery(document).ready( fn ) should be jQuery" );
- jQuery(document).on("ready.readytest", makeHandler("never"));
- equal(order.length, 0, "Event handler should never execute since DOM ready has already passed");
+ jQuery( document ).on( "ready.readytest", makeHandler( "never" ) );
+ equal( order.length, 0, "Event handler should never execute since DOM ready has already passed" );
// Cleanup.
- jQuery(document).off("ready.readytest");
- });
+ jQuery( document ).off( "ready.readytest" );
+ } );
} )();
assert.t( "ID selector with existing ID descendant", "#firstp #simon1", [ "simon1" ] );
assert.t( "ID selector with non-existant 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 > #台北", [ "台北" ] );
var nothiddendiv;
- 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 Is Not Equal", "#ap a[hreflang!='en']", [ "google","groups","anchor1" ] );
+ assert.t( "Attribute Contains", "a[href *= 'google']", [ "google", "groups" ] );
+ assert.t( "Attribute Is Not Equal", "#ap a[hreflang!='en']", [ "google", "groups", "anchor1" ] );
assert.t( "Empty values", "#select1 option[value='']", [ "option1a" ] );
- assert.t( "Empty values", "#select1 option[value!='']", [ "option1b","option1c","option1d" ] );
+ assert.t( "Empty values", "#select1 option[value!='']", [ "option1b", "option1c", "option1d" ] );
assert.t( "Select options via :selected", "#select1 option:selected", [ "option1a" ] );
assert.t( "Select options via :selected", "#select2 option:selected", [ "option2d" ] );
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 + "']" );
}
}
- });
+ } );
} )();