1 module("effects", { teardown: moduleTeardown });
3 test("sanity check", function() {
5 ok( jQuery("#dl:visible, #qunit-fixture:visible, #foo:visible").length === 3, "QUnit state is correct for testing effects" );
8 test("show()", function() {
11 var hiddendiv = jQuery("div.hidden");
13 hiddendiv.hide().show();
15 equal( hiddendiv.css("display"), "block", "Make sure a pre-hidden div is visible." );
17 var div = jQuery("<div>").hide().appendTo("#qunit-fixture").show();
19 equal( div.css("display"), "block", "Make sure pre-hidden divs show" );
23 hiddendiv = jQuery("div.hidden");
25 equal(jQuery.css( hiddendiv[0], "display"), "none", "hiddendiv is display: none");
27 hiddendiv.css("display", "block");
28 equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block");
31 equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block");
33 hiddendiv.css("display","");
36 div = jQuery("#qunit-fixture div");
37 div.show().each(function(){
38 if ( this.style.display == "none" ) pass = false;
44 "undefined speed": undefined,
45 "empty string speed": "",
49 jQuery.each(speeds, function(name, speed) {
51 div.hide().show(speed).each(function() {
52 if ( this.style.display == "none" ) pass = false;
54 ok( pass, "Show with " + name);
57 jQuery.each(speeds, function(name, speed) {
59 div.hide().show(speed, function() {
62 ok( pass, "Show with " + name + " does not call animate callback" );
65 // #show-tests * is set display: none in CSS
66 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>");
68 var old = jQuery("#test-table").show().css("display") !== "table";
69 jQuery("#test-table").remove();
78 "table" : old ? "block" : "table",
79 "thead" : old ? "block" : "table-header-group",
80 "tbody" : old ? "block" : "table-row-group",
81 "tr" : old ? "block" : "table-row",
82 "th" : old ? "block" : "table-cell",
83 "td" : old ? "block" : "table-cell",
85 "li" : old ? "block" : "list-item"
88 jQuery.each(test, function(selector, expected) {
89 var elem = jQuery(selector, "#show-tests").show();
90 equal( elem.css("display"), expected, "Show using correct display type for " + selector );
93 // Make sure that showing or hiding a text node doesn't cause an error
94 jQuery("<div>test</div> text <span>test</span>").show().remove();
95 jQuery("<div>test</div> text <span>test</span>").hide().remove();
98 test("show(Number) - other displays", function() {
103 // #show-tests * is set display: none in CSS
104 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>");
106 var old = jQuery("#test-table").show().css("display") !== "table",
108 jQuery("#test-table").remove();
117 "table" : old ? "block" : "table",
118 "thead" : old ? "block" : "table-header-group",
119 "tbody" : old ? "block" : "table-row-group",
120 "tr" : old ? "block" : "table-row",
121 "th" : old ? "block" : "table-cell",
122 "td" : old ? "block" : "table-cell",
124 "li" : old ? "block" : "list-item"
127 jQuery.each(test, function(selector, expected) {
128 var elem = jQuery(selector, "#show-tests").show(1, function() {
129 equal( elem.css("display"), expected, "Show using correct display type for " + selector );
130 if ( ++num === 15 ) {
140 test("Persist correct display value", function() {
145 // #show-tests * is set display: none in CSS
146 jQuery("#qunit-fixture").append("<div id='show-tests'><span style='position:absolute;'>foo</span></div>");
148 var $span = jQuery("#show-tests span"),
149 displayNone = $span.css("display"),
150 display = "", num = 0;
154 display = $span.css("display");
158 $span.fadeIn(100, function() {
159 equal($span.css("display"), display, "Expecting display: " + display);
160 $span.fadeOut(100, function () {
161 equal($span.css("display"), displayNone, "Expecting display: " + displayNone);
162 $span.fadeIn(100, function() {
163 equal($span.css("display"), display, "Expecting display: " + display);
170 test("show() resolves correct default display #8099", function() {
172 var tt8099 = jQuery("<tt/>").appendTo("body"),
173 dfn8099 = jQuery("<dfn/>", { html: "foo"}).appendTo("body");
175 equal( tt8099.css("display"), "none", "default display override for all tt" );
176 equal( tt8099.show().css("display"), "inline", "Correctly resolves display:inline" );
178 equal( jQuery("#foo").hide().show().css("display"), "block", "Correctly resolves display:block after hide/show" );
180 equal( tt8099.hide().css("display"), "none", "default display override for all tt" );
181 equal( tt8099.show().css("display"), "inline", "Correctly resolves display:inline" );
183 equal( dfn8099.css("display"), "none", "default display override for all dfn" );
184 equal( dfn8099.show().css("display"), "inline", "Correctly resolves display:inline" );
191 test( "show() resolves correct default display, detached nodes (#10006)", function(){
192 // Tests originally contributed by Orkel in
193 // https://github.com/jquery/jquery/pull/458
198 div = jQuery("<div class='hidden'>");
199 div.show().appendTo("#qunit-fixture");
200 equal( div.css("display"), "block", "Make sure a detached, pre-hidden( through stylesheets ) div is visible." );
202 div = jQuery("<div style='display: none'>");
203 div.show().appendTo("#qunit-fixture");
204 equal( div.css("display"), "block", "Make sure a detached, pre-hidden( through inline style ) div is visible." );
206 span = jQuery("<span class='hidden'/>");
207 span.show().appendTo("#qunit-fixture");
208 equal( span.css("display"), "inline", "Make sure a detached, pre-hidden( through stylesheets ) span has default display." );
210 span = jQuery("<span style='display: inline'/>");
211 span.show().appendTo("#qunit-fixture");
212 equal( span.css("display"), "inline", "Make sure a detached, pre-hidden( through inline style ) span has default display." );
214 div = jQuery("<div><div class='hidden'></div></div>").children("div");
215 div.show().appendTo("#qunit-fixture");
216 equal( div.css("display"), "block", "Make sure a detached, pre-hidden( through stylesheets ) div inside another visible div is visible." );
218 div = jQuery("<div><div style='display: none'></div></div>").children("div");
219 div.show().appendTo("#qunit-fixture");
220 equal( div.css("display"), "block", "Make sure a detached, pre-hidden( through inline style ) div inside another visible div is visible." );
222 div = jQuery("div.hidden");
224 equal( div.css("display"), "block", "Make sure a detached( through detach() ), pre-hidden div is visible." );
227 span = jQuery("<span>");
228 span.appendTo("#qunit-fixture").detach().show().appendTo("#qunit-fixture" );
229 equal( span.css("display"), "inline", "Make sure a detached( through detach() ), pre-hidden span has default display." );
232 div = jQuery("<div>");
233 div.show().appendTo("#qunit-fixture");
234 ok( !!div.get( 0 ).style.display, "Make sure not hidden div has a inline style." );
236 div = jQuery( document.createElement("div") );
237 div.show().appendTo("#qunit-fixture");
238 equal( div.css("display"), "block", "Make sure a pre-created element has default display." );
240 div = jQuery("<div style='display: inline'/>");
241 div.show().appendTo("#qunit-fixture");
242 equal( div.css("display"), "inline", "Make sure that element has same display when it was created." );
246 test("animate(Hash, Object, Function)", function() {
249 var hash = {opacity: "show"};
250 var hashCopy = jQuery.extend({}, hash);
251 jQuery("#foo").animate(hash, 0, function() {
252 equal( hash.opacity, hashCopy.opacity, "Check if animate changed the hash parameter" );
257 test("animate negative height", function() {
260 jQuery("#foo").animate({ height: -100 }, 100, function() {
261 equal( this.offsetHeight, 0, "Verify height." );
266 test("animate negative padding", function() {
269 jQuery("#foo").animate({ paddingBottom: -100 }, 100, function() {
270 equal( jQuery(this).css("paddingBottom"), "0px", "Verify paddingBottom." );
275 test("animate block as inline width/height", function() {
278 var span = jQuery("<span>").css("display", "inline-block").appendTo("body"),
279 expected = span.css("display");
283 if ( jQuery.support.inlineBlockNeedsLayout || expected === "inline-block" ) {
286 jQuery("#foo").css({ display: "inline", width: "", height: "" }).animate({ width: 42, height: 42 }, 100, function() {
287 equal( jQuery(this).css("display"), jQuery.support.inlineBlockNeedsLayout ? "inline" : "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
288 equal( this.offsetWidth, 42, "width was animated" );
289 equal( this.offsetHeight, 42, "height was animated" );
293 // Browser doesn't support inline-block
295 ok( true, "Browser doesn't support inline-block" );
296 ok( true, "Browser doesn't support inline-block" );
297 ok( true, "Browser doesn't support inline-block" );
301 test("animate native inline width/height", function() {
304 var span = jQuery("<span>").css("display", "inline-block").appendTo("body"),
305 expected = span.css("display");
309 if ( jQuery.support.inlineBlockNeedsLayout || expected === "inline-block" ) {
311 jQuery("#foo").css({ display: "", width: "", height: "" })
312 .append("<span>text</span>")
314 .animate({ width: 42, height: 42 }, 100, function() {
315 equal( jQuery(this).css("display"), "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
316 equal( this.offsetWidth, 42, "width was animated" );
317 equal( this.offsetHeight, 42, "height was animated" );
321 // Browser doesn't support inline-block
323 ok( true, "Browser doesn't support inline-block" );
324 ok( true, "Browser doesn't support inline-block" );
325 ok( true, "Browser doesn't support inline-block" );
329 test("animate block width/height", function() {
332 jQuery("#foo").css({ display: "block", width: 20, height: 20 }).animate({ width: 42, height: 42 }, 100, function() {
333 equal( jQuery(this).css("display"), "block", "inline-block was not set on block element when animating width/height" );
334 equal( this.offsetWidth, 42, "width was animated" );
335 equal( this.offsetHeight, 42, "height was animated" );
340 test("animate table width/height", function() {
344 var displayMode = jQuery("#table").css("display") !== "table" ? "block" : "table";
346 jQuery("#table").animate({ width: 42, height: 42 }, 100, function() {
347 equal( jQuery(this).css("display"), displayMode, "display mode is correct" );
352 test("animate table-row width/height", function() {
355 var tr = jQuery("#table")
356 .attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 })
357 .html("<tr style='height:42px;'><td style='padding:0;'><div style='width:20px;height:20px;'></div></td></tr>")
360 // IE<8 uses "block" instead of the correct display type
361 var displayMode = tr.css("display") !== "table-row" ? "block" : "table-row";
363 tr.animate({ width: 10, height: 10 }, 100, function() {
364 equal( jQuery(this).css("display"), displayMode, "display mode is correct" );
365 equal( this.offsetWidth, 20, "width animated to shrink wrap point" );
366 equal( this.offsetHeight, 20, "height animated to shrink wrap point" );
371 test("animate table-cell width/height", function() {
374 var td = jQuery("#table")
375 .attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 })
376 .html("<tr><td style='width:42px;height:42px;padding:0;'><div style='width:20px;height:20px;'></div></td></tr>")
379 // IE<8 uses "block" instead of the correct display type
380 var displayMode = td.css("display") !== "table-cell" ? "block" : "table-cell";
382 td.animate({ width: 10, height: 10 }, 100, function() {
383 equal( jQuery(this).css("display"), displayMode, "display mode is correct" );
384 equal( this.offsetWidth, 20, "width animated to shrink wrap point" );
385 equal( this.offsetHeight, 20, "height animated to shrink wrap point" );
390 test("animate percentage(%) on width/height", function() {
393 var $div = jQuery("<div style='position:absolute;top:-999px;left:-999px;width:60px;height:60px;'><div style='width:50%;height:50%;'></div></div>")
394 .appendTo("#qunit-fixture").children("div");
397 $div.animate({ width: "25%", height: "25%" }, 13, function() {
398 var $this = jQuery(this);
399 equal( $this.width(), 15, "Width was animated to 15px rather than 25px");
400 equal( $this.height(), 15, "Height was animated to 15px rather than 25px");
405 test("animate resets overflow-x and overflow-y when finished", function() {
409 .css({ display: "block", width: 20, height: 20, overflowX: "visible", overflowY: "auto" })
410 .animate({ width: 42, height: 42 }, 100, function() {
411 equal( this.style.overflowX, "visible", "overflow-x is visible" );
412 equal( this.style.overflowY, "auto", "overflow-y is auto" );
417 /* // This test ends up being flaky depending upon the CPU load
418 test("animate option (queue === false)", function () {
424 var $foo = jQuery("#foo");
425 $foo.animate({width:"100px"}, 3000, function () {
426 // should finish after unqueued animation so second
428 deepEqual( order, [ 1, 2 ], "Animations finished in the correct order" );
431 $foo.animate({fontSize:"2em"}, {queue:false, duration:10, complete:function () {
432 // short duration and out of queue so should finish first
438 asyncTest( "animate option { queue: false }", function() {
440 var foo = jQuery( "#foo" );
447 complete: function() {
448 ok( true, "Animation Completed" );
453 equal( foo.queue().length, 0, "Queue is empty" );
456 asyncTest( "animate option { queue: true }", function() {
458 var foo = jQuery( "#foo" );
465 complete: function() {
466 ok( true, "Animation Completed" );
471 notEqual( foo.queue().length, 0, "Default queue is not empty" );
475 asyncTest( "animate option { queue: 'name' }", function() {
477 var foo = jQuery( "#foo" ),
478 origWidth = foo.width(),
481 foo.animate( { width: origWidth + 100 }, {
484 complete: function() {
486 // second callback function
488 equal( foo.width(), origWidth + 100, "Animation ended" );
489 equal( foo.queue("name").length, 1, "Queue length of 'name' queue" );
491 }).queue( "name", function( next ) {
493 // last callback function
494 deepEqual( order, [ 1, 2 ], "Callbacks in expected order" );
498 setTimeout( function() {
500 // this is the first callback function that should be called
502 equal( foo.width(), origWidth, "Animation does not start on its own." );
503 equal( foo.queue("name").length, 2, "Queue length of 'name' queue" );
504 foo.dequeue( "name" );
509 test("animate with no properties", function() {
512 var divs = jQuery("div"), count = 0;
514 divs.animate({}, function(){
518 equal( divs.length, count, "Make sure that callback is called for each element in the set." );
522 var foo = jQuery("#foo");
525 foo.animate({top: 10}, 100, function(){
526 ok( true, "Animation was properly dequeued." );
531 test("animate duration 0", function() {
536 var $elems = jQuery([{ a:0 },{ a:0 }]), counter = 0;
538 equal( jQuery.timers.length, 0, "Make sure no animation was running from another test" );
540 $elems.eq(0).animate( {a:1}, 0, function(){
541 ok( true, "Animate a simple property." );
545 // Failed until [6115]
546 equal( jQuery.timers.length, 0, "Make sure synchronic animations are not left on jQuery.timers" );
548 equal( counter, 1, "One synchronic animations" );
550 $elems.animate( { a:2 }, 0, function(){
551 ok( true, "Animate a second simple property." );
555 equal( counter, 3, "Multiple synchronic animations" );
557 $elems.eq(0).animate( {a:3}, 0, function(){
558 ok( true, "Animate a third simple property." );
561 $elems.eq(1).animate( {a:3}, 200, function(){
563 // Failed until [6115]
564 equal( counter, 5, "One synchronic and one asynchronic" );
568 var $elem = jQuery("<div />");
569 $elem.show(0, function(){
570 ok(true, "Show callback with no duration");
572 $elem.hide(0, function(){
573 ok(true, "Hide callback with no duration");
576 // manually clean up detached elements
580 test("animate hyphenated properties", function() {
585 .css("font-size", 10)
586 .animate({"font-size": 20}, 200, function() {
587 equal( this.style.fontSize, "20px", "The font-size property was animated." );
592 test("animate non-element", function() {
596 var obj = { test: 0 };
598 jQuery(obj).animate({test: 200}, 200, function(){
599 equal( obj.test, 200, "The custom property should be modified." );
604 test("stop()", function() {
608 var $foo = jQuery("#foo");
611 $foo.hide().width(200)
612 .animate({ width: "show" }, 1000);
614 setTimeout(function() {
615 var nw = $foo.width();
616 notEqual( nw, w, "An animation occurred " + nw + "px " + w + "px");
620 notEqual( nw, w, "Stop didn't reset the animation " + nw + "px " + w + "px");
621 setTimeout(function() {
623 $foo.removeData(undefined, true);
624 equal( nw, $foo.width(), "The animation didn't continue" );
629 var $one = jQuery("#fadein");
630 var $two = jQuery("#show");
631 $one.fadeTo(100, 0, function() {
634 setTimeout(function() {
635 $two.fadeTo(100, 0, function() {
636 equal( $two.css("opacity"), "0", "Stop does not interfere with animations on other elements (#6641)" );
638 $one.add( $two ).css("opacity", "");
643 test("stop() - several in queue", function() {
647 var $foo = jQuery("#foo");
649 $foo.hide().width(200).width();
651 $foo.animate({ width: "show" }, 1000);
652 $foo.animate({ width: "hide" }, 1000);
653 $foo.animate({ width: "show" }, 1000);
654 setTimeout(function(){
655 equal( $foo.queue().length, 3, "All 3 still in the queue" );
656 var nw = $foo.width();
657 notEqual( nw, w, "An animation occurred " + nw + "px " + w + "px");
661 notEqual( nw, w, "Stop didn't reset the animation " + nw + "px " + w + "px");
668 test("stop(clearQueue)", function() {
672 var $foo = jQuery("#foo");
674 $foo.hide().width(200).width();
676 $foo.animate({ width: "show" }, 1000);
677 $foo.animate({ width: "hide" }, 1000);
678 $foo.animate({ width: "show" }, 1000);
679 setTimeout(function(){
680 var nw = $foo.width();
681 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
685 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
687 equal( $foo.queue().length, 0, "The animation queue was cleared" );
688 setTimeout(function(){
689 equal( nw, $foo.width(), "The animation didn't continue" );
695 test("stop(clearQueue, gotoEnd)", function() {
699 var $foo = jQuery("#foo");
701 $foo.hide().width(200).width();
703 $foo.animate({ width: "show" }, 1000);
704 $foo.animate({ width: "hide" }, 1000);
705 $foo.animate({ width: "show" }, 1000);
706 $foo.animate({ width: "hide" }, 1000);
707 setTimeout(function(){
708 var nw = $foo.width();
709 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
710 $foo.stop(false, true);
713 // Disabled, being flaky
714 //equal( nw, 1, "Stop() reset the animation" );
716 setTimeout(function(){
717 // Disabled, being flaky
718 //equal( $foo.queue().length, 2, "The next animation continued" );
725 asyncTest( "stop( queue, ..., ... ) - Stop single queues", function() {
727 var foo = jQuery( "#foo" ),
730 foo.width( 200 ).height( 200 );
735 complete: function() {
736 equal( foo.width(), 400, "Animation completed for standard queue" );
737 equal( foo.height(), saved, "Height was not changed after the second stop");
747 }).dequeue( "height" ).stop( "height", false, true );
749 equal( foo.height(), 400, "Height was stopped with gotoEnd" );
756 }).dequeue( "height" ).stop( "height", false, false );
757 saved = foo.height();
760 test("toggle()", function() {
762 var x = jQuery("#foo");
763 ok( x.is(":visible"), "is visible" );
765 ok( x.is(":hidden"), "is hidden" );
767 ok( x.is(":visible"), "is visible again" );
770 ok( x.is(":visible"), "is visible" );
772 ok( x.is(":hidden"), "is hidden" );
774 ok( x.is(":visible"), "is visible again" );
777 jQuery.checkOverflowDisplay = function(){
778 var o = jQuery.css( this, "overflow" );
780 equal(o, "visible", "Overflow should be visible: " + o);
781 equal(jQuery.css( this, "display" ), "inline", "Display shouldn't be tampered with.");
786 test( "jQuery.fx.prototype.cur()", 6, function() {
787 var div = jQuery( "<div></div>" ).appendTo( "#qunit-fixture" ).css({
789 border: "5px solid black",
791 marginBottom: "-11000px"
795 ( new jQuery.fx( div, {}, "color" ) ).cur(),
796 jQuery.css( div, "color" ),
797 "Return the same value as jQuery.css for complex properties (bug #7912)"
801 ( new jQuery.fx( div, {}, "borderLeftWidth" ) ).cur(),
803 "Return simple values parsed as Float"
806 // backgroundPosition actually returns 0% 0% in most browser
807 // this fakes a "" return
808 jQuery.cssHooks.backgroundPosition = {
810 ok( true, "hook used" );
816 ( new jQuery.fx( div, {}, "backgroundPosition" ) ).cur(),
818 "Return 0 when jQuery.css returns an empty string"
821 delete jQuery.cssHooks.backgroundPosition;
824 ( new jQuery.fx( div, {}, "left" ) ).cur(),
826 "Return 0 when jQuery.css returns 'auto'"
830 ( new jQuery.fx( div, {}, "marginBottom" ) ).cur(),
832 "support negative values < -10000 (bug #7193)"
836 test("JS Overflow and Display", function() {
839 jQuery.makeTest( "JS Overflow and Display" )
840 .addClass("widewidth")
841 .css({ overflow: "visible", display: "inline" })
842 .addClass("widewidth")
843 .text("Some sample text.")
844 .before("text before")
846 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
849 test("CSS Overflow and Display", function() {
852 jQuery.makeTest( "CSS Overflow and Display" )
853 .addClass("overflow inline")
854 .addClass("widewidth")
855 .text("Some sample text.")
856 .before("text before")
858 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
862 "CSS Auto": function( elem, prop ) {
863 jQuery( elem ).addClass( "auto" + prop )
864 .text( "This is a long string of text." );
867 "JS Auto": function( elem, prop ) {
868 jQuery( elem ).css( prop, "" )
869 .text( "This is a long string of text." );
872 "CSS 100": function( elem, prop ) {
873 jQuery( elem ).addClass( "large" + prop );
876 "JS 100": function( elem, prop ) {
877 jQuery( elem ).css( prop, prop === "opacity" ? 1 : "100px" );
878 return prop === "opacity" ? 1 : 100;
880 "CSS 50": function( elem, prop ) {
881 jQuery( elem ).addClass( "med" + prop );
884 "JS 50": function( elem, prop ) {
885 jQuery( elem ).css( prop, prop === "opacity" ? 0.50 : "50px" );
886 return prop === "opacity" ? 0.5 : 50;
888 "CSS 0": function( elem, prop ) {
889 jQuery( elem ).addClass( "no" + prop );
892 "JS 0": function( elem, prop ) {
893 jQuery( elem ).css( prop, prop === "opacity" ? 0 : "0px" );
896 }, function( fn, f ) {
898 "show": function( elem, prop ) {
899 jQuery( elem ).hide( ).addClass( "wide" + prop );
902 "hide": function( elem, prop ) {
903 jQuery( elem ).addClass( "wide" + prop );
906 "100": function( elem, prop ) {
907 jQuery( elem ).addClass( "wide" + prop );
908 return prop == "opacity" ? 1 : 100;
910 "50": function( elem, prop ) {
911 return prop == "opacity" ? 0.50 : 50;
913 "0": function( elem, prop ) {
914 jQuery( elem ).addClass( "noback" );
917 }, function( tn, t ) {
918 test(fn + " to " + tn, function() {
919 var elem = jQuery.makeTest( fn + " to " + tn );
921 var t_w = t( elem, "width" );
922 var f_w = f( elem, "width" );
923 var t_h = t( elem, "height" );
924 var f_h = f( elem, "height" );
925 var t_o = t( elem, "opacity" );
926 var f_o = f( elem, "opacity" );
934 if ( t_h == "show" ) num++;
935 if ( t_w == "show" ) num++;
936 if ( t_w == "hide" || t_w == "show" ) num++;
937 if ( t_h == "hide" || t_h == "show" ) num++;
938 if ( t_o == "hide" || t_o == "show" ) num++;
939 if ( t_w == "hide" ) num++;
940 if ( t_o.constructor == Number ) num += 2;
941 if ( t_w.constructor == Number ) num += 2;
942 if ( t_h.constructor == Number ) num +=2;
947 var anim = { width: t_w, height: t_h, opacity: t_o };
949 elem.animate(anim, 50);
951 jQuery.when( elem ).done(function( elem ) {
955 if ( t_w == "show" ) {
956 equal( elem.style.display, "block", "Showing, display should block: " + elem.style.display );
959 if ( t_w == "hide" || t_w == "show" ) {
960 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 );
963 if ( t_h == "hide" || t_h == "show" ) {
964 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 );
967 var cur_o = jQuery.style(elem, "opacity");
969 if ( f_o !== jQuery.css(elem, "opacity") ) {
970 f_o = f( elem, "opacity" );
973 // The only time an _empty_string_ will be matched is in IE
974 // otherwise, the correct values will be tested as usual
979 if ( cur_o === "" ) {
983 if ( t_o == "hide" || t_o == "show" ) {
984 equal( cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o );
987 if ( t_w == "hide" ) {
988 equal( elem.style.display, "none", "Hiding, display should be none: " + elem.style.display );
991 if ( t_o.constructor == Number ) {
992 equal( cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o );
994 ok( jQuery.css(elem, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o );
997 if ( t_w.constructor == Number ) {
998 equal( elem.style.width, t_w + "px", "Final width should be " + t_w + ": " + elem.style.width );
1000 var cur_w = jQuery.css( elem,"width" );
1002 ok( elem.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w );
1005 if ( t_h.constructor == Number ) {
1006 equal( elem.style.height, t_h + "px", "Final height should be " + t_h + ": " + elem.style.height );
1008 var cur_h = jQuery.css( elem,"height" );
1010 ok( elem.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w );
1013 if ( t_h == "show" ) {
1014 var old_h = jQuery.css( elem, "height" );
1015 jQuery( elem ).append("<br/>Some more text<br/>and some more...");
1017 if ( /Auto/.test( fn ) ) {
1018 notEqual( jQuery.css( elem, "height" ), old_h, "Make sure height is auto." );
1020 equal( jQuery.css( elem, "height" ), old_h, "Make sure height is not auto." );
1024 // manually remove generated element
1025 jQuery( elem ).remove();
1033 jQuery.fn.saveState = function( hiddenOverflow ) {
1034 var check = ["opacity", "height", "width", "display", "overflow"];
1035 expect(check.length);
1038 return this.each(function(){
1041 jQuery.each(check, function( i, c ) {
1042 self.save[ c ] = c === "overflow" && hiddenOverflow ? "hidden" : self.style[ c ] || jQuery.css( self, c );
1047 jQuery.checkState = function() {
1049 jQuery.each(this.save, function( c, v ) {
1050 var cur = self.style[ c ] || jQuery.css( self, c );
1051 equal( cur, v, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")");
1054 // manually clean data on modified element
1055 jQuery.removeData( this, "olddisplay", true );
1061 test("Chain fadeOut fadeIn", function() {
1062 jQuery("#fadein div").saveState().fadeOut("fast").fadeIn("fast", jQuery.checkState );
1064 test("Chain fadeIn fadeOut", function() {
1065 jQuery("#fadeout div").saveState().fadeIn("fast").fadeOut("fast", jQuery.checkState );
1068 test("Chain hide show", function() {
1069 jQuery("#show div").saveState( jQuery.support.shrinkWrapBlocks ).hide("fast").show("fast", jQuery.checkState );
1071 test("Chain show hide", function() {
1072 jQuery("#hide div").saveState( jQuery.support.shrinkWrapBlocks ).show("fast").hide("fast", jQuery.checkState );
1074 test("Chain show hide with easing and callback", function() {
1075 jQuery("#hide div").saveState().show("fast").hide("fast","linear", jQuery.checkState );
1078 test("Chain toggle in", function() {
1079 jQuery("#togglein div").saveState( jQuery.support.shrinkWrapBlocks ).toggle("fast").toggle("fast", jQuery.checkState );
1081 test("Chain toggle out", function() {
1082 jQuery("#toggleout div").saveState( jQuery.support.shrinkWrapBlocks ).toggle("fast").toggle("fast", jQuery.checkState );
1084 test("Chain toggle out with easing and callback", function() {
1085 jQuery("#toggleout div").saveState( jQuery.support.shrinkWrapBlocks ).toggle("fast").toggle("fast","linear", jQuery.checkState );
1087 test("Chain slideDown slideUp", function() {
1088 jQuery("#slidedown div").saveState( jQuery.support.shrinkWrapBlocks ).slideDown("fast").slideUp("fast", jQuery.checkState );
1090 test("Chain slideUp slideDown", function() {
1091 jQuery("#slideup div").saveState( jQuery.support.shrinkWrapBlocks ).slideUp("fast").slideDown("fast", jQuery.checkState );
1093 test("Chain slideUp slideDown with easing and callback", function() {
1094 jQuery("#slideup div").saveState( jQuery.support.shrinkWrapBlocks ).slideUp("fast").slideDown("fast","linear", jQuery.checkState );
1097 test("Chain slideToggle in", function() {
1098 jQuery("#slidetogglein div").saveState( jQuery.support.shrinkWrapBlocks ).slideToggle("fast").slideToggle("fast", jQuery.checkState );
1100 test("Chain slideToggle out", function() {
1101 jQuery("#slidetoggleout div").saveState( jQuery.support.shrinkWrapBlocks ).slideToggle("fast").slideToggle("fast", jQuery.checkState );
1104 test("Chain fadeToggle in", function() {
1105 jQuery("#fadetogglein div").saveState().fadeToggle("fast").fadeToggle("fast", jQuery.checkState );
1107 test("Chain fadeToggle out", function() {
1108 jQuery("#fadetoggleout div").saveState().fadeToggle("fast").fadeToggle("fast", jQuery.checkState );
1111 test("Chain fadeTo 0.5 1.0 with easing and callback)", function() {
1112 jQuery("#fadeto div").saveState().fadeTo("fast",0.5).fadeTo("fast",1.0,"linear", jQuery.checkState );
1115 jQuery.makeTest = function( text ){
1116 var elem = jQuery("<div></div>")
1117 .attr( "id", "test" + jQuery.makeTest.id++ )
1122 .appendTo("#fx-tests")
1128 jQuery.makeTest.id = 1;
1130 test("jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function () {
1134 var $checkedtest = jQuery("#checkedtest");
1135 // IE6 was clearing "checked" in jQuery(elem).show("fast");
1136 $checkedtest.hide().show("fast", function() {
1137 ok( !! jQuery(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
1138 ok( ! jQuery(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
1139 ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
1140 ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
1146 "slideToggle": function( $elem ) {
1147 return $elem.height();
1149 "fadeToggle": function( $elem ) {
1150 return $elem.css("opacity");
1152 "toggle": function( $elem ) {
1153 return $elem.width();
1156 function( method, defProp ) {
1157 test( method + "().stop()." + method + "()", function() {
1160 var animTime = 2000;
1162 jQuery.each([ "in", "out" ], function( i, type ) {
1163 var $elem = jQuery( "#" + method.toLowerCase() + type ),
1164 startVal = defProp( $elem );
1166 $elem[ method ]( animTime );
1169 setTimeout( function() {
1172 notEqual( defProp( $elem ), startVal, ".stop() is called about halfway through animation." );
1174 $elem[ method ](animTime, function() {
1175 equal( defProp( $elem ), startVal, "After doing .stop() halfway through hide, check that state has been saved for returning to original property value." );
1177 // Start from hidden position to show this time
1178 $elem.hide()[ method ]( animTime );
1179 setTimeout( function() {
1182 notEqual( defProp( $elem ), startVal, ".stop() is called about halfway through animation." );
1184 $elem[ method ](animTime, function() {
1185 equal( defProp( $elem ), startVal, "After doing .stop() halfway through show, check that state has been saved for returning to original property value." );
1187 // Remove olddisplay data from .hide() call
1188 jQuery.removeData( this, "olddisplay", true );
1198 test("animate with per-property easing", function(){
1203 var data = { a:0, b:0, c:0 },
1204 _test1_called = false,
1205 _test2_called = false,
1206 _default_test_called = false,
1208 a: [ 100, "_test1" ],
1209 b: [ 100, "_test2" ],
1213 jQuery.easing["_test1"] = function(p) {
1214 _test1_called = true;
1218 jQuery.easing["_test2"] = function(p) {
1219 _test2_called = true;
1223 jQuery.easing["_default_test"] = function(p) {
1224 _default_test_called = true;
1228 jQuery(data).animate( props, 400, "_default_test", function(){
1231 ok( _test1_called, "Easing function (_test1) called" );
1232 ok( _test2_called, "Easing function (_test2) called" );
1233 ok( _default_test_called, "Easing function (_default) called" );
1234 equal( props.a[ 1 ], "_test1", "animate does not change original props (per-property easing would be lost)");
1235 equal( props.b[ 1 ], "_test2", "animate does not change original props (per-property easing would be lost)");
1240 test("hide hidden elements (bug #7141)", function() {
1244 var div = jQuery("<div style='display:none'></div>").appendTo("#qunit-fixture");
1245 equal( div.css("display"), "none", "Element is hidden by default" );
1247 ok( !jQuery._data(div, "olddisplay"), "olddisplay is undefined after hiding an already-hidden element" );
1249 equal( div.css("display"), "block", "Show a double-hidden element" );
1254 test("hide hidden elements, with animation (bug #7141)", function() {
1259 var div = jQuery("<div style='display:none'></div>").appendTo("#qunit-fixture");
1260 equal( div.css("display"), "none", "Element is hidden by default" );
1261 div.hide(1, function () {
1262 ok( !jQuery._data(div, "olddisplay"), "olddisplay is undefined after hiding an already-hidden element" );
1263 div.show(1, function () {
1264 equal( div.css("display"), "block", "Show a double-hidden element" );
1270 test("animate unit-less properties (#4966)", 2, function() {
1272 var div = jQuery( "<div style='z-index: 0; position: absolute;'></div>" ).appendTo( "#qunit-fixture" );
1273 equal( div.css( "z-index" ), "0", "z-index is 0" );
1274 div.animate({ zIndex: 2 }, function() {
1275 equal( div.css( "z-index" ), "2", "z-index is 2" );
1280 test( "animate properties missing px w/ opacity as last (#9074)", 2, function() {
1283 var div = jQuery( "<div style='position: absolute; margin-left: 0; left: 0px;'></div>" )
1284 .appendTo( "#qunit-fixture" );
1285 function cssInt( prop ) {
1286 return parseInt( div.css( prop ), 10 );
1288 equal( cssInt( "marginLeft" ), 0, "Margin left is 0" );
1289 equal( cssInt( "left" ), 0, "Left is 0" );
1295 setTimeout(function() {
1296 var ml = cssInt( "marginLeft" ),
1297 l = cssInt( "left" );
1298 notEqual( ml, 0, "Margin left is not 0 after partial animate" );
1299 notEqual( ml, 200, "Margin left is not 200 after partial animate" );
1300 notEqual( l, 0, "Left is not 0 after partial animate" );
1301 notEqual( l, 200, "Left is not 200 after partial animate" );
1302 div.stop().remove();
1307 test("callbacks should fire in correct order (#9100)", function() {
1311 $lis = jQuery("<p data-operation='*2'></p><p data-operation='^2'></p>").appendTo("#qunit-fixture")
1312 // The test will always pass if no properties are animated or if the duration is 0
1313 .animate({fontSize: 12}, 13, function() {
1314 a *= jQuery(this).data("operation") === "*2" ? 2 : a;
1317 equal( a, 4, "test value has been *2 and _then_ ^2");
1323 asyncTest( "callbacks that throw exceptions will be removed (#5684)", function() {
1326 var foo = jQuery( "#foo" );
1328 function testException() {
1331 foo.animate({ height: 1 }, 1, function() {
1332 throw new testException;
1335 // this test thoroughly abuses undocumented methods - please feel free to update
1336 // with any changes internally to these functions.
1338 // make sure that the standard timer loop will NOT run.
1341 setTimeout(function() {
1343 // the first call to fx.tick should raise the callback exception
1344 raises( jQuery.fx.tick, testException, "Exception was thrown" );
1346 // the second call shouldn't
1349 ok( true, "Test completed without throwing a second exception" );
1355 test("animate will scale margin properties individually", function() {
1359 var foo = jQuery( "#foo" ).css({
1364 ok( foo.css( "marginLeft" ) !== foo.css( "marginRight" ), "Sanity Check" );
1370 ok( foo.css( "marginLeft") !== foo.css( "marginRight" ), "The margin properties are different");
1372 // clean up for next test