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" );
190 test( "show() resolves correct default display, detached nodes (#10006)", function(){
191 // Tests originally contributed by Orkel in
192 // https://github.com/jquery/jquery/pull/458
197 div = jQuery("<div class='hidden'>");
198 div.show().appendTo("#qunit-fixture");
199 equal( div.css("display"), "block", "Make sure a detached, pre-hidden( through stylesheets ) div is visible." );
201 div = jQuery("<div style='display: none'>");
202 div.show().appendTo("#qunit-fixture");
203 equal( div.css("display"), "block", "Make sure a detached, pre-hidden( through inline style ) div is visible." );
205 span = jQuery("<span class='hidden'/>");
206 span.show().appendTo("#qunit-fixture");
207 equal( span.css("display"), "inline", "Make sure a detached, pre-hidden( through stylesheets ) span has default display." );
209 span = jQuery("<span style='display: inline'/>");
210 span.show().appendTo("#qunit-fixture");
211 equal( span.css("display"), "inline", "Make sure a detached, pre-hidden( through inline style ) span has default display." );
213 div = jQuery("<div><div class='hidden'></div></div>").children("div");
214 div.show().appendTo("#qunit-fixture");
215 equal( div.css("display"), "block", "Make sure a detached, pre-hidden( through stylesheets ) div inside another visible div is visible." );
217 div = jQuery("<div><div style='display: none'></div></div>").children("div");
218 div.show().appendTo("#qunit-fixture");
219 equal( div.css("display"), "block", "Make sure a detached, pre-hidden( through inline style ) div inside another visible div is visible." );
221 div = jQuery("div.hidden");
223 equal( div.css("display"), "block", "Make sure a detached( through detach() ), pre-hidden div is visible." );
226 span = jQuery("<span>");
227 span.appendTo("#qunit-fixture").detach().show().appendTo("#qunit-fixture" );
228 equal( span.css("display"), "inline", "Make sure a detached( through detach() ), pre-hidden span has default display." );
231 div = jQuery("<div>");
232 div.show().appendTo("#qunit-fixture");
233 ok( !!div.get( 0 ).style.display, "Make sure not hidden div has a inline style." );
235 div = jQuery( document.createElement("div") );
236 div.show().appendTo("#qunit-fixture");
237 equal( div.css("display"), "block", "Make sure a pre-created element has default display." );
239 div = jQuery("<div style='display: inline'/>");
240 div.show().appendTo("#qunit-fixture");
241 equal( div.css("display"), "inline", "Make sure that element has same display when it was created." );
245 test("animate(Hash, Object, Function)", function() {
248 var hash = {opacity: "show"};
249 var hashCopy = jQuery.extend({}, hash);
250 jQuery("#foo").animate(hash, 0, function() {
251 equal( hash.opacity, hashCopy.opacity, "Check if animate changed the hash parameter" );
256 test("animate negative height", function() {
259 jQuery("#foo").animate({ height: -100 }, 100, function() {
260 equal( this.offsetHeight, 0, "Verify height." );
265 test("animate block as inline width/height", function() {
268 var span = jQuery("<span>").css("display", "inline-block").appendTo("body"),
269 expected = span.css("display");
273 if ( jQuery.support.inlineBlockNeedsLayout || expected === "inline-block" ) {
276 jQuery("#foo").css({ display: "inline", width: "", height: "" }).animate({ width: 42, height: 42 }, 100, function() {
277 equal( jQuery(this).css("display"), jQuery.support.inlineBlockNeedsLayout ? "inline" : "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
278 equal( this.offsetWidth, 42, "width was animated" );
279 equal( this.offsetHeight, 42, "height was animated" );
283 // Browser doesn't support inline-block
285 ok( true, "Browser doesn't support inline-block" );
286 ok( true, "Browser doesn't support inline-block" );
287 ok( true, "Browser doesn't support inline-block" );
291 test("animate native 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" ) {
301 jQuery("#foo").css({ display: "", width: "", height: "" })
302 .append("<span>text</span>")
304 .animate({ width: 42, height: 42 }, 100, function() {
305 equal( jQuery(this).css("display"), "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
306 equal( this.offsetWidth, 42, "width was animated" );
307 equal( this.offsetHeight, 42, "height was animated" );
311 // Browser doesn't support inline-block
313 ok( true, "Browser doesn't support inline-block" );
314 ok( true, "Browser doesn't support inline-block" );
315 ok( true, "Browser doesn't support inline-block" );
319 test("animate block width/height", function() {
322 jQuery("#foo").css({ display: "block", width: 20, height: 20 }).animate({ width: 42, height: 42 }, 100, function() {
323 equal( jQuery(this).css("display"), "block", "inline-block was not set on block element when animating width/height" );
324 equal( this.offsetWidth, 42, "width was animated" );
325 equal( this.offsetHeight, 42, "height was animated" );
330 test("animate table width/height", function() {
334 var displayMode = jQuery("#table").css("display") !== "table" ? "block" : "table";
336 jQuery("#table").animate({ width: 42, height: 42 }, 100, function() {
337 equal( jQuery(this).css("display"), displayMode, "display mode is correct" );
342 test("animate table-row width/height", function() {
345 var tr = jQuery("#table")
346 .attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 })
347 .html("<tr style='height:42px;'><td style='padding:0;'><div style='width:20px;height:20px;'></div></td></tr>")
350 // IE<8 uses "block" instead of the correct display type
351 var displayMode = tr.css("display") !== "table-row" ? "block" : "table-row";
353 tr.animate({ width: 10, height: 10 }, 100, function() {
354 equal( jQuery(this).css("display"), displayMode, "display mode is correct" );
355 equal( this.offsetWidth, 20, "width animated to shrink wrap point" );
356 equal( this.offsetHeight, 20, "height animated to shrink wrap point" );
361 test("animate table-cell width/height", function() {
364 var td = jQuery("#table")
365 .attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 })
366 .html("<tr><td style='width:42px;height:42px;padding:0;'><div style='width:20px;height:20px;'></div></td></tr>")
369 // IE<8 uses "block" instead of the correct display type
370 var displayMode = td.css("display") !== "table-cell" ? "block" : "table-cell";
372 td.animate({ width: 10, height: 10 }, 100, function() {
373 equal( jQuery(this).css("display"), displayMode, "display mode is correct" );
374 equal( this.offsetWidth, 20, "width animated to shrink wrap point" );
375 equal( this.offsetHeight, 20, "height animated to shrink wrap point" );
380 test("animate percentage(%) on width/height", function() {
383 var $div = jQuery("<div style='position:absolute;top:-999px;left:-999px;width:60px;height:60px;'><div style='width:50%;height:50%;'></div></div>")
384 .appendTo("#qunit-fixture").children("div");
387 $div.animate({ width: "25%", height: "25%" }, 13, function() {
388 var $this = jQuery(this);
389 equal( $this.width(), 15, "Width was animated to 15px rather than 25px");
390 equal( $this.height(), 15, "Height was animated to 15px rather than 25px");
395 test("animate resets overflow-x and overflow-y when finished", function() {
399 .css({ display: "block", width: 20, height: 20, overflowX: "visible", overflowY: "auto" })
400 .animate({ width: 42, height: 42 }, 100, function() {
401 equal( this.style.overflowX, "visible", "overflow-x is visible" );
402 equal( this.style.overflowY, "auto", "overflow-y is auto" );
407 /* // This test ends up being flaky depending upon the CPU load
408 test("animate option (queue === false)", function () {
414 var $foo = jQuery("#foo");
415 $foo.animate({width:"100px"}, 3000, function () {
416 // should finish after unqueued animation so second
418 deepEqual( order, [ 1, 2 ], "Animations finished in the correct order" );
421 $foo.animate({fontSize:"2em"}, {queue:false, duration:10, complete:function () {
422 // short duration and out of queue so should finish first
428 asyncTest( "animate option { queue: false }", function() {
430 var foo = jQuery( "#foo" );
437 complete: function() {
438 ok( true, "Animation Completed" );
443 equal( foo.queue().length, 0, "Queue is empty" );
446 asyncTest( "animate option { queue: true }", function() {
448 var foo = jQuery( "#foo" );
455 complete: function() {
456 ok( true, "Animation Completed" );
461 notEqual( foo.queue().length, 0, "Default queue is not empty" );
465 asyncTest( "animate option { queue: 'name' }", function() {
467 var foo = jQuery( "#foo" ),
468 origWidth = foo.width(),
471 foo.animate( { width: origWidth + 100 }, {
474 complete: function() {
476 // second callback function
478 equal( foo.width(), origWidth + 100, "Animation ended" );
479 equal( foo.queue("name").length, 1, "Queue length of 'name' queue" );
481 }).queue( "name", function( next ) {
483 // last callback function
484 deepEqual( order, [ 1, 2 ], "Callbacks in expected order" );
488 setTimeout( function() {
490 // this is the first callback function that should be called
492 equal( foo.width(), origWidth, "Animation does not start on its own." );
493 equal( foo.queue("name").length, 2, "Queue length of 'name' queue" );
494 foo.dequeue( "name" );
499 test("animate with no properties", function() {
502 var divs = jQuery("div"), count = 0;
504 divs.animate({}, function(){
508 equal( divs.length, count, "Make sure that callback is called for each element in the set." );
512 var foo = jQuery("#foo");
515 foo.animate({top: 10}, 100, function(){
516 ok( true, "Animation was properly dequeued." );
521 test("animate duration 0", function() {
526 var $elems = jQuery([{ a:0 },{ a:0 }]), counter = 0;
528 equal( jQuery.timers.length, 0, "Make sure no animation was running from another test" );
530 $elems.eq(0).animate( {a:1}, 0, function(){
531 ok( true, "Animate a simple property." );
535 // Failed until [6115]
536 equal( jQuery.timers.length, 0, "Make sure synchronic animations are not left on jQuery.timers" );
538 equal( counter, 1, "One synchronic animations" );
540 $elems.animate( { a:2 }, 0, function(){
541 ok( true, "Animate a second simple property." );
545 equal( counter, 3, "Multiple synchronic animations" );
547 $elems.eq(0).animate( {a:3}, 0, function(){
548 ok( true, "Animate a third simple property." );
551 $elems.eq(1).animate( {a:3}, 200, function(){
553 // Failed until [6115]
554 equal( counter, 5, "One synchronic and one asynchronic" );
558 var $elem = jQuery("<div />");
559 $elem.show(0, function(){
560 ok(true, "Show callback with no duration");
562 $elem.hide(0, function(){
563 ok(true, "Hide callback with no duration");
566 // manually clean up detached elements
570 test("animate hyphenated properties", function() {
575 .css("font-size", 10)
576 .animate({"font-size": 20}, 200, function() {
577 equal( this.style.fontSize, "20px", "The font-size property was animated." );
582 test("animate non-element", function() {
586 var obj = { test: 0 };
588 jQuery(obj).animate({test: 200}, 200, function(){
589 equal( obj.test, 200, "The custom property should be modified." );
594 test("stop()", function() {
598 var $foo = jQuery("#foo");
601 $foo.hide().width(200)
602 .animate({ width: "show" }, 1000);
604 setTimeout(function() {
605 var nw = $foo.width();
606 notEqual( nw, w, "An animation occurred " + nw + "px " + w + "px");
610 notEqual( nw, w, "Stop didn't reset the animation " + nw + "px " + w + "px");
611 setTimeout(function() {
613 $foo.removeData(undefined, true);
614 equal( nw, $foo.width(), "The animation didn't continue" );
619 var $one = jQuery("#fadein");
620 var $two = jQuery("#show");
621 $one.fadeTo(100, 0, function() {
624 setTimeout(function() {
625 $two.fadeTo(100, 0, function() {
626 equal( $two.css("opacity"), "0", "Stop does not interfere with animations on other elements (#6641)" );
628 $one.add( $two ).css("opacity", "");
633 test("stop() - several in queue", function() {
637 var $foo = jQuery("#foo");
639 $foo.hide().width(200).width();
641 $foo.animate({ width: "show" }, 1000);
642 $foo.animate({ width: "hide" }, 1000);
643 $foo.animate({ width: "show" }, 1000);
644 setTimeout(function(){
645 equal( $foo.queue().length, 3, "All 3 still in the queue" );
646 var nw = $foo.width();
647 notEqual( nw, w, "An animation occurred " + nw + "px " + w + "px");
651 notEqual( nw, w, "Stop didn't reset the animation " + nw + "px " + w + "px");
658 test("stop(clearQueue)", function() {
662 var $foo = jQuery("#foo");
664 $foo.hide().width(200).width();
666 $foo.animate({ width: "show" }, 1000);
667 $foo.animate({ width: "hide" }, 1000);
668 $foo.animate({ width: "show" }, 1000);
669 setTimeout(function(){
670 var nw = $foo.width();
671 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
675 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
677 equal( $foo.queue().length, 0, "The animation queue was cleared" );
678 setTimeout(function(){
679 equal( nw, $foo.width(), "The animation didn't continue" );
685 test("stop(clearQueue, gotoEnd)", function() {
689 var $foo = jQuery("#foo");
691 $foo.hide().width(200).width();
693 $foo.animate({ width: "show" }, 1000);
694 $foo.animate({ width: "hide" }, 1000);
695 $foo.animate({ width: "show" }, 1000);
696 $foo.animate({ width: "hide" }, 1000);
697 setTimeout(function(){
698 var nw = $foo.width();
699 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
700 $foo.stop(false, true);
703 // Disabled, being flaky
704 //equal( nw, 1, "Stop() reset the animation" );
706 setTimeout(function(){
707 // Disabled, being flaky
708 //equal( $foo.queue().length, 2, "The next animation continued" );
715 asyncTest( "stop( queue, ..., ... ) - Stop single queues", function() {
717 var foo = jQuery( "#foo" ),
720 foo.width( 200 ).height( 200 );
725 complete: function() {
726 equal( foo.width(), 400, "Animation completed for standard queue" );
727 equal( foo.height(), saved, "Height was not changed after the second stop");
737 }).dequeue( "height" ).stop( "height", false, true );
739 equal( foo.height(), 400, "Height was stopped with gotoEnd" );
746 }).dequeue( "height" ).stop( "height", false, false );
747 saved = foo.height();
750 test("toggle()", function() {
752 var x = jQuery("#foo");
753 ok( x.is(":visible"), "is visible" );
755 ok( x.is(":hidden"), "is hidden" );
757 ok( x.is(":visible"), "is visible again" );
760 ok( x.is(":visible"), "is visible" );
762 ok( x.is(":hidden"), "is hidden" );
764 ok( x.is(":visible"), "is visible again" );
767 jQuery.checkOverflowDisplay = function(){
768 var o = jQuery.css( this, "overflow" );
770 equal(o, "visible", "Overflow should be visible: " + o);
771 equal(jQuery.css( this, "display" ), "inline", "Display shouldn't be tampered with.");
776 test( "jQuery.fx.prototype.cur()", 6, function() {
777 var div = jQuery( "<div></div>" ).appendTo( "#qunit-fixture" ).css({
779 border: "5px solid black",
781 marginBottom: "-11000px"
785 ( new jQuery.fx( div, {}, "color" ) ).cur(),
786 jQuery.css( div, "color" ),
787 "Return the same value as jQuery.css for complex properties (bug #7912)"
791 ( new jQuery.fx( div, {}, "borderLeftWidth" ) ).cur(),
793 "Return simple values parsed as Float"
796 // backgroundPosition actually returns 0% 0% in most browser
797 // this fakes a "" return
798 jQuery.cssHooks.backgroundPosition = {
800 ok( true, "hook used" );
806 ( new jQuery.fx( div, {}, "backgroundPosition" ) ).cur(),
808 "Return 0 when jQuery.css returns an empty string"
811 delete jQuery.cssHooks.backgroundPosition;
814 ( new jQuery.fx( div, {}, "left" ) ).cur(),
816 "Return 0 when jQuery.css returns 'auto'"
820 ( new jQuery.fx( div, {}, "marginBottom" ) ).cur(),
822 "support negative values < -10000 (bug #7193)"
826 test("JS Overflow and Display", function() {
829 jQuery.makeTest( "JS Overflow and Display" )
830 .addClass("widewidth")
831 .css({ overflow: "visible", display: "inline" })
832 .addClass("widewidth")
833 .text("Some sample text.")
834 .before("text before")
836 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
839 test("CSS Overflow and Display", function() {
842 jQuery.makeTest( "CSS Overflow and Display" )
843 .addClass("overflow inline")
844 .addClass("widewidth")
845 .text("Some sample text.")
846 .before("text before")
848 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
852 "CSS Auto": function( elem, prop ) {
853 jQuery( elem ).addClass( "auto" + prop )
854 .text( "This is a long string of text." );
857 "JS Auto": function( elem, prop ) {
858 jQuery( elem ).css( prop, "" )
859 .text( "This is a long string of text." );
862 "CSS 100": function( elem, prop ) {
863 jQuery( elem ).addClass( "large" + prop );
866 "JS 100": function( elem, prop ) {
867 jQuery( elem ).css( prop, prop === "opacity" ? 1 : "100px" );
868 return prop === "opacity" ? 1 : 100;
870 "CSS 50": function( elem, prop ) {
871 jQuery( elem ).addClass( "med" + prop );
874 "JS 50": function( elem, prop ) {
875 jQuery( elem ).css( prop, prop === "opacity" ? 0.50 : "50px" );
876 return prop === "opacity" ? 0.5 : 50;
878 "CSS 0": function( elem, prop ) {
879 jQuery( elem ).addClass( "no" + prop );
882 "JS 0": function( elem, prop ) {
883 jQuery( elem ).css( prop, prop === "opacity" ? 0 : "0px" );
886 }, function( fn, f ) {
888 "show": function( elem, prop ) {
889 jQuery( elem ).hide( ).addClass( "wide" + prop );
892 "hide": function( elem, prop ) {
893 jQuery( elem ).addClass( "wide" + prop );
896 "100": function( elem, prop ) {
897 jQuery( elem ).addClass( "wide" + prop );
898 return prop == "opacity" ? 1 : 100;
900 "50": function( elem, prop ) {
901 return prop == "opacity" ? 0.50 : 50;
903 "0": function( elem, prop ) {
904 jQuery( elem ).addClass( "noback" );
907 }, function( tn, t ) {
908 test(fn + " to " + tn, function() {
909 var elem = jQuery.makeTest( fn + " to " + tn );
911 var t_w = t( elem, "width" );
912 var f_w = f( elem, "width" );
913 var t_h = t( elem, "height" );
914 var f_h = f( elem, "height" );
915 var t_o = t( elem, "opacity" );
916 var f_o = f( elem, "opacity" );
924 if ( t_h == "show" ) num++;
925 if ( t_w == "show" ) num++;
926 if ( t_w == "hide" || t_w == "show" ) num++;
927 if ( t_h == "hide" || t_h == "show" ) num++;
928 if ( t_o == "hide" || t_o == "show" ) num++;
929 if ( t_w == "hide" ) num++;
930 if ( t_o.constructor == Number ) num += 2;
931 if ( t_w.constructor == Number ) num += 2;
932 if ( t_h.constructor == Number ) num +=2;
937 var anim = { width: t_w, height: t_h, opacity: t_o };
939 elem.animate(anim, 50);
941 jQuery.when( elem ).done(function( elem ) {
945 if ( t_w == "show" ) {
946 equal( elem.style.display, "block", "Showing, display should block: " + elem.style.display );
949 if ( t_w == "hide" || t_w == "show" ) {
950 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 );
953 if ( t_h == "hide" || t_h == "show" ) {
954 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 );
957 var cur_o = jQuery.style(elem, "opacity");
959 if ( f_o !== jQuery.css(elem, "opacity") ) {
960 f_o = f( elem, "opacity" );
963 // The only time an _empty_string_ will be matched is in IE
964 // otherwise, the correct values will be tested as usual
969 if ( cur_o === "" ) {
973 if ( t_o == "hide" || t_o == "show" ) {
974 equal( cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o );
977 if ( t_w == "hide" ) {
978 equal( elem.style.display, "none", "Hiding, display should be none: " + elem.style.display );
981 if ( t_o.constructor == Number ) {
982 equal( cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o );
984 ok( jQuery.css(elem, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o );
987 if ( t_w.constructor == Number ) {
988 equal( elem.style.width, t_w + "px", "Final width should be " + t_w + ": " + elem.style.width );
990 var cur_w = jQuery.css( elem,"width" );
992 ok( elem.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w );
995 if ( t_h.constructor == Number ) {
996 equal( elem.style.height, t_h + "px", "Final height should be " + t_h + ": " + elem.style.height );
998 var cur_h = jQuery.css( elem,"height" );
1000 ok( elem.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w );
1003 if ( t_h == "show" ) {
1004 var old_h = jQuery.css( elem, "height" );
1005 jQuery( elem ).append("<br/>Some more text<br/>and some more...");
1007 if ( /Auto/.test( fn ) ) {
1008 notEqual( jQuery.css( elem, "height" ), old_h, "Make sure height is auto." );
1010 equal( jQuery.css( elem, "height" ), old_h, "Make sure height is not auto." );
1014 // manually remove generated element
1015 jQuery( elem ).remove();
1023 jQuery.fn.saveState = function( hiddenOverflow ) {
1024 var check = ["opacity", "height", "width", "display", "overflow"];
1025 expect(check.length);
1028 return this.each(function(){
1031 jQuery.each(check, function( i, c ) {
1032 self.save[ c ] = c === "overflow" && hiddenOverflow ? "hidden" : self.style[ c ] || jQuery.css( self, c );
1037 jQuery.checkState = function() {
1039 jQuery.each(this.save, function( c, v ) {
1040 var cur = self.style[ c ] || jQuery.css( self, c );
1041 equal( cur, v, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")");
1044 // manually clean data on modified element
1045 jQuery.removeData( this, "olddisplay", true );
1051 test("Chain fadeOut fadeIn", function() {
1052 jQuery("#fadein div").saveState().fadeOut("fast").fadeIn("fast", jQuery.checkState );
1054 test("Chain fadeIn fadeOut", function() {
1055 jQuery("#fadeout div").saveState().fadeIn("fast").fadeOut("fast", jQuery.checkState );
1058 test("Chain hide show", function() {
1059 jQuery("#show div").saveState( jQuery.support.shrinkWrapBlocks ).hide("fast").show("fast", jQuery.checkState );
1061 test("Chain show hide", function() {
1062 jQuery("#hide div").saveState( jQuery.support.shrinkWrapBlocks ).show("fast").hide("fast", jQuery.checkState );
1064 test("Chain show hide with easing and callback", function() {
1065 jQuery("#hide div").saveState().show("fast").hide("fast","linear", jQuery.checkState );
1068 test("Chain toggle in", function() {
1069 jQuery("#togglein div").saveState( jQuery.support.shrinkWrapBlocks ).toggle("fast").toggle("fast", jQuery.checkState );
1071 test("Chain toggle out", function() {
1072 jQuery("#toggleout div").saveState( jQuery.support.shrinkWrapBlocks ).toggle("fast").toggle("fast", jQuery.checkState );
1074 test("Chain toggle out with easing and callback", function() {
1075 jQuery("#toggleout div").saveState( jQuery.support.shrinkWrapBlocks ).toggle("fast").toggle("fast","linear", jQuery.checkState );
1077 test("Chain slideDown slideUp", function() {
1078 jQuery("#slidedown div").saveState( jQuery.support.shrinkWrapBlocks ).slideDown("fast").slideUp("fast", jQuery.checkState );
1080 test("Chain slideUp slideDown", function() {
1081 jQuery("#slideup div").saveState( jQuery.support.shrinkWrapBlocks ).slideUp("fast").slideDown("fast", jQuery.checkState );
1083 test("Chain slideUp slideDown with easing and callback", function() {
1084 jQuery("#slideup div").saveState( jQuery.support.shrinkWrapBlocks ).slideUp("fast").slideDown("fast","linear", jQuery.checkState );
1087 test("Chain slideToggle in", function() {
1088 jQuery("#slidetogglein div").saveState( jQuery.support.shrinkWrapBlocks ).slideToggle("fast").slideToggle("fast", jQuery.checkState );
1090 test("Chain slideToggle out", function() {
1091 jQuery("#slidetoggleout div").saveState( jQuery.support.shrinkWrapBlocks ).slideToggle("fast").slideToggle("fast", jQuery.checkState );
1094 test("Chain fadeToggle in", function() {
1095 jQuery("#fadetogglein div").saveState().fadeToggle("fast").fadeToggle("fast", jQuery.checkState );
1097 test("Chain fadeToggle out", function() {
1098 jQuery("#fadetoggleout div").saveState().fadeToggle("fast").fadeToggle("fast", jQuery.checkState );
1101 test("Chain fadeTo 0.5 1.0 with easing and callback)", function() {
1102 jQuery("#fadeto div").saveState().fadeTo("fast",0.5).fadeTo("fast",1.0,"linear", jQuery.checkState );
1105 jQuery.makeTest = function( text ){
1106 var elem = jQuery("<div></div>")
1107 .attr( "id", "test" + jQuery.makeTest.id++ )
1112 .appendTo("#fx-tests")
1118 jQuery.makeTest.id = 1;
1120 test("jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function () {
1124 var $checkedtest = jQuery("#checkedtest");
1125 // IE6 was clearing "checked" in jQuery(elem).show("fast");
1126 $checkedtest.hide().show("fast", function() {
1127 ok( !! jQuery(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
1128 ok( ! jQuery(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
1129 ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
1130 ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
1136 "slideToggle": function( $elem ) {
1137 return $elem.height();
1139 "fadeToggle": function( $elem ) {
1140 return $elem.css("opacity");
1142 "toggle": function( $elem ) {
1143 return $elem.width();
1146 function( method, defProp ) {
1147 test( method + "().stop()." + method + "()", function() {
1150 jQuery.each([ "in", "out" ], function( i, type ) {
1151 var $elem = jQuery( "#" + method.toLowerCase() + type ),
1152 startVal = defProp( $elem );
1154 $elem[ method ]("fast");
1157 setTimeout( function() {
1160 notEqual( defProp( $elem ), startVal, ".stop() is called about halfway through animation." );
1162 $elem[ method ]("fast", function() {
1163 equal( defProp( jQuery(this) ), startVal, "After doing .stop() halfway, check that state has been saved for returning to original property value." );
1171 test("animate with per-property easing", function(){
1176 var data = { a:0, b:0, c:0 },
1177 _test1_called = false,
1178 _test2_called = false,
1179 _default_test_called = false,
1181 a: [ 100, "_test1" ],
1182 b: [ 100, "_test2" ],
1186 jQuery.easing["_test1"] = function(p) {
1187 _test1_called = true;
1191 jQuery.easing["_test2"] = function(p) {
1192 _test2_called = true;
1196 jQuery.easing["_default_test"] = function(p) {
1197 _default_test_called = true;
1201 jQuery(data).animate( props, 400, "_default_test", function(){
1204 ok( _test1_called, "Easing function (_test1) called" );
1205 ok( _test2_called, "Easing function (_test2) called" );
1206 ok( _default_test_called, "Easing function (_default) called" );
1207 equal( props.a[ 1 ], "_test1", "animate does not change original props (per-property easing would be lost)");
1208 equal( props.b[ 1 ], "_test2", "animate does not change original props (per-property easing would be lost)");
1213 test("hide hidden elements (bug #7141)", function() {
1217 var div = jQuery("<div style='display:none'></div>").appendTo("#qunit-fixture");
1218 equal( div.css("display"), "none", "Element is hidden by default" );
1220 ok( !jQuery._data(div, "olddisplay"), "olddisplay is undefined after hiding an already-hidden element" );
1222 equal( div.css("display"), "block", "Show a double-hidden element" );
1227 test("hide hidden elements, with animation (bug #7141)", function() {
1232 var div = jQuery("<div style='display:none'></div>").appendTo("#qunit-fixture");
1233 equal( div.css("display"), "none", "Element is hidden by default" );
1234 div.hide(1, function () {
1235 ok( !jQuery._data(div, "olddisplay"), "olddisplay is undefined after hiding an already-hidden element" );
1236 div.show(1, function () {
1237 equal( div.css("display"), "block", "Show a double-hidden element" );
1243 test("animate unit-less properties (#4966)", 2, function() {
1245 var div = jQuery( "<div style='z-index: 0; position: absolute;'></div>" ).appendTo( "#qunit-fixture" );
1246 equal( div.css( "z-index" ), "0", "z-index is 0" );
1247 div.animate({ zIndex: 2 }, function() {
1248 equal( div.css( "z-index" ), "2", "z-index is 2" );
1253 test( "animate properties missing px w/ opacity as last (#9074)", 2, function() {
1256 var div = jQuery( "<div style='position: absolute; margin-left: 0; left: 0px;'></div>" )
1257 .appendTo( "#qunit-fixture" );
1258 function cssInt( prop ) {
1259 return parseInt( div.css( prop ), 10 );
1261 equal( cssInt( "marginLeft" ), 0, "Margin left is 0" );
1262 equal( cssInt( "left" ), 0, "Left is 0" );
1268 setTimeout(function() {
1269 var ml = cssInt( "marginLeft" ),
1270 l = cssInt( "left" );
1271 notEqual( ml, 0, "Margin left is not 0 after partial animate" );
1272 notEqual( ml, 200, "Margin left is not 200 after partial animate" );
1273 notEqual( l, 0, "Left is not 0 after partial animate" );
1274 notEqual( l, 200, "Left is not 200 after partial animate" );
1275 div.stop().remove();
1280 test("callbacks should fire in correct order (#9100)", function() {
1284 $lis = jQuery("<p data-operation='*2'></p><p data-operation='^2'></p>").appendTo("#qunit-fixture")
1285 // The test will always pass if no properties are animated or if the duration is 0
1286 .animate({fontSize: 12}, 13, function() {
1287 a *= jQuery(this).data("operation") === "*2" ? 2 : a;
1290 equal( a, 4, "test value has been *2 and _then_ ^2");
1296 asyncTest( "callbacks that throw exceptions will be removed (#5684)", function() {
1299 var foo = jQuery( "#foo" );
1301 function testException() {
1304 foo.animate({ height: 1 }, 1, function() {
1305 throw new testException;
1308 // this test thoroughly abuses undocumented methods - please feel free to update
1309 // with any changes internally to these functions.
1311 // make sure that the standard timer loop will NOT run.
1314 setTimeout(function() {
1316 // the first call to fx.tick should raise the callback exception
1317 raises( jQuery.fx.tick, testException, "Exception was thrown" );
1319 // the second call shouldn't
1322 ok( true, "Test completed without throwing a second exception" );