3 // Can't test what ain't there
8 var off = jQuery.fx.off;
11 teardown: function() {
13 return moduleTeardown.apply( this, arguments );
17 test("sanity check", function() {
19 ok( jQuery("#dl:visible, #qunit-fixture:visible, #foo:visible").length === 3, "QUnit state is correct for testing effects" );
22 test("show() basic", 2, function() {
24 hiddendiv = jQuery("div.hidden");
26 hiddendiv.hide().show();
28 equal( hiddendiv.css("display"), "block", "Make sure a pre-hidden div is visible." );
30 div = jQuery("<div>").hide().appendTo("#qunit-fixture").show();
32 equal( div.css("display"), "block", "Make sure pre-hidden divs show" );
34 // Clean up the detached node
37 QUnit.expectJqData(hiddendiv, "olddisplay");
40 test("show()", 27, function () {
41 var div, speeds, old, test,
42 displaysActual, displaysExpected,
43 hiddendiv = jQuery("div.hidden");
45 equal(jQuery.css( hiddendiv[0], "display"), "none", "hiddendiv is display: none");
47 hiddendiv.css("display", "block");
48 equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block");
51 equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block");
53 hiddendiv.css("display","");
56 displaysExpected = [];
58 div = jQuery("#fx-queue div").slice(0, 4);
59 div.show().each(function() {
60 notEqual(this.style.display, "none", "don't change any <div> with display block");
65 "undefined speed": undefined,
69 jQuery.each(speeds, function(name, speed) {
71 div.hide().show(speed).each(function() {
72 if ( this.style.display === "none" ) {
76 ok( pass, "Show with " + name);
79 jQuery.each(speeds, function(name, speed) {
81 div.hide().show(speed, function() {
84 ok( pass, "Show with " + name + " does not call animate callback" );
87 // Tolerate data from show()/hide()
88 QUnit.expectJqData(div, "olddisplay");
90 // #show-tests * is set display: none in CSS
91 jQuery("#qunit-fixture").append("<div id='show-tests'><div><p><a href='#'></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div><table id='test-table'></table>");
93 old = jQuery("#test-table").show().css("display") !== "table";
94 jQuery("#test-table").remove();
103 "table" : old ? "block" : "table",
104 "thead" : old ? "block" : "table-header-group",
105 "tbody" : old ? "block" : "table-row-group",
106 "tr" : old ? "block" : "table-row",
107 "th" : old ? "block" : "table-cell",
108 "td" : old ? "block" : "table-cell",
110 "li" : old ? "block" : "list-item"
113 jQuery.each(test, function(selector, expected) {
114 var elem = jQuery(selector, "#show-tests").show();
115 equal( elem.css("display"), expected, "Show using correct display type for " + selector );
118 jQuery("#show-tests").remove();
120 // Make sure that showing or hiding a text node doesn't cause an error
121 jQuery("<div>test</div> text <span>test</span>").show().remove();
122 jQuery("<div>test</div> text <span>test</span>").hide().remove();
125 test("show(Number) - other displays", function() {
130 // #show-tests * is set display: none in CSS
131 jQuery("#qunit-fixture").append("<div id='show-tests'><div><p><a href='#'></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div><table id='test-table'></table>");
134 old = jQuery("#test-table").show().css("display") !== "table",
136 jQuery("#test-table").remove();
138 // Note: inline elements are expected to be inline-block
139 // because we're showing width/height
140 // Can't animate width/height inline
145 "a" : "inline-block",
146 "code" : "inline-block",
148 "span" : "inline-block",
149 "table" : old ? "block" : "table",
150 "thead" : old ? "block" : "table-header-group",
151 "tbody" : old ? "block" : "table-row-group",
152 "tr" : old ? "block" : "table-row",
153 "th" : old ? "block" : "table-cell",
154 "td" : old ? "block" : "table-cell",
156 "li" : old ? "block" : "list-item"
159 jQuery.each(test, function(selector, expected) {
160 var elem = jQuery(selector, "#show-tests").show(1, function() {
161 equal( elem.css("display"), expected, "Show using correct display type for " + selector );
162 if ( ++num === 15 ) {
168 jQuery("#show-tests").remove();
172 test("Persist correct display value", function() {
177 // #show-tests * is set display: none in CSS
178 jQuery("#qunit-fixture").append("<div id='show-tests'><span style='position:absolute;'>foo</span></div>");
180 var $span = jQuery("#show-tests span"),
181 displayNone = $span.css("display"),
186 display = $span.css("display");
190 $span.fadeIn(100, function() {
191 equal($span.css("display"), display, "Expecting display: " + display);
192 $span.fadeOut(100, function () {
193 equal($span.css("display"), displayNone, "Expecting display: " + displayNone);
194 $span.fadeIn(100, function() {
195 equal($span.css("display"), display, "Expecting display: " + display);
201 QUnit.expectJqData($span, "olddisplay");
204 test("animate(Hash, Object, Function)", function() {
207 var hash = {opacity: "show"},
208 hashCopy = jQuery.extend({}, hash);
209 jQuery("#foo").animate(hash, 0, function() {
210 equal( hash.opacity, hashCopy.opacity, "Check if animate changed the hash parameter" );
215 test("animate relative values", function() {
219 bases = [ "%", "px", "em" ],
220 adjustments = [ "px", "em" ],
221 container = jQuery("<div></div>")
222 .css({ position: "absolute", height: "50em", width: "50em" }),
223 animations = bases.length * adjustments.length;
225 expect( 2 * animations );
227 jQuery.each( bases, function( _, baseUnit ) {
228 jQuery.each( adjustments, function( _, adjustUnit ) {
229 var base = value + baseUnit,
230 adjust = { height: "+=2" + adjustUnit, width: "-=2" + adjustUnit },
231 elem = jQuery("<div></div>")
232 .appendTo( container.clone().appendTo("#qunit-fixture") )
234 position: "absolute",
236 width: value + adjustUnit
238 baseScale = elem[ 0 ].offsetHeight / value,
239 adjustScale = elem[ 0 ].offsetWidth / value;
241 elem.css( "width", base ).animate( adjust, 100, function() {
242 equal( this.offsetHeight, value * baseScale + 2 * adjustScale,
243 baseUnit + "+=" + adjustUnit );
244 equal( this.offsetWidth, value * baseScale - 2 * adjustScale,
245 baseUnit + "-=" + adjustUnit );
247 if ( --animations === 0 ) {
255 test("animate negative height", function() {
258 jQuery("#foo").animate({ height: -100 }, 100, function() {
259 equal( this.offsetHeight, 0, "Verify height." );
264 test("animate negative margin", function() {
267 jQuery("#foo").animate({ "marginTop": -100 }, 100, function() {
268 equal( jQuery(this).css("marginTop"), "-100px", "Verify margin." );
273 test("animate negative margin with px", function() {
276 jQuery("#foo").animate({ marginTop: "-100px" }, 100, function() {
277 equal( jQuery(this).css("marginTop"), "-100px", "Verify margin." );
282 test("animate negative padding", function() {
285 jQuery("#foo").animate({ "paddingBottom": -100 }, 100, function() {
286 equal( jQuery(this).css("paddingBottom"), "0px", "Verify paddingBottom." );
291 test("animate block as inline width/height", function() {
294 var span = jQuery("<span>").css("display", "inline-block").appendTo("body"),
295 expected = span.css("display");
299 if ( jQuery.support.inlineBlockNeedsLayout || expected === "inline-block" ) {
302 jQuery("#foo").css({ display: "inline", width: "", height: "" }).animate({ width: 42, height: 42 }, 100, function() {
303 equal( jQuery(this).css("display"), jQuery.support.inlineBlockNeedsLayout ? "inline" : "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
304 equal( this.offsetWidth, 42, "width was animated" );
305 equal( this.offsetHeight, 42, "height was animated" );
309 // Browser doesn't support inline-block
311 ok( true, "Browser doesn't support inline-block" );
312 ok( true, "Browser doesn't support inline-block" );
313 ok( true, "Browser doesn't support inline-block" );
317 test("animate native inline width/height", function() {
320 var span = jQuery("<span>").css("display", "inline-block").appendTo("body"),
321 expected = span.css("display");
325 if ( jQuery.support.inlineBlockNeedsLayout || expected === "inline-block" ) {
327 jQuery("#foo").css({ display: "", width: "", height: "" })
328 .append("<span>text</span>")
330 .animate({ width: 42, height: 42 }, 100, function() {
331 equal( jQuery(this).css("display"), "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
332 equal( this.offsetWidth, 42, "width was animated" );
333 equal( this.offsetHeight, 42, "height was animated" );
337 // Browser doesn't support inline-block
339 ok( true, "Browser doesn't support inline-block" );
340 ok( true, "Browser doesn't support inline-block" );
341 ok( true, "Browser doesn't support inline-block" );
345 test( "animate block width/height", function() {
349 jQuery("<div>").appendTo("#qunit-fixture").css({
360 if ( jQuery( this ).width() > 42 ) {
361 ok( false, "width was incorrectly augmented during animation" );
364 complete: function() {
365 equal( jQuery( this ).css("display"), "block", "inline-block was not set on block element when animating width/height" );
366 equal( jQuery( this ).width(), 42, "width was animated" );
367 equal( jQuery( this ).height(), 42, "height was animated" );
373 test("animate table width/height", function() {
377 var displayMode = jQuery("#table").css("display") !== "table" ? "block" : "table";
379 jQuery("#table").animate({ width: 42, height: 42 }, 100, function() {
380 equal( jQuery(this).css("display"), displayMode, "display mode is correct" );
385 test("animate table-row width/height", function() {
389 tr = jQuery("#table")
390 .attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 })
391 .html("<tr style='height:42px;'><td style='padding:0;'><div style='width:20px;height:20px;'></div></td></tr>")
394 // IE<8 uses "block" instead of the correct display type
395 displayMode = tr.css("display") !== "table-row" ? "block" : "table-row";
397 tr.animate({ width: 10, height: 10 }, 100, function() {
398 equal( jQuery(this).css("display"), displayMode, "display mode is correct" );
399 equal( this.offsetWidth, 20, "width animated to shrink wrap point" );
400 equal( this.offsetHeight, 20, "height animated to shrink wrap point" );
405 test("animate table-cell width/height", function() {
409 td = jQuery("#table")
410 .attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 })
411 .html("<tr><td style='width:42px;height:42px;padding:0;'><div style='width:20px;height:20px;'></div></td></tr>")
414 // IE<8 uses "block" instead of the correct display type
415 displayMode = td.css("display") !== "table-cell" ? "block" : "table-cell";
417 td.animate({ width: 10, height: 10 }, 100, function() {
418 equal( jQuery(this).css("display"), displayMode, "display mode is correct" );
419 equal( this.offsetWidth, 20, "width animated to shrink wrap point" );
420 equal( this.offsetHeight, 20, "height animated to shrink wrap point" );
425 test("animate percentage(%) on width/height", function() {
428 var $div = jQuery("<div style='position:absolute;top:-999px;left:-999px;width:60px;height:60px;'><div style='width:50%;height:50%;'></div></div>")
429 .appendTo("#qunit-fixture").children("div");
432 $div.animate({ width: "25%", height: "25%" }, 13, function() {
433 var $this = jQuery(this);
434 equal( $this.css("width"), "15px", "Width was animated to 15px rather than 25px");
435 equal( $this.css("height"), "15px", "Height was animated to 15px rather than 25px");
440 test("animate resets overflow-x and overflow-y when finished", function() {
444 .css({ display: "block", width: 20, height: 20, overflowX: "visible", overflowY: "auto" })
445 .animate({ width: 42, height: 42 }, 100, function() {
446 equal( this.style.overflowX, "visible", "overflow-x is visible" );
447 equal( this.style.overflowY, "auto", "overflow-y is auto" );
452 /* // This test ends up being flaky depending upon the CPU load
453 test("animate option (queue === false)", function () {
459 var $foo = jQuery("#foo");
460 $foo.animate({width:"100px"}, 3000, function () {
461 // should finish after unqueued animation so second
463 deepEqual( order, [ 1, 2 ], "Animations finished in the correct order" );
466 $foo.animate({fontSize:"2em"}, {queue:false, duration:10, complete:function () {
467 // short duration and out of queue so should finish first
473 asyncTest( "animate option { queue: false }", function() {
475 var foo = jQuery( "#foo" );
482 complete: function() {
483 ok( true, "Animation Completed" );
488 equal( foo.queue().length, 0, "Queue is empty" );
491 asyncTest( "animate option { queue: true }", function() {
493 var foo = jQuery( "#foo" );
500 complete: function() {
501 ok( true, "Animation Completed" );
506 notEqual( foo.queue().length, 0, "Default queue is not empty" );
509 asyncTest( "animate option { queue: 'name' }", function() {
511 var foo = jQuery( "#foo" ),
512 origWidth = parseFloat( foo.css("width") ),
515 foo.animate( { width: origWidth + 100 }, {
518 complete: function() {
520 // second callback function
522 equal( parseFloat( foo.css("width") ), origWidth + 100, "Animation ended" );
523 equal( foo.queue("name").length, 1, "Queue length of 'name' queue" );
525 }).queue( "name", function() {
527 // last callback function
528 deepEqual( order, [ 1, 2 ], "Callbacks in expected order" );
532 setTimeout( function() {
534 // this is the first callback function that should be called
536 equal( parseFloat( foo.css("width") ), origWidth, "Animation does not start on its own." );
537 equal( foo.queue("name").length, 2, "Queue length of 'name' queue" );
538 foo.dequeue( "name" );
543 test("animate with no properties", function() {
547 divs = jQuery("div"),
550 divs.animate({}, function(){
554 equal( divs.length, count, "Make sure that callback is called for each element in the set." );
558 foo = jQuery("#foo");
561 foo.animate({top: 10}, 100, function(){
562 ok( true, "Animation was properly dequeued." );
567 test("animate duration 0", function() {
573 $elems = jQuery([{ a:0 },{ a:0 }]),
576 equal( jQuery.timers.length, 0, "Make sure no animation was running from another test" );
578 $elems.eq(0).animate( {a:1}, 0, function(){
579 ok( true, "Animate a simple property." );
583 // Failed until [6115]
584 equal( jQuery.timers.length, 0, "Make sure synchronic animations are not left on jQuery.timers" );
586 equal( counter, 1, "One synchronic animations" );
588 $elems.animate( { a:2 }, 0, function(){
589 ok( true, "Animate a second simple property." );
593 equal( counter, 3, "Multiple synchronic animations" );
595 $elems.eq(0).animate( {a:3}, 0, function(){
596 ok( true, "Animate a third simple property." );
599 $elems.eq(1).animate( {a:3}, 200, function(){
601 // Failed until [6115]
602 equal( counter, 5, "One synchronic and one asynchronic" );
606 $elem = jQuery("<div />");
607 $elem.show(0, function(){
608 ok(true, "Show callback with no duration");
610 $elem.hide(0, function(){
611 ok(true, "Hide callback with no duration");
614 // manually clean up detached elements
618 test("animate hyphenated properties", function() {
623 .css("font-size", 10)
624 .animate({"font-size": 20}, 200, function() {
625 equal( this.style.fontSize, "20px", "The font-size property was animated." );
630 test("animate non-element", function() {
634 var obj = { test: 0 };
636 jQuery(obj).animate({test: 200}, 200, function(){
637 equal( obj.test, 200, "The custom property should be modified." );
642 test("stop()", function() {
647 $foo = jQuery("#foo"),
651 $foo.hide().css( "width", 200 )
652 .animate( { "width": "show" }, 1500 );
654 setTimeout(function() {
655 var nw = $foo.css("width");
656 notEqual( parseFloat( nw ), w, "An animation occurred " + nw + " " + w + "px" );
659 nw = $foo.css("width");
660 notEqual( parseFloat( nw ), w, "Stop didn't reset the animation " + nw + " " + w + "px" );
661 setTimeout(function() {
663 $foo.removeData(undefined, true);
664 equal( nw, $foo.css("width"), "The animation didn't continue" );
665 if ( --tests === 0 ) {
671 $one = jQuery("#fadein");
672 $two = jQuery("#show");
673 $one.fadeTo(100, 0, function() {
676 setTimeout(function() {
677 $two.fadeTo(100, 0, function() {
678 equal( $two.css("opacity"), "0", "Stop does not interfere with animations on other elements (#6641)" );
680 $one.add( $two ).css("opacity", "");
681 if ( --tests === 0 ) {
688 test("stop() - several in queue", function() {
692 $foo = jQuery( "#foo" );
694 // default duration is 400ms, so 800px ensures we aren't 0 or 1 after 1ms
695 $foo.hide().css( "width", 800 );
697 $foo.animate({ "width": "show" }, 400, "linear");
698 $foo.animate({ "width": "hide" });
699 $foo.animate({ "width": "show" });
701 // could be replaced by something nicer using sinon.
703 while( time === jQuery.now() ) {}
706 equal( $foo.queue().length, 3, "3 in the queue" );
708 nw = $foo.css( "width" );
709 notEqual( parseFloat( nw ), 1, "An animation occurred " + nw );
712 equal( $foo.queue().length, 2, "2 in the queue" );
713 nw = $foo.css( "width" );
714 notEqual( parseFloat( nw ), 1, "Stop didn't reset the animation " + nw );
718 equal( $foo.queue().length, 0, "0 in the queue" );
721 test("stop(clearQueue)", function() {
725 var $foo = jQuery("#foo"),
727 $foo.hide().css( "width", 200 ).css("width");
729 $foo.animate({ "width": "show" }, 1000);
730 $foo.animate({ "width": "hide" }, 1000);
731 $foo.animate({ "width": "show" }, 1000);
732 setTimeout(function(){
733 var nw = $foo.css("width");
734 ok( parseFloat( nw ) !== w, "An animation occurred " + nw + " " + w + "px");
737 nw = $foo.css("width");
738 ok( parseFloat( nw ) !== w, "Stop didn't reset the animation " + nw + " " + w + "px");
740 equal( $foo.queue().length, 0, "The animation queue was cleared" );
741 setTimeout(function(){
742 equal( nw, $foo.css("width"), "The animation didn't continue" );
748 test("stop(clearQueue, gotoEnd)", function() {
752 var $foo = jQuery("#foo"),
754 $foo.hide().css( "width", 200 ).css("width");
756 $foo.animate({ width: "show" }, 1000);
757 $foo.animate({ width: "hide" }, 1000);
758 $foo.animate({ width: "show" }, 1000);
759 $foo.animate({ width: "hide" }, 1000);
760 setTimeout(function(){
761 var nw = $foo.css("width");
762 ok( parseFloat( nw ) !== w, "An animation occurred " + nw + " " + w + "px");
763 $foo.stop(false, true);
765 nw = $foo.css("width");
766 // Disabled, being flaky
767 //equal( nw, 1, "Stop() reset the animation" );
769 setTimeout(function(){
770 // Disabled, being flaky
771 //equal( $foo.queue().length, 2, "The next animation continued" );
778 asyncTest( "stop( queue, ..., ... ) - Stop single queues", function() {
781 foo = jQuery("#foo").css({ width: 200, height: 200 });
787 complete: function() {
788 equal( parseFloat( foo.css("width") ), 400, "Animation completed for standard queue" );
789 equal( parseFloat( foo.css("height") ), saved, "Height was not changed after the second stop");
799 }).dequeue("height").stop( "height", false, true );
801 equal( parseFloat( foo.css("height") ), 400, "Height was stopped with gotoEnd" );
808 }).dequeue( "height" ).stop( "height", false, false );
809 saved = parseFloat( foo.css("height") );
812 test("toggle()", function() {
814 var x = jQuery("#foo");
815 ok( x.is(":visible"), "is visible" );
817 ok( x.is(":hidden"), "is hidden" );
819 ok( x.is(":visible"), "is visible again" );
822 ok( x.is(":visible"), "is visible" );
824 ok( x.is(":hidden"), "is hidden" );
826 ok( x.is(":visible"), "is visible again" );
829 test( "jQuery.fx.prototype.cur() - <1.8 Back Compat", 7, function() {
830 var div = jQuery( "<div></div>" ).appendTo( "#qunit-fixture" ).css({
832 border: "5px solid black",
834 marginBottom: "-11000px"
838 ( new jQuery.fx( div, {}, "color" ) ).cur(),
839 jQuery.css( div, "color" ),
840 "Return the same value as jQuery.css for complex properties (bug #7912)"
844 ( new jQuery.fx( div, {}, "borderLeftWidth" ) ).cur(),
846 "Return simple values parsed as Float"
849 // backgroundPosition actually returns 0% 0% in most browser
850 // this fakes a "" return
851 // hook now gets called twice because Tween will grab the current
852 // value as it is being newed
853 jQuery.cssHooks.backgroundPosition = {
855 ok( true, "hook used" );
861 ( new jQuery.fx( div, {}, "backgroundPosition" ) ).cur(),
863 "Return 0 when jQuery.css returns an empty string"
866 delete jQuery.cssHooks.backgroundPosition;
869 ( new jQuery.fx( div, {}, "left" ) ).cur(),
871 "Return 0 when jQuery.css returns 'auto'"
875 ( new jQuery.fx( div, {}, "marginBottom" ) ).cur(),
877 "support negative values < -10000 (bug #7193)"
880 jQuery( div ).remove();
883 test("Overflow and Display", function() {
888 testClass = jQuery.makeTest("Overflow and Display")
889 .addClass("overflow inline"),
890 testStyle = jQuery.makeTest("Overflow and Display (inline style)")
891 .css({ overflow: "visible", display: "inline" }),
894 equal( jQuery.css( this, "overflow" ), "visible", "Overflow should be 'visible'" );
895 equal( jQuery.css( this, "display" ), "inline", "Display should be 'inline'" );
897 if ( --remaining === 0 ) {
902 testClass.add( testStyle )
903 .addClass("widewidth")
904 .text("Some sample text.")
905 .before("text before")
907 .animate({ opacity: 0.5 }, "slow", done );
911 "CSS Auto": function( elem, prop ) {
912 jQuery( elem ).addClass( "auto" + prop )
913 .text( "This is a long string of text." );
916 "JS Auto": function( elem, prop ) {
917 jQuery( elem ).css( prop, "" )
918 .text( "This is a long string of text." );
921 "CSS 100": function( elem, prop ) {
922 jQuery( elem ).addClass( "large" + prop );
925 "JS 100": function( elem, prop ) {
926 jQuery( elem ).css( prop, prop === "opacity" ? 1 : "100px" );
927 return prop === "opacity" ? 1 : 100;
929 "CSS 50": function( elem, prop ) {
930 jQuery( elem ).addClass( "med" + prop );
933 "JS 50": function( elem, prop ) {
934 jQuery( elem ).css( prop, prop === "opacity" ? 0.50 : "50px" );
935 return prop === "opacity" ? 0.5 : 50;
937 "CSS 0": function( elem, prop ) {
938 jQuery( elem ).addClass( "no" + prop );
941 "JS 0": function( elem, prop ) {
942 jQuery( elem ).css( prop, prop === "opacity" ? 0 : "0px" );
945 }, function( fn, f ) {
947 "show": function( elem, prop ) {
948 jQuery( elem ).hide( ).addClass( "wide" + prop );
951 "hide": function( elem, prop ) {
952 jQuery( elem ).addClass( "wide" + prop );
955 "100": function( elem, prop ) {
956 jQuery( elem ).addClass( "wide" + prop );
957 return prop === "opacity" ? 1 : 100;
959 "50": function( elem, prop ) {
960 return prop === "opacity" ? 0.50 : 50;
962 "0": function( elem ) {
963 jQuery( elem ).addClass( "noback" );
966 }, function( tn, t ) {
967 test(fn + " to " + tn, function() {
969 elem = jQuery.makeTest( fn + " to " + tn ),
970 t_w = t( elem, "width" ),
971 f_w = f( elem, "width" ),
972 t_h = t( elem, "height" ),
973 f_h = f( elem, "height" ),
974 t_o = t( elem, "opacity" ),
975 f_o = f( elem, "opacity" );
982 // TODO: uncrowd this
983 if ( t_h === "show" ) {num++;}
984 if ( t_w === "show" ) {num++;}
985 if ( t_w === "hide" || t_w === "show" ) {num++;}
986 if ( t_h === "hide" || t_h === "show" ) {num++;}
987 if ( t_o === "hide" || t_o === "show" ) {num++;}
988 if ( t_w === "hide" ) {num++;}
989 if ( t_o.constructor === Number ) {num += 2;}
990 if ( t_w.constructor === Number ) {num += 2;}
991 if ( t_h.constructor === Number ) {num +=2;}
996 anim = { width: t_w, height: t_h, opacity: t_o };
998 elem.animate(anim, 50);
1000 jQuery.when( elem ).done(function( elem ) {
1001 var cur_o, cur_w, cur_h, old_h;
1005 if ( t_w === "show" ) {
1006 equal( elem.style.display, "block", "Showing, display should block: " + elem.style.display );
1009 if ( t_w === "hide" || t_w === "show" ) {
1010 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 );
1013 if ( t_h === "hide" || t_h === "show" ) {
1014 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 );
1017 cur_o = jQuery.style(elem, "opacity");
1019 if ( f_o !== jQuery.css(elem, "opacity") ) {
1020 f_o = f( elem, "opacity" );
1023 // The only time an _empty_string_ will be matched is in IE
1024 // otherwise, the correct values will be tested as usual
1029 if ( cur_o === "" ) {
1033 if ( t_o === "hide" || t_o === "show" ) {
1034 equal( cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o );
1037 if ( t_w === "hide" ) {
1038 equal( elem.style.display, "none", "Hiding, display should be none: " + elem.style.display );
1041 if ( t_o.constructor === Number ) {
1042 equal( cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o );
1044 ok( jQuery.css(elem, "opacity") !== "" || cur_o === t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o );
1047 if ( t_w.constructor === Number ) {
1048 equal( elem.style.width, t_w + "px", "Final width should be " + t_w + ": " + elem.style.width );
1050 cur_w = jQuery.css( elem,"width" );
1052 ok( elem.style.width !== "" || cur_w === t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w );
1055 if ( t_h.constructor === Number ) {
1056 equal( elem.style.height, t_h + "px", "Final height should be " + t_h + ": " + elem.style.height );
1058 cur_h = jQuery.css( elem,"height" );
1060 ok( elem.style.height !== "" || cur_h === t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_h );
1063 if ( t_h === "show" ) {
1064 old_h = jQuery.css( elem, "height" );
1065 jQuery( elem ).append("<br/>Some more text<br/>and some more...");
1067 if ( /Auto/.test( fn ) ) {
1068 notEqual( jQuery.css( elem, "height" ), old_h, "Make sure height is auto." );
1070 equal( jQuery.css( elem, "height" ), old_h, "Make sure height is not auto." );
1074 // manually remove generated element
1075 jQuery( elem ).remove();
1083 asyncTest("Effects chaining", function() {
1085 shrinkwrap = jQuery.support.shrinkWrapBlocks(),
1086 props = [ "opacity", "height", "width", "display", "overflow" ],
1087 setup = function( name, selector, hiddenOverflow ) {
1088 var $el = jQuery( selector );
1089 return $el.data( getProps( $el[0], hiddenOverflow ) ).data( "name", name );
1091 assert = function() {
1092 var data = jQuery.data( this ),
1096 deepEqual( getProps( this ), data, name );
1098 jQuery.removeData( this );
1099 if ( --remaining === 0 ) {
1103 getProps = function( el, hiddenOverflow ) {
1105 jQuery.each( props, function( i, prop ) {
1106 obj[ prop ] = prop === "overflow" && hiddenOverflow ? "hidden" : el.style[ prop ] || jQuery.css( el, prop );
1111 expect( remaining );
1113 // We need to pass jQuery.support.shrinkWrapBlocks for all methods that
1114 // set overflow hidden (slide* and show/hide with speed)
1115 setup( ".fadeOut().fadeIn()", "#fadein div" ).fadeOut("fast").fadeIn( "fast", assert );
1116 setup( ".fadeIn().fadeOut()", "#fadeout div" ).fadeIn("fast").fadeOut( "fast", assert );
1117 setup( ".hide().show()", "#show div", shrinkwrap ).hide("fast").show( "fast", assert );
1118 setup( ".show().hide()", "#hide div", shrinkwrap ).show("fast").hide( "fast", assert );
1119 setup( ".show().hide(easing)", "#easehide div", shrinkwrap ).show("fast").hide( "fast", "linear", assert );
1120 setup( ".toggle().toggle() - in", "#togglein div", shrinkwrap ).toggle("fast").toggle( "fast", assert );
1121 setup( ".toggle().toggle() - out", "#toggleout div", shrinkwrap ).toggle("fast").toggle( "fast", assert );
1122 setup( ".toggle().toggle(easing) - out", "#easetoggleout div", shrinkwrap ).toggle("fast").toggle( "fast", "linear", assert );
1123 setup( ".slideDown().slideUp()", "#slidedown div", shrinkwrap ).slideDown("fast").slideUp( "fast", assert );
1124 setup( ".slideUp().slideDown()", "#slideup div", shrinkwrap ).slideUp("fast").slideDown( "fast", assert );
1125 setup( ".slideUp().slideDown(easing)", "#easeslideup div", shrinkwrap ).slideUp("fast").slideDown( "fast", "linear", assert );
1126 setup( ".slideToggle().slideToggle() - in", "#slidetogglein div", shrinkwrap ).slideToggle("fast").slideToggle( "fast", assert );
1127 setup( ".slideToggle().slideToggle() - out", "#slidetoggleout div", shrinkwrap ).slideToggle("fast").slideToggle( "fast", assert );
1128 setup( ".fadeToggle().fadeToggle() - in", "#fadetogglein div" ).fadeToggle("fast").fadeToggle( "fast", assert );
1129 setup( ".fadeToggle().fadeToggle() - out", "#fadetoggleout div" ).fadeToggle("fast").fadeToggle( "fast", assert );
1130 setup( ".fadeTo(0.5).fadeTo(1.0, easing)", "#fadeto div" ).fadeTo( "fast", 0.5 ).fadeTo( "fast", 1.0, "linear", assert );
1133 jQuery.makeTest = function( text ){
1134 var elem = jQuery("<div></div>")
1135 .attr( "id", "test" + jQuery.makeTest.id++ )
1140 .appendTo("#fx-tests")
1146 jQuery.makeTest.id = 1;
1148 test("jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function () {
1152 var $checkedtest = jQuery("#checkedtest");
1153 $checkedtest.hide().show("fast", function() {
1154 ok( jQuery("input[type='radio']", $checkedtest).first().attr("checked"), "Check first radio still checked." );
1155 ok( !jQuery("input[type='radio']", $checkedtest).last().attr("checked"), "Check last radio still NOT checked." );
1156 ok( jQuery("input[type='checkbox']", $checkedtest).first().attr("checked"), "Check first checkbox still checked." );
1157 ok( !jQuery("input[type='checkbox']", $checkedtest).last().attr("checked"), "Check last checkbox still NOT checked." );
1162 test( "interrupt toggle", function() {
1166 var longDuration = 2000,
1167 shortDuration = 500,
1169 $elems = jQuery(".chain-test"),
1170 finish = function() {
1171 if ( !(--remaining) ) {
1176 jQuery.each( { slideToggle: "height", fadeToggle: "opacity", toggle: "width" }, function( method, prop ) {
1177 var $methodElems = $elems.filter( "[id^='" + method.toLowerCase() + "']" ).each(function() {
1178 // Don't end test until we're done with this element
1181 // Save original property value for comparison
1182 jQuery.data( this, "startVal", jQuery( this ).css( prop ) );
1184 // Expect olddisplay data from our .hide() call below
1185 QUnit.expectJqData( this, "olddisplay" );
1188 // Interrupt a hiding toggle
1189 $methodElems[ method ]( longDuration );
1190 setTimeout(function() {
1191 $methodElems.stop().each(function() {
1192 notEqual( jQuery( this ).css( prop ), jQuery.data( this, "startVal" ), ".stop() before completion of hiding ." + method + "() - #" + this.id );
1196 $methodElems[ method ]( shortDuration, function() {
1198 $elem = jQuery( this ),
1199 startVal = $elem.data("startVal");
1201 $elem.removeData("startVal");
1203 equal( $elem.css( prop ), startVal, "original value restored by ." + method + "() - #" + id );
1205 // Interrupt a showing toggle
1206 $elem.hide()[ method ]( longDuration );
1207 setTimeout(function() {
1209 notEqual( $elem.css( prop ), startVal, ".stop() before completion of showing ." + method + "() - #" + id );
1212 $elem[ method ]( shortDuration, function() {
1213 equal( $elem.css( prop ), startVal, "original value restored by ." + method + "() - #" + id );
1222 test("animate with per-property easing", function(){
1227 var data = { a:0, b:0, c:0 },
1228 _test1_called = false,
1229 _test2_called = false,
1230 _default_test_called = false,
1232 a: [ 100, "_test1" ],
1233 b: [ 100, "_test2" ],
1237 jQuery.easing["_test1"] = function(p) {
1238 _test1_called = true;
1242 jQuery.easing["_test2"] = function(p) {
1243 _test2_called = true;
1247 jQuery.easing["_default_test"] = function(p) {
1248 _default_test_called = true;
1252 jQuery(data).animate( props, 400, "_default_test", function(){
1255 ok( _test1_called, "Easing function (_test1) called" );
1256 ok( _test2_called, "Easing function (_test2) called" );
1257 ok( _default_test_called, "Easing function (_default) called" );
1258 equal( props.a[ 1 ], "_test1", "animate does not change original props (per-property easing would be lost)");
1259 equal( props.b[ 1 ], "_test2", "animate does not change original props (per-property easing would be lost)");
1264 test("animate with CSS shorthand properties", function(){
1268 var _default_count = 0,
1270 propsBasic = { "padding": "10 20 30" },
1271 propsSpecial = { "padding": [ "1 2 3", "_special" ] };
1273 jQuery.easing._default = function(p) {
1280 jQuery.easing._special = function(p) {
1288 .animate( propsBasic, 200, "_default", function() {
1289 equal( this.style.paddingTop, "10px", "padding-top was animated" );
1290 equal( this.style.paddingLeft, "20px", "padding-left was animated" );
1291 equal( this.style.paddingRight, "20px", "padding-right was animated" );
1292 equal( this.style.paddingBottom, "30px", "padding-bottom was animated" );
1293 equal( _default_count, 4, "per-animation default easing called for each property" );
1296 .animate( propsSpecial, 200, "_default", function() {
1297 equal( this.style.paddingTop, "1px", "padding-top was animated again" );
1298 equal( this.style.paddingLeft, "2px", "padding-left was animated again" );
1299 equal( this.style.paddingRight, "2px", "padding-right was animated again" );
1300 equal( this.style.paddingBottom, "3px", "padding-bottom was animated again" );
1301 equal( _default_count, 0, "per-animation default easing not called" );
1302 equal( _special_count, 4, "special easing called for each property" );
1304 jQuery(this).css("padding", "0");
1305 delete jQuery.easing._default;
1306 delete jQuery.easing._special;
1311 test("hide hidden elements, with animation (bug #7141)", function() {
1316 var div = jQuery("<div style='display:none'></div>").appendTo("#qunit-fixture");
1317 equal( div.css("display"), "none", "Element is hidden by default" );
1318 div.hide(1, function () {
1319 ok( !jQuery._data(div, "olddisplay"), "olddisplay is undefined after hiding an already-hidden element" );
1320 div.show(1, function () {
1321 equal( div.css("display"), "block", "Show a double-hidden element" );
1327 test("animate unit-less properties (#4966)", 2, function() {
1329 var div = jQuery( "<div style='z-index: 0; position: absolute;'></div>" ).appendTo( "#qunit-fixture" );
1330 equal( div.css( "z-index" ), "0", "z-index is 0" );
1331 div.animate({ zIndex: 2 }, function() {
1332 equal( div.css( "z-index" ), "2", "z-index is 2" );
1337 test( "animate properties missing px w/ opacity as last (#9074)", 2, function() {
1340 var div = jQuery( "<div style='position: absolute; margin-left: 0; left: 0px;'></div>" )
1341 .appendTo( "#qunit-fixture" );
1342 function cssInt( prop ) {
1343 return parseInt( div.css( prop ), 10 );
1345 equal( cssInt( "marginLeft" ), 0, "Margin left is 0" );
1346 equal( cssInt( "left" ), 0, "Left is 0" );
1352 setTimeout(function() {
1353 var ml = cssInt( "marginLeft" ),
1354 l = cssInt( "left" );
1355 notEqual( ml, 0, "Margin left is not 0 after partial animate" );
1356 notEqual( ml, 200, "Margin left is not 200 after partial animate" );
1357 notEqual( l, 0, "Left is not 0 after partial animate" );
1358 notEqual( l, 200, "Left is not 200 after partial animate" );
1359 div.stop().remove();
1364 test("callbacks should fire in correct order (#9100)", function() {
1371 jQuery("<p data-operation='*2'></p><p data-operation='^2'></p>")
1372 .appendTo("#qunit-fixture")
1373 // The test will always pass if no properties are animated or if the duration is 0
1374 .animate({ fontSize: 12 }, 13, function() {
1375 a *= jQuery(this).data("operation") === "*2" ? 2 : a;
1378 equal( a, 4, "test value has been *2 and _then_ ^2");
1384 asyncTest( "callbacks that throw exceptions will be removed (#5684)", function() {
1387 var foo = jQuery( "#foo" );
1389 function testException() {
1392 foo.animate({ height: 1 }, 1, function() {
1393 throw new testException();
1396 // this test thoroughly abuses undocumented methods - please feel free to update
1397 // with any changes internally to these functions.
1399 // make sure that the standard timer loop will NOT run.
1402 setTimeout(function() {
1404 // the first call to fx.tick should raise the callback exception
1405 raises( jQuery.fx.tick, testException, "Exception was thrown" );
1407 // the second call shouldn't
1410 ok( true, "Test completed without throwing a second exception" );
1416 test("animate will scale margin properties individually", function() {
1420 var foo = jQuery( "#foo" ).css({
1425 ok( foo.css( "marginLeft" ) !== foo.css( "marginRight" ), "Sanity Check" );
1431 ok( foo.css( "marginLeft") !== foo.css( "marginRight" ), "The margin properties are different");
1433 // clean up for next test
1443 test("Do not append px to 'fill-opacity' #9548", 1, function() {
1444 var $div = jQuery("<div>").appendTo("#qunit-fixture");
1446 $div.css("fill-opacity", 0).animate({ "fill-opacity": 1.0 }, 0, function () {
1447 equal( jQuery(this).css("fill-opacity"), 1, "Do not append px to 'fill-opacity'");
1452 asyncTest("line-height animates correctly (#13855)", 12, function() {
1453 var longDuration = 2000,
1454 shortDuration = 500,
1456 "<p style='line-height: 100;'>unitless</p>" +
1457 "<p style='line-height: 5000px;'>px</p>" +
1458 "<p style='line-height: 5000%;'>percent</p>" +
1459 "<p style='line-height: 100em;'>em</p>"
1460 ).appendTo("#qunit-fixture"),
1461 initialHeight = jQuery.map( animated, function( el ) {
1462 return jQuery( el ).height();
1467 animated.animate( { "line-height": "hide" }, longDuration );
1468 setTimeout(function() {
1469 var progress = ( (new Date()) - t0 ) / longDuration;
1471 animated.each(function( i ) {
1472 var label = jQuery.text( this ),
1473 initial = initialHeight[ i ],
1474 height = jQuery( this ).height(),
1475 lower = initial * ( 1 - progress ) / tolerance;
1476 ok( height < initial, "hide " + label + ": upper bound; " +
1477 height + " < " + initial + " @ " + ( progress * 100 ) + "%" );
1478 ok( height > lower, "hide " + label + ": lower bound; " +
1479 height + " > " + lower + " @ " + ( progress * 100 ) + "%" );
1483 animated.stop( true, true ).hide().animate( { "line-height": "show" }, longDuration );
1484 setTimeout(function() {
1485 var progress = ( (new Date()) - t0 ) / longDuration;
1487 animated.each(function( i ) {
1488 var label = jQuery.text( this ),
1489 initial = initialHeight[ i ],
1490 height = jQuery( this ).height(),
1491 upper = initial * progress * tolerance;
1492 ok( height < upper, "show " + label + ": upper bound; " +
1493 height + " < " + upper + " @ " + ( progress * 100 ) + "%" );
1496 animated.stop( true, true );
1502 // Start 1.8 Animation tests
1503 asyncTest( "jQuery.Animation( object, props, opts )", 4, function() {
1516 animation = jQuery.Animation( testObject, testDest, { "duration": 1 });
1517 animation.done(function() {
1518 for ( var prop in testDest ) {
1519 equal( testObject[ prop ], testDest[ prop ], "Animated: " + prop );
1521 animation.done(function() {
1522 deepEqual( testObject, testDest, "No unexpected properties" );
1528 asyncTest( "Animate Option: step: function( percent, tween )", 1, function() {
1530 jQuery( "#foo" ).animate({
1536 step: function( value, tween ) {
1537 var calls = counter[ tween.prop ] = counter[ tween.prop ] || [];
1538 // in case this is called multiple times for either, lets store it in
1539 // 0 or 1 in the array
1540 calls[ value === 0 ? 0 : 1 ] = value;
1542 }).queue( function( next ) {
1543 deepEqual( counter, {
1547 }, "Step function was called once at 0% and once at 100% for each property");
1553 asyncTest( "Animate callbacks have correct context", 2, function() {
1554 var foo = jQuery( "#foo" );
1558 equal( foo[ 0 ], this, "Complete callback after stop(true) `this` is element" );
1559 }).stop( true, true );
1563 equal( foo[ 0 ], this, "Complete callback `this` is element" );
1568 asyncTest( "User supplied callback called after show when fx off (#8892)", 2, function() {
1569 var foo = jQuery( "#foo" );
1570 jQuery.fx.off = true;
1572 foo.fadeIn( 500, function() {
1573 ok( jQuery( this ).is( ":visible" ), "Element is visible in callback" );
1574 foo.fadeOut( 500, function() {
1575 ok( jQuery( this ).is( ":hidden" ), "Element is hidden in callback" );
1576 jQuery.fx.off = false;
1582 test( "animate should set display for disconnected nodes", function() {
1590 fadeTo: [ "fast", 0.5 ],
1591 slideDown: [ "fast" ],
1593 animate: [{ width: "show" }]
1595 $divTest = jQuery("<div>test</div>"),
1596 // parentNode = null
1597 $divEmpty = jQuery("<div/>"),
1598 $divNone = jQuery("<div style='display: none;'/>"),
1599 $divInline = jQuery("<div style='display: inline;'/>");
1601 strictEqual( $divTest.show()[ 0 ].style.display, "block", "set display with show() for element with parentNode = document fragment" );
1602 strictEqual( $divEmpty.show()[ 0 ].style.display, "block", "set display with show() for element with parentNode = null" );
1603 strictEqual( $divNone.show()[ 0 ].style.display, "block", "show() should change display if it already set to none" );
1604 strictEqual( $divInline.show()[ 0 ].style.display, "inline", "show() should not change display if it already set" );
1606 QUnit.expectJqData( $divTest[ 0 ], "olddisplay" );
1607 QUnit.expectJqData( $divEmpty[ 0 ], "olddisplay" );
1608 QUnit.expectJqData( $divNone[ 0 ], "olddisplay" );
1611 jQuery.each( methods, function( name, opt ) {
1614 // parentNode = document fragment
1615 jQuery("<div>test</div>"),
1617 // parentNode = null
1621 var callback = [function () {
1622 strictEqual( this.style.display, "block", "set display to block with " + name );
1624 QUnit.expectJqData( this, "olddisplay" );
1630 jQuery.fn[ name ].apply( this, opt.concat( callback ) );
1635 asyncTest("Animation callback should not show animated element as :animated (#7157)", 1, function() {
1636 var foo = jQuery( "#foo" );
1640 }, 100, function() {
1641 ok( !foo.is(":animated"), "The element is not animated" );
1646 asyncTest( "hide called on element within hidden parent should set display to none (#10045)", 3, function() {
1647 var hidden = jQuery(".hidden"),
1648 elems = jQuery("<div>hide</div><div>hide0</div><div>hide1</div>");
1650 hidden.append( elems );
1653 elems.eq( 0 ).hide(),
1654 elems.eq( 1 ).hide( 0 ),
1655 elems.eq( 2 ).hide( 1 )
1657 strictEqual( elems.get( 0 ).style.display, "none", "hide() called on element within hidden parent should set display to none" );
1658 strictEqual( elems.get( 1 ).style.display, "none", "hide( 0 ) called on element within hidden parent should set display to none" );
1659 strictEqual( elems.get( 2 ).style.display, "none", "hide( 1 ) called on element within hidden parent should set display to none" );
1666 asyncTest( "hide, fadeOut and slideUp called on element width height and width = 0 should set display to none", 5, function() {
1667 var foo = jQuery("#foo"),
1671 for ( ; i < 5; i++ ) {
1672 elems = elems.add("<div style='width:0;height:0;'></div>");
1675 foo.append( elems );
1678 elems.eq( 0 ).hide(),
1679 elems.eq( 1 ).hide( jQuery.noop ),
1680 elems.eq( 2 ).hide( 1 ),
1681 elems.eq( 3 ).fadeOut(),
1682 elems.eq( 4 ).slideUp()
1684 strictEqual( elems.get( 0 ).style.display, "none", "hide() called on element width height and width = 0 should set display to none" );
1685 strictEqual( elems.get( 1 ).style.display, "none",
1686 "hide( jQuery.noop ) called on element width height and width = 0 should set display to none" );
1687 strictEqual( elems.get( 2 ).style.display, "none", "hide( 1 ) called on element width height and width = 0 should set display to none" );
1688 strictEqual( elems.get( 3 ).style.display, "none", "fadeOut() called on element width height and width = 0 should set display to none" );
1689 strictEqual( elems.get( 4 ).style.display, "none", "slideUp() called on element width height and width = 0 should set display to none" );
1695 asyncTest( "Handle queue:false promises", 10, function() {
1696 var foo = jQuery( "#foo" ).clone().andSelf(),
1704 complete: function() {
1705 ok( step++ <= 2, "Step one or two" );
1711 complete: function() {
1712 ok( step > 2 && step < 5, "Step three or four" );
1717 foo.promise().done( function() {
1718 equal( step++, 5, "steps 1-5: queue:false then queue:fx done" );
1723 complete: function() {
1724 ok( step > 5 && step < 8, "Step six or seven" );
1732 complete: function() {
1733 ok( step > 7 && step < 10, "Step eight or nine" );
1736 }).promise().done( function() {
1737 equal( step++, 10, "steps 6-10: queue:fx then queue:false" );
1744 asyncTest( "multiple unqueued and promise", 4, function() {
1745 var foo = jQuery( "#foo" ),
1752 complete: function() {
1753 strictEqual( step++, 2, "Step 2" );
1760 complete: function() {
1761 strictEqual( step++, 3, "Step 3" );
1766 complete: function() {
1767 // no properties is a non-op and finishes immediately
1768 strictEqual( step++, 1, "Step 1" );
1770 }).promise().done( function() {
1771 strictEqual( step++, 4, "Step 4" );
1776 asyncTest( "animate does not change start value for non-px animation (#7109)", 1, function() {
1777 var parent = jQuery( "<div><div></div></div>" ).css({ width: 284, height: 1 }).appendTo( "#qunit-fixture" ),
1778 child = parent.children().css({ fontSize: "98.6in", width: "0.01em", height: 1 }),
1779 actual = parseFloat( child.css( "width" ) ),
1782 child.animate({ width: "0%" }, {
1785 computed.push( parseFloat( child.css( "width" ) ) );
1787 }).queue( function( next ) {
1788 var ratio = computed[ 0 ] / actual;
1789 ok( ratio > 0.9 && ratio < 1.1 , "Starting width was close enough" );
1796 asyncTest( "non-px animation handles non-numeric start (#11971)", 2, function() {
1797 var foo = jQuery("#foo"),
1798 initial = foo.css("backgroundPositionX");
1802 ok( true, "Style property not understood" );
1807 foo.animate({ backgroundPositionX: "42%" }, {
1809 progress: function( anim, percent ) {
1814 if ( parseFloat( initial ) ) {
1815 equal( jQuery.style( this, "backgroundPositionX" ), initial, "Numeric start preserved" );
1817 equal( jQuery.style( this, "backgroundPositionX" ), "0%", "Non-numeric start zeroed" );
1821 equal( jQuery.style( this, "backgroundPositionX" ), "42%", "End reached" );
1827 asyncTest("Animation callbacks (#11797)", 15, function() {
1828 var targets = jQuery("#foo").children(),
1830 expectedProgress = 0;
1832 targets.eq( 0 ).animate( {}, {
1835 ok( true, "empty: start" );
1837 progress: function( anim, percent ) {
1838 equal( percent, 0, "empty: progress 0" );
1841 ok( true, "empty: done" );
1844 ok( false, "empty: fail" );
1846 always: function() {
1847 ok( true, "empty: always" );
1852 ok( done, "empty: done immediately" );
1855 targets.eq( 1 ).animate({
1860 ok( true, "stopped: start" );
1862 progress: function( anim, percent ) {
1863 equal( percent, 0, "stopped: progress 0" );
1866 ok( false, "stopped: done" );
1869 ok( true, "stopped: fail" );
1871 always: function() {
1872 ok( true, "stopped: always" );
1877 ok( done, "stopped: stopped immediately" );
1879 targets.eq( 2 ).animate({
1884 ok( true, "async: start" );
1886 progress: function( anim, percent ) {
1887 // occasionally the progress handler is called twice in first frame.... *shrug*
1888 if ( percent === 0 && expectedProgress === 1 ) {
1891 equal( percent, expectedProgress, "async: progress " + expectedProgress );
1892 // once at 0, once at 1
1896 ok( true, "async: done" );
1899 ok( false, "async: fail" );
1901 always: function() {
1902 ok( true, "async: always" );
1908 test( "Animate properly sets overflow hidden when animating width/height (#12117)", 8, function() {
1909 jQuery.each( [ "height", "width" ], function( _, prop ) {
1910 jQuery.each( [ 100, 0 ], function( _, value ) {
1911 var div = jQuery("<div>").css( "overflow", "auto" ),
1913 props[ prop ] = value;
1914 div.animate( props, 1 );
1915 equal( div.css( "overflow" ), "hidden",
1916 "overflow: hidden set when animating " + prop + " to " + value );
1918 if ( jQuery.support.shrinkWrapBlocks ) {
1919 ok( true, "cannot restore overflow, shrinkWrapBlocks" );
1921 equal( div.css( "overflow" ), "auto",
1922 "overflow: auto restored after animating " + prop + " to " + value );
1928 test( "Each tick of the timer loop uses a fresh time (#12837)", function() {
1929 var lastVal, current,
1937 step: function( p, fx ) {
1938 ok( fx.now !== lastVal, "Current value is not the last value: " + lastVal + " - " + fx.now );
1942 current = jQuery.now();
1943 // intentionally empty, we want to spin wheels until the time changes.
1944 while ( current === jQuery.now() ) { }
1946 // now that we have a new time, run another tick
1949 current = jQuery.now();
1950 // intentionally empty, we want to spin wheels until the time changes.
1951 while ( current === jQuery.now() ) { }
1957 test( "Animations with 0 duration don't ease (#12273)", 1, function() {
1958 jQuery.easing.test = function() {
1959 ok( false, "Called easing" );
1962 jQuery( "#foo" ).animate({
1967 complete: function() {
1968 equal( jQuery( this ).height(), 100, "Height is 100" );
1972 delete jQuery.easing.test;
1975 jQuery.map([ "toggle", "slideToggle", "fadeToggle" ], function ( method ) {
1976 // this test would look a lot better if we were using something to override
1977 // the default timers
1978 var duration = 1500;
1979 asyncTest( "toggle state tests: " + method + " (#8685)", function() {
1980 function secondToggle() {
1981 var stopped = parseFloat( element.css( check ) );
1985 step: function( p, fx ) {
1986 if ( fx.pos > 0.1 && fx.prop === check && !tested ) {
1988 equal( fx.start, stopped, check + " starts at " + stopped + " where it stopped" );
1989 equal( fx.end, original, check + " ending value is " + original );
1999 check = method === "slideToggle" ? "height" : "opacity",
2000 element = jQuery("#foo").height( 200 );
2007 step: function( p, fx ) {
2008 if ( fx.pos > 0.1 && fx.prop === check && !tested ) {
2010 original = fx.start;
2011 ok( fx.start !== 0, check + " is starting at " + original + " on first toggle (non-zero)" );
2012 equal( fx.end, 0, check + " is ending at 0 on first toggle" );
2016 always: secondToggle
2021 test( "jQuery.fx.start & jQuery.fx.stop hook points", function() {
2022 var oldStart = jQuery.fx.start,
2023 oldStop = jQuery.fx.stop,
2024 foo = jQuery({ foo: 0 });
2028 jQuery.fx.start = function() {
2029 ok( true, "start called" );
2031 jQuery.fx.stop = function() {
2032 ok( true, "stop called" );
2036 foo.animate({ foo: 1 }, { queue: false });
2038 foo.animate({ foo: 2 }, { queue: false });
2044 jQuery.fx.start = oldStart;
2045 jQuery.fx.stop = oldStop;
2048 test( ".finish() completes all queued animations", function() {
2055 div = jQuery("<div>");
2059 jQuery.each( animations, function( prop, value ) {
2061 anim[ prop ] = value;
2062 // the delay shouldn't matter at all!
2063 div.css( prop, 1 ).animate( anim, function() {
2064 ok( true, "Called animation callback for " + prop );
2067 equal( div.queue().length, 8, "8 animations in the queue" );
2069 jQuery.each( animations, function( prop, value ) {
2070 equal( parseFloat( div.css( prop ) ), value, prop + " finished at correct value" );
2072 equal( div.queue().length, 0, "empty queue when done" );
2073 equal( div.is(":animated"), false, ":animated doesn't match" );
2077 // leaves a "shadow timer" which does nothing around, need to force a tick
2081 test( ".finish( false ) - unqueued animations", function() {
2088 div = jQuery("<div>");
2092 jQuery.each( animations, function( prop, value ) {
2094 anim[ prop ] = value;
2095 div.css( prop, 1 ).animate( anim, {
2097 complete: function() {
2098 ok( true, "Called animation callback for " + prop );
2102 equal( div.queue().length, 0, "0 animations in the queue" );
2103 div.finish( false );
2104 jQuery.each( animations, function( prop, value ) {
2105 equal( parseFloat( div.css( prop ) ), value, prop + " finished at correct value" );
2107 equal( div.is(":animated"), false, ":animated doesn't match" );
2111 // leaves a "shadow timer" which does nothing around, need to force a tick
2115 test( ".finish( \"custom\" ) - custom queue animations", function() {
2122 div = jQuery("<div>");
2126 jQuery.each( animations, function( prop, value ) {
2128 anim[ prop ] = value;
2129 div.css( prop, 1 ).animate( anim, {
2131 complete: function() {
2132 ok( true, "Called animation callback for " + prop );
2136 equal( div.queue( "custom" ).length, 4, "4 animations in the queue" );
2137 // start the first animation
2138 div.dequeue( "custom" );
2139 equal( div.is(":animated"), true, ":animated matches" );
2140 div.finish( "custom" );
2141 jQuery.each( animations, function( prop, value ) {
2142 equal( parseFloat( div.css( prop ) ), value, prop + " finished at correct value" );
2144 equal( div.is(":animated"), false, ":animated doesn't match" );
2148 // leaves a "shadow timer" which does nothing around, need to force a tick
2152 test( ".finish() calls finish of custom queue functions", function() {
2153 function queueTester( next, hooks ) {
2154 hooks.stop = function( gotoEnd ) {
2156 equal( this, div[0] );
2157 ok( gotoEnd, "hooks.stop(true) called");
2160 var div = jQuery( "<div>" ),
2165 queueTester.finish = function() {
2167 ok( true, "Finish called on custom queue function" );
2170 div.queue( queueTester ).queue( queueTester ).queue( queueTester ).finish();
2172 equal( inside, 1, "1 stop(true) callback" );
2173 equal( outside, 2, "2 finish callbacks" );
2178 asyncTest( ".finish() is applied correctly when multiple elements were animated (#13937)", function() {
2181 var elems = jQuery("<a>0</a><a>1</a><a>2</a>");
2183 elems.animate( { opacity: 0 }, 1500 ).animate( { opacity: 1 }, 1500 );
2184 setTimeout(function() {
2185 elems.eq( 1 ).finish();
2186 ok( !elems.eq( 1 ).queue().length, "empty queue for .finish()ed element" );
2187 ok( elems.eq( 0 ).queue().length, "non-empty queue for preceding element" );
2188 ok( elems.eq( 2 ).queue().length, "non-empty queue for following element" );
2191 // setTimeout needed in order to avoid setInterval/setTimeout execution bug in FF
2192 window.setTimeout(function() {
2198 asyncTest( "slideDown() after stop() (#13483)", 2, function() {
2199 var ul = jQuery( "<ul style='height: 100px; display: block;'></ul>" )
2200 .appendTo("#qunit-fixture"),
2201 origHeight = ul.height();
2203 // First test. slideUp() -> stop() in the middle -> slideDown() until the end
2205 setTimeout( function() {
2207 ul.slideDown( 1, function() {
2208 equal( ul.height(), origHeight, "slideDown() after interrupting slideUp() with stop(). Height must be in original value" );
2210 // Second test. slideDown() -> stop() in the middle -> slideDown() until the end
2211 ul.slideUp( 1, function() {
2212 ul.slideDown( 1000 );
2213 setTimeout( function() {
2215 ul.slideDown( 1, function() {
2216 equal( ul.height(), origHeight, "slideDown() after interrupting slideDown() with stop(). Height must be in original value" );
2229 asyncTest( "fadeIn() after stop() (related to #13483)", 5, function() {
2230 var ul = jQuery( "<ul style='height: 100px; display: block;'></ul>" )
2231 .appendTo("#qunit-fixture").css( "opacity", 1 ),
2232 origOpacity = ul.css( "opacity" );
2234 // First test. fadeOut() -> stop() in the middle -> fadeIn() until the end
2236 setTimeout( function() {
2238 ok( ul.css( "opacity" ) > 0, "fadeOut() interrupted" );
2239 ul.fadeIn( 1, function() {
2240 equal( ul.css( "opacity" ), origOpacity, "fadeIn() restored original opacity after interrupted fadeOut()" );
2242 // Second test. fadeIn() -> stop() in the middle -> fadeIn() until the end
2243 ul.fadeOut( 1, function() {
2244 equal( ul.css( "opacity" ), origOpacity, "fadeOut() completed" );
2246 setTimeout( function() {
2248 ok( ul.css( "opacity" ) < origOpacity, "fadeIn() interrupted" );
2249 ul.fadeIn( 1, function() {
2250 equal( ul.css("opacity"), origOpacity, "fadeIn() restored original opacity after interrupted fadeIn()" );