( function() { // Can't test what ain't there if ( !jQuery.fx ) { return; } var oldRaf = window.requestAnimationFrame, hideOptions = { inline: function() { jQuery.style( this, "display", "none" ); }, cascade: function() { this.className = "hidden"; } }; QUnit.module( "effects", { setup: function() { window.requestAnimationFrame = null; this.sandbox = sinon.sandbox.create(); this.clock = this.sandbox.useFakeTimers( 505877050 ); this._oldInterval = jQuery.fx.interval; jQuery.fx.step = {}; jQuery.fx.interval = 10; jQuery.now = Date.now; }, teardown: function() { this.sandbox.restore(); jQuery.now = Date.now; jQuery.fx.stop(); jQuery.fx.interval = this._oldInterval; window.requestAnimationFrame = oldRaf; return moduleTeardown.apply( this, arguments ); } } ); QUnit[ jQuery.find.compile ? "test" : "skip" ]( "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" ); } ); QUnit.test( "show() basic", function( assert ) { assert.expect( 1 ); var div = jQuery( "
" ).hide().appendTo( "#qunit-fixture" ).show(); assert.equal( div.css( "display" ), "block", "Make sure pre-hidden divs show" ); // Clean up the detached node div.remove(); } ); QUnit.test( "show()", function( assert ) { assert.expect( 27 ); var div, speeds, test, hiddendiv = jQuery( "div.hidden" ); assert.equal( jQuery.css( hiddendiv[ 0 ], "display" ), "none", "hiddendiv is display: none" ); hiddendiv.css( "display", "block" ); assert.equal( jQuery.css( hiddendiv[ 0 ], "display" ), "block", "hiddendiv is display: block" ); hiddendiv.show(); assert.equal( jQuery.css( hiddendiv[ 0 ], "display" ), "block", "hiddendiv is display: block" ); hiddendiv.css( "display", "" ); div = jQuery( "#fx-queue div" ).slice( 0, 4 ); div.show().each( function() { assert.notEqual( this.style.display, "none", "don't change any
with display block" ); } ); speeds = { "null speed": null, "undefined speed": undefined, "false speed": false }; jQuery.each( speeds, function( name, speed ) { var pass = true; div.hide().show( speed ).each( function() { if ( this.style.display === "none" ) { pass = false; } } ); assert.ok( pass, "Show with " + name ); } ); jQuery.each( speeds, function( name, speed ) { var pass = true; div.hide().show( speed, function() { pass = false; } ); assert.ok( pass, "Show with " + name + " does not call animate callback" ); } ); // Tolerate data from show()/hide() assert.expectJqData( this, div, "olddisplay" ); jQuery( "
" + "

" + "
" + "
" ).appendTo( "#qunit-fixture" ).find( "*" ).css( "display", "none" ); 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" }; jQuery.each( test, function( selector, expected ) { var elem = jQuery( selector, "#show-tests" ).show(); assert.equal( elem.css( "display" ), expected, "Show using correct display type for " + selector ); } ); jQuery( "#show-tests" ).remove(); // Make sure that showing or hiding a text node doesn't cause an error jQuery( "
test
text test" ).show().remove(); jQuery( "
test
text test" ).hide().remove(); } ); supportjQuery.each( hideOptions, function( type, setup ) { QUnit.test( "show(Number) - " + type + " hidden", function( assert ) { assert.expect( 30 ); jQuery( "
" + "

" + "" + "
" + "
" ).appendTo( "#qunit-fixture" ).find( "*" ).each( setup ); // 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", "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 ) { jQuery( selector, "#show-tests" ).show( 100 ); } ); this.clock.tick( 50 ); jQuery.each( test, function( selector, expected ) { jQuery( selector, "#show-tests" ).each( function() { assert.equal( jQuery( this ).css( "display" ), expected === "inline" ? "inline-block" : expected, "Correct display type during animation for " + selector ); } ); } ); this.clock.tick( 50 ); jQuery.each( test, function( selector, expected ) { jQuery( selector, "#show-tests" ).each( function() { assert.equal( jQuery( this ).css( "display" ), expected, "Correct display type after animation for " + selector ); } ); } ); jQuery( "#show-tests" ).remove(); } ); } ); // Supports #7397 supportjQuery.each( hideOptions, function( type, setup ) { QUnit.test( "Persist correct display value - " + type + " hidden", function( assert ) { assert.expect( 3 ); jQuery( "
foo
" ) .appendTo( "#qunit-fixture" ).find( "*" ).each( setup ); var $span = jQuery( "#show-tests span" ), displayNone = $span.css( "display" ), display = "", clock = this.clock; $span.show(); display = $span.css( "display" ); $span.hide(); $span.fadeIn( 100, function() { assert.equal( $span.css( "display" ), display, "Expecting display: " + display ); $span.fadeOut( 100, function() { assert.equal( $span.css( "display" ), displayNone, "Expecting display: " + displayNone ); $span.fadeIn( 100, function() { assert.equal( $span.css( "display" ), display, "Expecting display: " + display ); } ); } ); } ); clock.tick( 300 ); assert.expectJqData( this, $span, "olddisplay" ); } ); } ); QUnit.test( "animate(Hash, Object, Function)", function( assert ) { assert.expect( 1 ); var hash = { opacity: "show" }, hashCopy = jQuery.extend( {}, hash ); jQuery( "#foo" ).animate( hash, 0, function() { assert.equal( hash.opacity, hashCopy.opacity, "Check if animate changed the hash parameter" ); } ); } ); QUnit.test( "animate relative values", function( assert ) { var value = 40, clock = this.clock, bases = [ "%", "px", "em" ], adjustments = [ "px", "em" ], container = jQuery( "
" ) .css( { position: "absolute", height: "50em", width: "50em" } ), animations = bases.length * adjustments.length; assert.expect( 2 * animations ); jQuery.each( bases, function( _, baseUnit ) { jQuery.each( adjustments, function( _, adjustUnit ) { var base = value + baseUnit, adjust = { height: "+=2" + adjustUnit, width: "-=2" + adjustUnit }, elem = jQuery( "
" ) .appendTo( container.clone().appendTo( "#qunit-fixture" ) ) .css( { position: "absolute", height: base, width: value + adjustUnit } ), baseScale = elem[ 0 ].offsetHeight / value, adjustScale = elem[ 0 ].offsetWidth / value; elem.css( "width", base ).animate( adjust, 100, function() { assert.equal( this.offsetHeight, value * baseScale + 2 * adjustScale, baseUnit + "+=" + adjustUnit ); assert.equal( this.offsetWidth, value * baseScale - 2 * adjustScale, baseUnit + "-=" + adjustUnit ); } ); clock.tick( 100 ); } ); } ); } ); QUnit.test( "animate negative height", function( assert ) { assert.expect( 1 ); jQuery( "#foo" ).animate( { height: -100 }, 100, function() { assert.equal( this.offsetHeight, 0, "Verify height." ); } ); this.clock.tick( 100 ); } ); QUnit.test( "animate negative margin", function( assert ) { assert.expect( 1 ); jQuery( "#foo" ).animate( { "marginTop": -100 }, 100, function() { assert.equal( jQuery( this ).css( "marginTop" ), "-100px", "Verify margin." ); } ); this.clock.tick( 100 ); } ); QUnit.test( "animate negative margin with px", function( assert ) { assert.expect( 1 ); jQuery( "#foo" ).animate( { marginTop: "-100px" }, 100, function() { assert.equal( jQuery( this ).css( "marginTop" ), "-100px", "Verify margin." ); } ); this.clock.tick( 100 ); } ); QUnit.test( "animate negative padding", function( assert ) { assert.expect( 1 ); jQuery( "#foo" ).animate( { "paddingBottom": -100 }, 100, function() { assert.equal( jQuery( this ).css( "paddingBottom" ), "0px", "Verify paddingBottom." ); } ); this.clock.tick( 100 ); } ); QUnit.test( "animate block as inline width/height", function( assert ) { assert.expect( 3 ); jQuery( "#foo" ).css( { display: "inline", width: "", height: "" } ).animate( { width: 42, height: 42 }, 100, function() { assert.equal( jQuery( this ).css( "display" ), "inline-block", "inline-block was set on non-floated inline element when animating width/height" ); assert.equal( this.offsetWidth, 42, "width was animated" ); assert.equal( this.offsetHeight, 42, "height was animated" ); } ); this.clock.tick( 100 ); } ); QUnit.test( "animate native inline width/height", function( assert ) { assert.expect( 3 ); jQuery( "#foo" ).css( { display: "", width: "", height: "" } ) .append( "text" ) .children( "span" ) .animate( { width: 42, height: 42 }, 100, function() { assert.equal( jQuery( this ).css( "display" ), "inline-block", "inline-block was set on non-floated inline element when animating width/height" ); assert.equal( this.offsetWidth, 42, "width was animated" ); assert.equal( this.offsetHeight, 42, "height was animated" ); } ); this.clock.tick( 100 ); } ); QUnit.test( "animate block width/height", function( assert ) { assert.expect( 3 ); jQuery( "
" ).appendTo( "#qunit-fixture" ).css( { display: "block", width: 20, height: 20, paddingLeft: 60 } ).animate( { width: 42, height: 42 }, { duration: 100, step: function() { if ( jQuery( this ).width() > 42 ) { assert.ok( false, "width was incorrectly augmented during animation" ); } }, complete: function() { assert.equal( jQuery( this ).css( "display" ), "block", "inline-block was not set on block element when animating width/height" ); assert.equal( jQuery( this ).width(), 42, "width was animated" ); assert.equal( jQuery( this ).height(), 42, "height was animated" ); } } ); this.clock.tick( 100 ); } ); QUnit.test( "animate table width/height", function( assert ) { assert.expect( 1 ); jQuery( "#table" ).animate( { width: 42, height: 42 }, 100, function() { assert.equal( jQuery( this ).css( "display" ), "table", "display mode is correct" ); } ); this.clock.tick( 100 ); } ); QUnit.test( "animate table-row width/height", function( assert ) { assert.expect( 3 ); var tr = jQuery( "#table" ) .attr( { "cellspacing": 0, "cellpadding": 0, "border": 0 } ) .html( "
" ) .find( "tr" ); tr.animate( { width: 10, height: 10 }, 100, function() { assert.equal( jQuery( this ).css( "display" ), "table-row", "display mode is correct" ); assert.equal( this.offsetWidth, 20, "width animated to shrink wrap point" ); assert.equal( this.offsetHeight, 20, "height animated to shrink wrap point" ); } ); this.clock.tick( 100 ); } ); QUnit.test( "animate table-cell width/height", function( assert ) { assert.expect( 3 ); var td = jQuery( "#table" ) .attr( { "cellspacing": 0, "cellpadding": 0, "border": 0 } ) .html( "
" ) .find( "td" ); td.animate( { width: 10, height: 10 }, 100, function() { assert.equal( jQuery( this ).css( "display" ), "table-cell", "display mode is correct" ); assert.equal( this.offsetWidth, 20, "width animated to shrink wrap point" ); assert.equal( this.offsetHeight, 20, "height animated to shrink wrap point" ); } ); this.clock.tick( 100 ); } ); QUnit.test( "animate percentage(%) on width/height", function( assert ) { assert.expect( 2 ); var $div = jQuery( "
" ) .appendTo( "#qunit-fixture" ).children( "div" ); $div.animate( { width: "25%", height: "25%" }, 13, function() { var $this = jQuery( this ); assert.equal( $this.css( "width" ), "15px", "Width was animated to 15px rather than 25px" ); assert.equal( $this.css( "height" ), "15px", "Height was animated to 15px rather than 25px" ); } ); this.clock.tick( 20 ); } ); QUnit.test( "animate resets overflow-x and overflow-y when finished", function( assert ) { assert.expect( 2 ); jQuery( "#foo" ) .css( { display: "block", width: 20, height: 20, overflowX: "visible", overflowY: "auto" } ) .animate( { width: 42, height: 42 }, 100, function() { assert.equal( this.style.overflowX, "visible", "overflow-x is visible" ); assert.equal( this.style.overflowY, "auto", "overflow-y is auto" ); } ); this.clock.tick( 100 ); } ); /* // This test ends up being flaky depending upon the CPU load QUnit.test("animate option (queue === false)", function( assert ) { assert.expect(1); QUnit.stop(); var order = []; var $foo = jQuery("#foo"); $foo.animate({width:"100px"}, 3000, function () { // should finish after unqueued animation so second order.push(2); assert.deepEqual( order, [ 1, 2 ], "Animations finished in the correct order" ); QUnit.start(); }); $foo.animate({fontSize:"2em"}, {queue:false, duration:10, complete:function () { // short duration and out of queue so should finish first order.push(1); }}); }); */ QUnit.test( "animate option { queue: false }", function( assert ) { assert.expect( 2 ); var foo = jQuery( "#foo" ); foo.animate( { fontSize: "2em" }, { queue: false, duration: 10, complete: function() { assert.ok( true, "Animation Completed" ); } } ); this.clock.tick( 10 ); assert.equal( foo.queue().length, 0, "Queue is empty" ); } ); QUnit.test( "animate option { queue: true }", function( assert ) { assert.expect( 2 ); var foo = jQuery( "#foo" ); foo.animate( { fontSize: "2em" }, { queue: true, duration: 10, complete: function() { assert.ok( true, "Animation Completed" ); } } ); assert.notEqual( foo.queue().length, 0, "Default queue is not empty" ); //clear out existing timers before next test this.clock.tick( 10 ); } ); QUnit.test( "animate option { queue: 'name' }", function( assert ) { assert.expect( 5 ); var foo = jQuery( "#foo" ), origWidth = parseFloat( foo.css( "width" ) ), order = []; foo.animate( { width: origWidth + 100 }, { queue: "name", duration: 1, complete: function() { // second callback function order.push( 2 ); assert.equal( parseFloat( foo.css( "width" ) ), origWidth + 100, "Animation ended" ); assert.equal( foo.queue( "name" ).length, 1, "Queue length of 'name' queue" ); } } ).queue( "name", function() { // last callback function assert.deepEqual( order, [ 1, 2 ], "Callbacks in expected order" ); } ); // this is the first callback function that should be called order.push( 1 ); assert.equal( parseFloat( foo.css( "width" ) ), origWidth, "Animation does not start on its own." ); assert.equal( foo.queue( "name" ).length, 2, "Queue length of 'name' queue" ); foo.dequeue( "name" ); this.clock.tick( 10 ); } ); QUnit.test( "animate with no properties", function( assert ) { assert.expect( 2 ); var foo, divs = jQuery( "div" ), count = 0; divs.animate( {}, function() { count++; } ); assert.equal( divs.length, count, "Make sure that callback is called for each element in the set." ); foo = jQuery( "#foo" ); foo.animate( {} ); foo.animate( { top: 10 }, 100, function() { assert.ok( true, "Animation was properly dequeued." ); } ); this.clock.tick( 100 ); } ); QUnit.test( "animate duration 0", function( assert ) { assert.expect( 11 ); var $elem, $elems = jQuery( [ { a:0 }, { a:0 } ] ), counter = 0; assert.equal( jQuery.timers.length, 0, "Make sure no animation was running from another test" ); $elems.eq( 0 ).animate( { a:1 }, 0, function() { assert.ok( true, "Animate a simple property." ); counter++; } ); // Failed until [6115] assert.equal( jQuery.timers.length, 0, "Make sure synchronic animations are not left on jQuery.timers" ); assert.equal( counter, 1, "One synchronic animations" ); $elems.animate( { a:2 }, 0, function() { assert.ok( true, "Animate a second simple property." ); counter++; } ); assert.equal( counter, 3, "Multiple synchronic animations" ); $elems.eq( 0 ).animate( { a:3 }, 0, function() { assert.ok( true, "Animate a third simple property." ); counter++; } ); $elems.eq( 1 ).animate( { a:3 }, 200, function() { counter++; // Failed until [6115] assert.equal( counter, 5, "One synchronic and one asynchronic" ); } ); this.clock.tick( 200 ); $elem = jQuery( "
" ); $elem.show( 0, function() { assert.ok( true, "Show callback with no duration" ); } ); $elem.hide( 0, function() { assert.ok( true, "Hide callback with no duration" ); } ); // manually clean up detached elements $elem.remove(); } ); QUnit.test( "animate hyphenated properties", function( assert ) { assert.expect( 1 ); jQuery( "#foo" ) .css( "font-size", 10 ) .animate( { "font-size": 20 }, 200, function() { assert.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 ); } ); QUnit.test( "animate non-element", function( assert ) { assert.expect( 1 ); var obj = { test: 0 }; jQuery( obj ).animate( { test: 200 }, 200, function() { assert.equal( obj.test, 200, "The custom property should be modified." ); } ); this.clock.tick( 200 ); } ); QUnit.test( "stop()", function( assert ) { assert.expect( 4 ); var $one, $two, $foo = jQuery( "#foo" ), w = 0, nw; $foo.hide().css( "width", 200 ) .animate( { "width": "show" }, 1500 ); this.clock.tick( 100 ); nw = $foo.css( "width" ); assert.notEqual( parseFloat( nw ), w, "An animation occurred " + nw + " " + w + "px" ); $foo.stop(); nw = $foo.css( "width" ); assert.notEqual( parseFloat( nw ), w, "Stop didn't reset the animation " + nw + " " + w + "px" ); this.clock.tick( 100 ); $foo.removeData(); $foo.removeData( undefined, true ); assert.equal( nw, $foo.css( "width" ), "The animation didn't continue" ); $one = jQuery( "#fadein" ); $two = jQuery( "#show" ); $one.fadeTo( 100, 0, function() { $one.stop(); } ); this.clock.tick( 100 ); $two.fadeTo( 100, 0, function() { assert.equal( $two.css( "opacity" ), "0", "Stop does not interfere with animations on other elements (#6641)" ); // Reset styles $one.add( $two ).css( "opacity", "" ); } ); this.clock.tick( 100 ); } ); // In IE9 inside testswarm this test doesn't work properly ( function() { var type = "test"; if ( QUnit.isSwarm && /msie 9\.0/i.test( window.navigator.userAgent ) ) { type = "skip"; } QUnit[ type ]( "stop() - several in queue", function( assert ) { assert.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" } ); this.clock.tick( 1 ); jQuery.fx.tick(); assert.equal( $foo.queue().length, 3, "3 in the queue" ); nw = $foo.css( "width" ); assert.notEqual( parseFloat( nw ), 1, "An animation occurred " + nw ); $foo.stop(); assert.equal( $foo.queue().length, 2, "2 in the queue" ); nw = $foo.css( "width" ); assert.notEqual( parseFloat( nw ), 1, "Stop didn't reset the animation " + nw ); $foo.stop( true ); assert.equal( $foo.queue().length, 0, "0 in the queue" ); } ); } )(); QUnit.test( "stop(clearQueue)", function( assert ) { assert.expect( 4 ); var $foo = jQuery( "#foo" ), w = 0, nw; $foo.hide().css( "width", 200 ).css( "width" ); $foo.animate( { "width": "show" }, 1000 ); $foo.animate( { "width": "hide" }, 1000 ); $foo.animate( { "width": "show" }, 1000 ); this.clock.tick( 100 ); nw = $foo.css( "width" ); assert.ok( parseFloat( nw ) !== w, "An animation occurred " + nw + " " + w + "px" ); $foo.stop( true ); nw = $foo.css( "width" ); assert.ok( parseFloat( nw ) !== w, "Stop didn't reset the animation " + nw + " " + w + "px" ); assert.equal( $foo.queue().length, 0, "The animation queue was cleared" ); this.clock.tick( 100 ); assert.equal( nw, $foo.css( "width" ), "The animation didn't continue" ); } ); QUnit.test( "stop(clearQueue, gotoEnd)", function( assert ) { assert.expect( 1 ); var $foo = jQuery( "#foo" ), w = 0, nw; $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 ); this.clock.tick( 100 ); nw = $foo.css( "width" ); assert.ok( parseFloat( nw ) !== w, "An animation occurred " + nw + " " + w + "px" ); $foo.stop( false, true ); 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 ); } ); QUnit.test( "stop( queue, ..., ... ) - Stop single queues", function( assert ) { assert.expect( 3 ); var saved, foo = jQuery( "#foo" ).css( { width: 200, height: 200 } ); foo.animate( { width: 400 }, { duration: 500, complete: function() { assert.equal( parseFloat( foo.css( "width" ) ), 400, "Animation completed for standard queue" ); assert.equal( parseFloat( foo.css( "height" ) ), saved, "Height was not changed after the second stop" ); } } ); foo.animate( { height: 400 }, { duration: 1000, queue: "height" } ).dequeue( "height" ).stop( "height", false, true ); assert.equal( parseFloat( foo.css( "height" ) ), 400, "Height was stopped with gotoEnd" ); foo.animate( { height: 200 }, { duration: 1000, queue: "height" } ).dequeue( "height" ).stop( "height", false, false ); saved = parseFloat( foo.css( "height" ) ); this.clock.tick( 500 ); } ); QUnit[ jQuery.find.compile ? "test" : "skip" ]( "toggle()", function( assert ) { assert.expect( 6 ); var x = jQuery( "#foo" ); assert.ok( x.is( ":visible" ), "is visible" ); x.toggle(); assert.ok( x.is( ":hidden" ), "is hidden" ); x.toggle(); assert.ok( x.is( ":visible" ), "is visible again" ); x.toggle( true ); assert.ok( x.is( ":visible" ), "is visible" ); x.toggle( false ); assert.ok( x.is( ":hidden" ), "is hidden" ); x.toggle( true ); assert.ok( x.is( ":visible" ), "is visible again" ); } ); QUnit.test( "jQuery.fx.prototype.cur() - <1.8 Back Compat", function( assert ) { assert.expect( 7 ); var div = jQuery( "
" ).appendTo( "#qunit-fixture" ).css( { color: "#ABC", border: "5px solid black", left: "auto", marginBottom: "-11000px" } )[ 0 ]; assert.equal( ( new jQuery.fx( div, {}, "color" ) ).cur(), jQuery.css( div, "color" ), "Return the same value as jQuery.css for complex properties (bug #7912)" ); assert.strictEqual( ( new jQuery.fx( div, {}, "borderLeftWidth" ) ).cur(), 5, "Return simple values parsed as Float" ); // backgroundPosition actually returns 0% 0% in most browser // this fakes a "" return // hook now gets called twice because Tween will grab the current // value as it is being newed jQuery.cssHooks.backgroundPosition = { get: function() { assert.ok( true, "hook used" ); return ""; } }; assert.strictEqual( ( new jQuery.fx( div, {}, "backgroundPosition" ) ).cur(), 0, "Return 0 when jQuery.css returns an empty string" ); delete jQuery.cssHooks.backgroundPosition; assert.strictEqual( ( new jQuery.fx( div, {}, "left" ) ).cur(), 0, "Return 0 when jQuery.css returns 'auto'" ); assert.equal( ( new jQuery.fx( div, {}, "marginBottom" ) ).cur(), -11000, "support negative values < -10000 (bug #7193)" ); jQuery( div ).remove(); } ); QUnit.test( "Overflow and Display", function( assert ) { assert.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" } ), done = function() { assert.equal( jQuery.css( this, "overflow" ), "visible", "Overflow should be 'visible'" ); assert.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 ); this.clock.tick( 600 ); } ); jQuery.each( { "CSS Auto": function( elem, prop ) { jQuery( elem ).addClass( "auto" + prop ) .text( "This is a long string of text." ); return ""; }, "JS Auto": function( elem, prop ) { jQuery( elem ).css( prop, "" ) .text( "This is a long string of text." ); return ""; }, "CSS 100": function( elem, prop ) { jQuery( elem ).addClass( "large" + prop ); return ""; }, "JS 100": function( elem, prop ) { jQuery( elem ).css( prop, prop === "opacity" ? 1 : "100px" ); return prop === "opacity" ? 1 : 100; }, "CSS 50": function( elem, prop ) { jQuery( elem ).addClass( "med" + prop ); return ""; }, "JS 50": function( elem, prop ) { jQuery( elem ).css( prop, prop === "opacity" ? 0.50 : "50px" ); return prop === "opacity" ? 0.5 : 50; }, "CSS 0": function( elem, prop ) { jQuery( elem ).addClass( "no" + prop ); return ""; }, "JS 0": function( elem, prop ) { jQuery( elem ).css( prop, prop === "opacity" ? 0 : "0px" ); return 0; } }, function( fn, f ) { jQuery.each( { "show": function( elem, prop ) { jQuery( elem ).hide().addClass( "wide" + prop ); return "show"; }, "hide": function( elem, prop ) { jQuery( elem ).addClass( "wide" + prop ); return "hide"; }, "100": function( elem, prop ) { jQuery( elem ).addClass( "wide" + prop ); return prop === "opacity" ? 1 : 100; }, "50": function( elem, prop ) { return prop === "opacity" ? 0.50 : 50; }, "0": function( elem ) { jQuery( elem ).addClass( "noback" ); return 0; } }, function( tn, t ) { QUnit.test( fn + " to " + tn, function( assert ) { var num, anim, elem = jQuery.makeTest( fn + " to " + tn ), t_w = t( elem, "width" ), f_w = f( elem, "width" ), t_h = t( elem, "height" ), f_h = f( elem, "height" ), t_o = t( elem, "opacity" ), f_o = f( elem, "opacity" ); if ( f_o === "" ) { f_o = 1; } num = 0; // TODO: uncrowd this if ( t_h === "show" ) { num++; } if ( t_w === "show" ) { num++; } if ( t_w === "hide" || t_w === "show" ) { num++; } if ( t_h === "hide" || t_h === "show" ) { num++; } if ( t_o === "hide" || t_o === "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; } assert.expect( num ); anim = { width: t_w, height: t_h, opacity: t_o }; elem.animate( anim, 50 ); jQuery.when( elem ).done( function( $elem ) { var cur_o, cur_w, cur_h, old_h, elem = $elem[ 0 ]; if ( t_w === "show" ) { assert.equal( $elem.css( "display" ), "block", "Showing, display should block: " + elem.style.display ); } if ( t_w === "hide" || t_w === "show" ) { assert.ok( f_w === "" ? elem.style.width === f_w : elem.style.width.indexOf( f_w ) === 0, "Width must be reset to " + f_w + ": " + elem.style.width ); } if ( t_h === "hide" || t_h === "show" ) { assert.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" ); if ( f_o !== jQuery.css( elem, "opacity" ) ) { f_o = f( elem, "opacity" ); } if ( t_o === "hide" || t_o === "show" ) { assert.equal( cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o ); } if ( t_w === "hide" ) { assert.equal( elem.style.display, "none", "Hiding, display should be none: " + elem.style.display ); } if ( t_o.constructor === Number ) { assert.equal( cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o ); assert.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 ) { assert.equal( elem.style.width, t_w + "px", "Final width should be " + t_w + ": " + elem.style.width ); cur_w = jQuery.css( elem, "width" ); assert.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 ) { assert.equal( elem.style.height, t_h + "px", "Final height should be " + t_h + ": " + elem.style.height ); cur_h = jQuery.css( elem, "height" ); assert.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( "
Some more text
and some more..." ); if ( /Auto/.test( fn ) ) { assert.notEqual( jQuery.css( elem, "height" ), old_h, "Make sure height is auto." ); } else { assert.equal( jQuery.css( elem, "height" ), old_h, "Make sure height is not auto." ); } } // manually remove generated element jQuery( elem ).remove(); } ); this.clock.tick( 100 ); } ); } ); } ); QUnit.test( "Effects chaining", function( assert ) { 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 ); }, check = function() { var data = jQuery.data( this ), name = data.name; delete data.name; assert.deepEqual( getProps( this ), data, name ); jQuery.removeData( this ); }, getProps = function( el ) { var obj = {}; jQuery.each( props, function( i, prop ) { obj[ prop ] = prop === "overflow" && el.style[ prop ] || jQuery.css( el, prop ); } ); return obj; }; assert.expect( remaining ); setup( ".fadeOut().fadeIn()", "#fadein div" ).fadeOut( "fast" ).fadeIn( "fast", check ); setup( ".fadeIn().fadeOut()", "#fadeout div" ).fadeIn( "fast" ).fadeOut( "fast", check ); setup( ".hide().show()", "#show div" ).hide( "fast" ).show( "fast", check ); setup( ".show().hide()", "#hide div" ).show( "fast" ).hide( "fast", check ); setup( ".show().hide(easing)", "#easehide div" ).show( "fast" ).hide( "fast", "linear", check ); setup( ".toggle().toggle() - in", "#togglein div" ).toggle( "fast" ).toggle( "fast", check ); setup( ".toggle().toggle() - out", "#toggleout div" ).toggle( "fast" ).toggle( "fast", check ); setup( ".toggle().toggle(easing) - out", "#easetoggleout div" ).toggle( "fast" ).toggle( "fast", "linear", check ); setup( ".slideDown().slideUp()", "#slidedown div" ).slideDown( "fast" ).slideUp( "fast", check ); setup( ".slideUp().slideDown()", "#slideup div" ).slideUp( "fast" ).slideDown( "fast", check ); setup( ".slideUp().slideDown(easing)", "#easeslideup div" ).slideUp( "fast" ).slideDown( "fast", "linear", check ); setup( ".slideToggle().slideToggle() - in", "#slidetogglein div" ).slideToggle( "fast" ).slideToggle( "fast", check ); setup( ".slideToggle().slideToggle() - out", "#slidetoggleout div" ).slideToggle( "fast" ).slideToggle( "fast", check ); setup( ".fadeToggle().fadeToggle() - in", "#fadetogglein div" ).fadeToggle( "fast" ).fadeToggle( "fast", check ); setup( ".fadeToggle().fadeToggle() - out", "#fadetoggleout div" ).fadeToggle( "fast" ).fadeToggle( "fast", check ); setup( ".fadeTo(0.5).fadeTo(1.0, easing)", "#fadeto div" ).fadeTo( "fast", 0.5 ).fadeTo( "fast", 1.0, "linear", check ); this.clock.tick( 400 ); } ); jQuery.makeTest = function( text ) { var elem = jQuery( "
" ) .attr( "id", "test" + jQuery.makeTest.id++ ) .addClass( "box" ); jQuery( "

" ) .text( text ) .appendTo( "#fx-tests" ) .after( elem ); return elem; }; jQuery.makeTest.id = 1; QUnit.test( "jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function( assert ) { assert.expect( 4 ); var $checkedtest = jQuery( "#checkedtest" ); $checkedtest.hide().show( "fast", function() { assert.ok( jQuery( "input[type='radio']", $checkedtest ).first().attr( "checked" ), "Check first radio still checked." ); assert.ok( !jQuery( "input[type='radio']", $checkedtest ).last().attr( "checked" ), "Check last radio still NOT checked." ); assert.ok( jQuery( "input[type='checkbox']", $checkedtest ).first().attr( "checked" ), "Check first checkbox still checked." ); assert.ok( !jQuery( "input[type='checkbox']", $checkedtest ).last().attr( "checked" ), "Check last checkbox still NOT checked." ); } ); this.clock.tick( 200 ); } ); QUnit.test( "interrupt toggle", function( assert ) { assert.expect( 24 ); var env = this, longDuration = 2000, shortDuration = 500, remaining = 0, $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() { // Don't end test until we're done with this element remaining++; // Save original property value for comparison jQuery.data( this, "startVal", jQuery( this ).css( prop ) ); // Expect olddisplay data from our .hide() call below assert.expectJqData( env, this, "olddisplay" ); } ); // Interrupt a hiding toggle $methodElems[ method ]( longDuration ); setTimeout( function() { $methodElems.stop().each( function() { assert.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" ); $elem.removeData( "startVal" ); assert.equal( $elem.css( prop ), startVal, "original value restored by ." + method + "() - #" + id ); // Interrupt a showing toggle $elem.hide()[ method ]( longDuration ); setTimeout( function() { $elem.stop(); assert.notEqual( $elem.css( prop ), startVal, ".stop() before completion of showing ." + method + "() - #" + id ); // Restore $elem[ method ]( shortDuration, function() { assert.equal( $elem.css( prop ), startVal, "original value restored by ." + method + "() - #" + id ); finish(); } ); }, shortDuration ); } ); }, shortDuration ); } ); clock.tick( longDuration ); // FIXME untangle the set timeouts } ); QUnit.test( "animate with per-property easing", function( assert ) { assert.expect( 5 ); var data = { a: 0, b: 0, c: 0 }, test1Called = false, test2Called = false, defaultTestCalled = false, props = { a: [ 100, "_test1" ], b: [ 100, "_test2" ], c: 100 }; jQuery.easing._test1 = function( p ) { test1Called = true; return p; }; jQuery.easing._test2 = function( p ) { test2Called = true; return p; }; jQuery.easing._defaultTest = function( p ) { defaultTestCalled = true; return p; }; jQuery( data ).animate( props, 400, "_defaultTest", function() { assert.ok( test1Called, "Easing function (_test1) called" ); assert.ok( test2Called, "Easing function (_test2) called" ); assert.ok( defaultTestCalled, "Easing function (_default) called" ); assert.equal( props.a[ 1 ], "_test1", "animate does not change original props (per-property easing would be lost)" ); assert.equal( props.b[ 1 ], "_test2", "animate does not change original props (per-property easing would be lost)" ); } ); this.clock.tick( 400 ); } ); QUnit.test( "animate with CSS shorthand properties", function( assert ) { assert.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 ) { if ( p >= 1 ) { easeAnimation_count++; } return p; }; jQuery.easing.propertyScope = function( p ) { if ( p >= 1 ) { easeProperty_count++; } return p; }; jQuery( "#foo" ) .animate( propsBasic, 200, "animationScope", function() { assert.equal( this.style.paddingTop, "10px", "padding-top was animated" ); assert.equal( this.style.paddingLeft, "20px", "padding-left was animated" ); assert.equal( this.style.paddingRight, "20px", "padding-right was animated" ); assert.equal( this.style.paddingBottom, "30px", "padding-bottom was animated" ); assert.equal( easeAnimation_count, 4, "per-animation default easing called for each property" ); easeAnimation_count = 0; } ) .animate( propsSpecial, 200, "animationScope", function() { assert.equal( this.style.paddingTop, "1px", "padding-top was animated again" ); assert.equal( this.style.paddingLeft, "2px", "padding-left was animated again" ); assert.equal( this.style.paddingRight, "2px", "padding-right was animated again" ); assert.equal( this.style.paddingBottom, "3px", "padding-bottom was animated again" ); assert.equal( easeAnimation_count, 0, "per-animation default easing not called" ); assert.equal( easeProperty_count, 4, "special easing called for each property" ); jQuery( this ).css( "padding", "0" ); delete jQuery.easing.animationScope; delete jQuery.easing.propertyScope; } ); this.clock.tick( 400 ); } ); QUnit.test( "hide hidden elements, with animation (bug #7141)", function( assert ) { assert.expect( 4 ); var div = jQuery( "