3 test("sanity check", function() {
5 ok( jQuery("#dl:visible, #main:visible, #foo:visible").length === 3, "QUnit state is correct for testing effects" );
8 test("show()", function() {
11 var hiddendiv = jQuery("div.hidden");
13 equal(jQuery.css( hiddendiv[0], "display"), "none", "hiddendiv is display: none");
15 hiddendiv.css("display", "block");
16 equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block");
19 equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block");
21 hiddendiv.css("display","");
23 var pass = true, div = jQuery("#main div");
24 div.show().each(function(){
25 if ( this.style.display == "none" ) pass = false;
31 "undefined speed": undefined,
32 "empty string speed": "",
36 jQuery.each(speeds, function(name, speed) {
38 div.hide().show(speed).each(function() {
39 if ( this.style.display == "none" ) pass = false;
41 ok( pass, "Show with " + name);
45 jQuery.each(speeds, function(name, speed) {
47 div.hide().show(speed, function() {
50 ok( pass, "Show with " + name + " does not call animate callback" );
53 // #show-tests * is set display: none in CSS
54 jQuery("#main").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>');
56 var old = jQuery("#test-table").show().css("display") !== "table";
57 jQuery("#test-table").remove();
66 "table" : old ? "block" : "table",
67 "thead" : old ? "block" : "table-header-group",
68 "tbody" : old ? "block" : "table-row-group",
69 "tr" : old ? "block" : "table-row",
70 "th" : old ? "block" : "table-cell",
71 "td" : old ? "block" : "table-cell",
73 "li" : old ? "block" : "list-item"
76 jQuery.each(test, function(selector, expected) {
77 var elem = jQuery(selector, "#show-tests").show();
78 equals( elem.css("display"), expected, "Show using correct display type for " + selector );
82 test("show(Number) - other displays", function() {
87 // #show-tests * is set display: none in CSS
88 jQuery("#main").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>');
90 var old = jQuery("#test-table").show().css("display") !== "table",
92 jQuery("#test-table").remove();
101 "table" : old ? "block" : "table",
102 "thead" : old ? "block" : "table-header-group",
103 "tbody" : old ? "block" : "table-row-group",
104 "tr" : old ? "block" : "table-row",
105 "th" : old ? "block" : "table-cell",
106 "td" : old ? "block" : "table-cell",
108 "li" : old ? "block" : "list-item"
111 jQuery.each(test, function(selector, expected) {
112 var elem = jQuery(selector, "#show-tests").show(1, function() {
113 equals( elem.css("display"), expected, "Show using correct display type for " + selector );
114 if ( ++num === 15 ) {
121 test("animate(Hash, Object, Function)", function() {
124 var hash = {opacity: 'show'};
125 var hashCopy = jQuery.extend({}, hash);
126 jQuery('#foo').animate(hash, 0, function() {
127 equals( hash.opacity, hashCopy.opacity, 'Check if animate changed the hash parameter' );
132 test("animate negative height", function() {
135 jQuery("#foo").animate({ height: -100 }, 100, function() {
136 equals( this.offsetHeight, 0, "Verify height." );
141 test("animate block as inline width/height", function() {
144 var span = jQuery("<span>").css("display", "inline-block").appendTo("body"),
145 expected = span.css("display");
149 if ( jQuery.support.inlineBlockNeedsLayout || expected === "inline-block" ) {
152 jQuery("#foo").css({ display: "inline", width: '', height: '' }).animate({ width: 42, height: 42 }, 100, function() {
153 equals( jQuery(this).css("display"), jQuery.support.inlineBlockNeedsLayout ? "inline" : "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
154 equals( this.offsetWidth, 42, "width was animated" );
155 equals( this.offsetHeight, 42, "height was animated" );
159 // Browser doesn't support inline-block
161 ok( true, "Browser doesn't support inline-block" );
162 ok( true, "Browser doesn't support inline-block" );
163 ok( true, "Browser doesn't support inline-block" );
167 test("animate native inline width/height", function() {
170 var span = jQuery("<span>").css("display", "inline-block").appendTo("body"),
171 expected = span.css("display");
175 if ( jQuery.support.inlineBlockNeedsLayout || expected === "inline-block" ) {
177 jQuery("#foo").css({ display: "", width: '', height: '' })
178 .append('<span>text</span>')
180 .animate({ width: 42, height: 42 }, 100, function() {
181 equals( jQuery(this).css("display"), "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
182 equals( this.offsetWidth, 42, "width was animated" );
183 equals( this.offsetHeight, 42, "height was animated" );
187 // Browser doesn't support inline-block
189 ok( true, "Browser doesn't support inline-block" );
190 ok( true, "Browser doesn't support inline-block" );
191 ok( true, "Browser doesn't support inline-block" );
195 test("animate block width/height", function() {
198 jQuery("#foo").css({ display: "block", width: 20, height: 20 }).animate({ width: 42, height: 42 }, 100, function() {
199 equals( jQuery(this).css("display"), "block", "inline-block was not set on block element when animating width/height" );
200 equals( this.offsetWidth, 42, "width was animated" );
201 equals( this.offsetHeight, 42, "height was animated" );
206 test("animate table width/height", function() {
210 var displayMode = jQuery("#table").css("display") !== "table" ? "block" : "table";
212 jQuery("#table").animate({ width: 42, height: 42 }, 100, function() {
213 equals( jQuery(this).css("display"), displayMode, "display mode is correct" );
218 test("animate table-row width/height", function() {
221 var tr = jQuery("#table")
222 .attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 })
223 .html("<tr style='height:42px;'><td style='padding:0;'><div style='width:20px;height:20px;'></div></td></tr>")
226 // IE<8 uses “block” instead of the correct display type
227 var displayMode = tr.css("display") !== "table-row" ? "block" : "table-row";
229 tr.animate({ width: 10, height: 10 }, 100, function() {
230 equals( jQuery(this).css("display"), displayMode, "display mode is correct" );
231 equals( this.offsetWidth, 20, "width animated to shrink wrap point" );
232 equals( this.offsetHeight, 20, "height animated to shrink wrap point" );
237 test("animate table-cell width/height", function() {
240 var td = jQuery("#table")
241 .attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 })
242 .html("<tr><td style='width:42px;height:42px;padding:0;'><div style='width:20px;height:20px;'></div></td></tr>")
245 // IE<8 uses “block” instead of the correct display type
246 var displayMode = td.css("display") !== "table-cell" ? "block" : "table-cell";
248 td.animate({ width: 10, height: 10 }, 100, function() {
249 equals( jQuery(this).css("display"), displayMode, "display mode is correct" );
250 equals( this.offsetWidth, 20, "width animated to shrink wrap point" );
251 equals( this.offsetHeight, 20, "height animated to shrink wrap point" );
256 test("animate resets overflow-x and overflow-y when finished", function() {
260 .css({ display: "block", width: 20, height: 20, overflowX: "visible", overflowY: "auto" })
261 .animate({ width: 42, height: 42 }, 100, function() {
262 equals( this.style.overflowX, "visible", "overflow-x is visible" );
263 equals( this.style.overflowY, "auto", "overflow-y is auto" );
268 /* // This test ends up being flaky depending upon the CPU load
269 test("animate option (queue === false)", function () {
275 var $foo = jQuery("#foo");
276 $foo.animate({width:'100px'}, 3000, function () {
277 // should finish after unqueued animation so second
279 same( order, [ 1, 2 ], "Animations finished in the correct order" );
282 $foo.animate({fontSize:'2em'}, {queue:false, duration:10, complete:function () {
283 // short duration and out of queue so should finish first
289 test("animate with no properties", function() {
292 var divs = jQuery("div"), count = 0;
294 divs.animate({}, function(){
298 equals( divs.length, count, "Make sure that callback is called for each element in the set." );
302 var foo = jQuery("#foo");
305 foo.animate({top: 10}, 100, function(){
306 ok( true, "Animation was properly dequeued." );
311 test("animate duration 0", function() {
316 var $elems = jQuery([{ a:0 },{ a:0 }]), counter = 0;
318 equals( jQuery.timers.length, 0, "Make sure no animation was running from another test" );
320 $elems.eq(0).animate( {a:1}, 0, function(){
321 ok( true, "Animate a simple property." );
325 // Failed until [6115]
326 equals( jQuery.timers.length, 0, "Make sure synchronic animations are not left on jQuery.timers" );
328 equals( counter, 1, "One synchronic animations" );
330 $elems.animate( { a:2 }, 0, function(){
331 ok( true, "Animate a second simple property." );
335 equals( counter, 3, "Multiple synchronic animations" );
337 $elems.eq(0).animate( {a:3}, 0, function(){
338 ok( true, "Animate a third simple property." );
341 $elems.eq(1).animate( {a:3}, 200, function(){
343 // Failed until [6115]
344 equals( counter, 5, "One synchronic and one asynchronic" );
348 var $elem = jQuery("<div />");
349 $elem.show(0, function(){
350 ok(true, "Show callback with no duration");
352 $elem.hide(0, function(){
353 ok(true, "Hide callback with no duration");
357 test("animate hyphenated properties", function(){
361 jQuery("#nothiddendiv")
362 .css("font-size", 10)
363 .animate({"font-size": 20}, 200, function(){
364 equals( this.style.fontSize, "20px", "The font-size property was animated." );
369 test("animate non-element", function(){
373 var obj = { test: 0 };
375 jQuery(obj).animate({test: 200}, 200, function(){
376 equals( obj.test, 200, "The custom property should be modified." );
381 test("stop()", function() {
385 var $foo = jQuery("#nothiddendiv");
387 $foo.hide().width(200).width();
389 $foo.animate({ width:'show' }, 1000);
390 setTimeout(function(){
391 var nw = $foo.width();
392 notEqual( nw, w, "An animation occurred " + nw + "px " + w + "px");
396 notEqual( nw, w, "Stop didn't reset the animation " + nw + "px " + w + "px");
397 setTimeout(function(){
398 equals( nw, $foo.width(), "The animation didn't continue" );
404 test("stop() - several in queue", function() {
408 var $foo = jQuery("#nothiddendivchild");
410 $foo.hide().width(200).width();
412 $foo.animate({ width:'show' }, 1000);
413 $foo.animate({ width:'hide' }, 1000);
414 $foo.animate({ width:'show' }, 1000);
415 setTimeout(function(){
416 equals( $foo.queue().length, 3, "All 3 still in the queue" );
417 var nw = $foo.width();
418 notEqual( nw, w, "An animation occurred " + nw + "px " + w + "px");
422 notEqual( nw, w, "Stop didn't reset the animation " + nw + "px " + w + "px");
429 test("stop(clearQueue)", function() {
433 var $foo = jQuery("#nothiddendiv");
435 $foo.hide().width(200).width();
437 $foo.animate({ width:'show' }, 1000);
438 $foo.animate({ width:'hide' }, 1000);
439 $foo.animate({ width:'show' }, 1000);
440 setTimeout(function(){
441 var nw = $foo.width();
442 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
446 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
448 equals( $foo.queue().length, 0, "The animation queue was cleared" );
449 setTimeout(function(){
450 equals( nw, $foo.width(), "The animation didn't continue" );
456 test("stop(clearQueue, gotoEnd)", function() {
460 var $foo = jQuery("#nothiddendivchild");
462 $foo.hide().width(200).width();
464 $foo.animate({ width:'show' }, 1000);
465 $foo.animate({ width:'hide' }, 1000);
466 $foo.animate({ width:'show' }, 1000);
467 $foo.animate({ width:'hide' }, 1000);
468 setTimeout(function(){
469 var nw = $foo.width();
470 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
471 $foo.stop(false, true);
474 // Disabled, being flaky
475 //equals( nw, 1, "Stop() reset the animation" );
477 setTimeout(function(){
478 // Disabled, being flaky
479 //equals( $foo.queue().length, 2, "The next animation continued" );
486 test("toggle()", function() {
488 var x = jQuery("#nothiddendiv");
489 ok( x.is(":visible"), "is visible" );
491 ok( x.is(":hidden"), "is hidden" );
493 ok( x.is(":visible"), "is visible again" );
496 ok( x.is(":visible"), "is visible" );
498 ok( x.is(":hidden"), "is hidden" );
500 ok( x.is(":visible"), "is visible again" );
503 jQuery.checkOverflowDisplay = function(){
504 var o = jQuery.css( this, "overflow" );
506 equals(o, "visible", "Overflow should be visible: " + o);
507 equals(jQuery.css( this, "display" ), "inline", "Display shouldn't be tampered with.");
512 test("JS Overflow and Display", function() {
515 jQuery.makeTest( "JS Overflow and Display" )
516 .addClass("widewidth")
517 .css({ overflow: "visible", display: "inline" })
518 .addClass("widewidth")
519 .text("Some sample text.")
520 .before("text before")
522 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
525 test("CSS Overflow and Display", function() {
528 jQuery.makeTest( "CSS Overflow and Display" )
529 .addClass("overflow inline")
530 .addClass("widewidth")
531 .text("Some sample text.")
532 .before("text before")
534 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
538 "CSS Auto": function(elem,prop){
539 jQuery(elem).addClass("auto" + prop)
540 .text("This is a long string of text.");
543 "JS Auto": function(elem,prop){
544 jQuery(elem).css(prop,"")
545 .text("This is a long string of text.");
548 "CSS 100": function(elem,prop){
549 jQuery(elem).addClass("large" + prop);
552 "JS 100": function(elem,prop){
553 jQuery(elem).css(prop,prop == "opacity" ? 1 : "100px");
554 return prop == "opacity" ? 1 : 100;
556 "CSS 50": function(elem,prop){
557 jQuery(elem).addClass("med" + prop);
560 "JS 50": function(elem,prop){
561 jQuery(elem).css(prop,prop == "opacity" ? 0.50 : "50px");
562 return prop == "opacity" ? 0.5 : 50;
564 "CSS 0": function(elem,prop){
565 jQuery(elem).addClass("no" + prop);
568 "JS 0": function(elem,prop){
569 jQuery(elem).css(prop,prop == "opacity" ? 0 : "0px");
574 "show": function(elem,prop){
575 jQuery(elem).hide().addClass("wide"+prop);
578 "hide": function(elem,prop){
579 jQuery(elem).addClass("wide"+prop);
582 "100": function(elem,prop){
583 jQuery(elem).addClass("wide"+prop);
584 return prop == "opacity" ? 1 : 100;
586 "50": function(elem,prop){
587 return prop == "opacity" ? 0.50 : 50;
589 "0": function(elem,prop){
590 jQuery(elem).addClass("noback");
594 test(fn + " to " + tn, function() {
595 var elem = jQuery.makeTest( fn + " to " + tn );
597 var t_w = t( elem, "width" );
598 var f_w = f( elem, "width" );
599 var t_h = t( elem, "height" );
600 var f_h = f( elem, "height" );
601 var t_o = t( elem, "opacity" );
602 var f_o = f( elem, "opacity" );
606 if ( t_h == "show" ) num++;
607 if ( t_w == "show" ) num++;
608 if ( t_w == "hide"||t_w == "show" ) num++;
609 if ( t_h == "hide"||t_h == "show" ) num++;
610 if ( t_o == "hide"||t_o == "show" ) num++;
611 if ( t_w == "hide" ) num++;
612 if ( t_o.constructor == Number ) num += 2;
613 if ( t_w.constructor == Number ) num += 2;
614 if ( t_h.constructor == Number ) num +=2;
619 var anim = { width: t_w, height: t_h, opacity: t_o };
621 elem.animate(anim, 50, function(){
623 equals( this.style.display, "block", "Showing, display should block: " + this.style.display);
625 if ( t_w == "hide"||t_w == "show" )
626 ok(f_w === "" ? this.style.width === f_w : this.style.width.indexOf(f_w) === 0, "Width must be reset to " + f_w + ": " + this.style.width);
628 if ( t_h == "hide"||t_h == "show" )
629 ok(f_h === "" ? this.style.height === f_h : this.style.height.indexOf(f_h) === 0, "Height must be reset to " + f_h + ": " + this.style.height);
631 var cur_o = jQuery.style(this, "opacity");
633 if ( t_o == "hide" || t_o == "show" )
634 equals(cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o);
637 equals(this.style.display, "none", "Hiding, display should be none: " + this.style.display);
639 if ( t_o.constructor == Number ) {
640 equals(cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o);
642 ok(jQuery.css(this, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o);
645 if ( t_w.constructor == Number ) {
646 equals(this.style.width, t_w + "px", "Final width should be " + t_w + ": " + this.style.width);
648 var cur_w = jQuery.css(this,"width");
650 ok(this.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w);
653 if ( t_h.constructor == Number ) {
654 equals(this.style.height, t_h + "px", "Final height should be " + t_h + ": " + this.style.height);
656 var cur_h = jQuery.css(this,"height");
658 ok(this.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w);
661 if ( t_h == "show" ) {
662 var old_h = jQuery.css(this, "height");
663 jQuery(this).append("<br/>Some more text<br/>and some more...");
665 if ( /Auto/.test( fn ) ) {
666 notEqual(jQuery.css(this, "height"), old_h, "Make sure height is auto.");
668 equals(jQuery.css(this, "height"), old_h, "Make sure height is not auto.");
678 jQuery.fn.saveState = function(hiddenOverflow){
679 var check = ['opacity','height','width','display','overflow'];
680 expect(check.length);
683 return this.each(function(){
686 jQuery.each(check, function(i,c){
687 self.save[c] = c === "overflow" && hiddenOverflow ? "hidden" : self.style[ c ] || jQuery.css(self,c);
692 jQuery.checkState = function(){
694 jQuery.each(this.save, function(c,v){
695 var cur = self.style[ c ] || jQuery.css(self, c);
696 equals( cur, v, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")");
702 test("Chain fadeOut fadeIn", function() {
703 jQuery('#fadein div').saveState().fadeOut('fast').fadeIn('fast',jQuery.checkState);
705 test("Chain fadeIn fadeOut", function() {
706 jQuery('#fadeout div').saveState().fadeIn('fast').fadeOut('fast',jQuery.checkState);
709 test("Chain hide show", function() {
710 jQuery('#show div').saveState(jQuery.support.shrinkWrapBlocks).hide('fast').show('fast',jQuery.checkState);
712 test("Chain show hide", function() {
713 jQuery('#hide div').saveState(jQuery.support.shrinkWrapBlocks).show('fast').hide('fast',jQuery.checkState);
715 test("Chain show hide with easing and callback", function() {
716 jQuery('#hide div').saveState().show('fast').hide('fast','linear',jQuery.checkState);
719 test("Chain toggle in", function() {
720 jQuery('#togglein div').saveState(jQuery.support.shrinkWrapBlocks).toggle('fast').toggle('fast',jQuery.checkState);
722 test("Chain toggle out", function() {
723 jQuery('#toggleout div').saveState(jQuery.support.shrinkWrapBlocks).toggle('fast').toggle('fast',jQuery.checkState);
725 test("Chain toggle out with easing and callback", function() {
726 jQuery('#toggleout div').saveState(jQuery.support.shrinkWrapBlocks).toggle('fast').toggle('fast','linear',jQuery.checkState);
728 test("Chain slideDown slideUp", function() {
729 jQuery('#slidedown div').saveState(jQuery.support.shrinkWrapBlocks).slideDown('fast').slideUp('fast',jQuery.checkState);
731 test("Chain slideUp slideDown", function() {
732 jQuery('#slideup div').saveState(jQuery.support.shrinkWrapBlocks).slideUp('fast').slideDown('fast',jQuery.checkState);
734 test("Chain slideUp slideDown with easing and callback", function() {
735 jQuery('#slideup div').saveState(jQuery.support.shrinkWrapBlocks).slideUp('fast').slideDown('fast','linear',jQuery.checkState);
738 test("Chain slideToggle in", function() {
739 jQuery('#slidetogglein div').saveState(jQuery.support.shrinkWrapBlocks).slideToggle('fast').slideToggle('fast',jQuery.checkState);
741 test("Chain slideToggle out", function() {
742 jQuery('#slidetoggleout div').saveState(jQuery.support.shrinkWrapBlocks).slideToggle('fast').slideToggle('fast',jQuery.checkState);
745 test("Chain fadeToggle in", function() {
746 jQuery('#fadetogglein div').saveState().fadeToggle('fast').fadeToggle('fast',jQuery.checkState);
748 test("Chain fadeToggle out", function() {
749 jQuery('#fadetoggleout div').saveState().fadeToggle('fast').fadeToggle('fast',jQuery.checkState);
752 test("Chain fadeTo 0.5 1.0 with easing and callback)", function() {
753 jQuery('#fadeto div').saveState().fadeTo('fast',0.5).fadeTo('fast',1.0,'linear',jQuery.checkState);
756 jQuery.makeTest = function( text ){
757 var elem = jQuery("<div></div>")
758 .attr("id", "test" + jQuery.makeTest.id++)
763 .appendTo("#fx-tests")
765 jQuery(this).next().toggle();
772 jQuery.makeTest.id = 1;
774 test("jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function () {
778 var $checkedtest = jQuery("#checkedtest");
779 // IE6 was clearing "checked" in jQuery(elem).show("fast");
780 $checkedtest.hide().show("fast", function() {
781 ok( !! jQuery(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
782 ok( ! jQuery(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
783 ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
784 ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
789 test("animate with per-property easing", function(){
794 var _test1_called = false;
795 var _test2_called = false;
796 var _default_test_called = false;
798 jQuery.easing['_test1'] = function() {
799 _test1_called = true;
802 jQuery.easing['_test2'] = function() {
803 _test2_called = true;
806 jQuery.easing['_default_test'] = function() {
807 _default_test_called = true;
810 jQuery({a:0,b:0,c:0}).animate({
814 }, 400, '_default_test', function(){
816 ok(_test1_called, "Easing function (1) called");
817 ok(_test2_called, "Easing function (2) called");
818 ok(_default_test_called, "Easing function (_default) called");
823 test("hide hidden elements (bug #7141)", function() {
827 var div = jQuery("<div style='display:none'></div>").appendTo("#main");
828 equals( div.css("display"), "none", "Element is hidden by default" );
830 ok( !div.data("olddisplay"), "olddisplay is undefined after hiding an already-hidden element" );
832 equals( div.css("display"), "block", "Show a double-hidden element" );
837 test("hide hidden elements, with animation (bug #7141)", function() {
842 var div = jQuery("<div style='display:none'></div>").appendTo("#main");
843 equals( div.css("display"), "none", "Element is hidden by default" );
844 div.hide(1, function () {
845 ok( !div.data("olddisplay"), "olddisplay is undefined after hiding an already-hidden element" );
846 div.show(1, function () {
847 equals( div.css("display"), "block", "Show a double-hidden element" );