3 test("show()", function() {
5 var pass = true, div = jQuery("#main div");
6 div.show().each(function(){
7 if ( this.style.display == "none" ) pass = false;
13 "undefined speed": undefined,
14 "empty string speed": "",
18 jQuery.each(speeds, function(name, speed) {
20 div.hide().show(speed).each(function() {
21 if ( this.style.display == "none" ) pass = false;
23 ok( pass, "Show with " + name);
27 jQuery.each(speeds, function(name, speed) {
29 div.hide().show(speed, function() {
32 ok( pass, "Show with " + name + " does not call animate callback" );
35 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>');
37 var old = jQuery("#show-tests table").show().css("display") !== "table";
46 "table" : old ? "block" : "table",
47 "thead" : old ? "block" : "table-header-group",
48 "tbody" : old ? "block" : "table-row-group",
49 "tr" : old ? "block" : "table-row",
50 "th" : old ? "block" : "table-cell",
51 "td" : old ? "block" : "table-cell",
53 "li" : old ? "block" : "list-item"
56 jQuery.each(test, function(selector, expected) {
57 var elem = jQuery(selector, "#show-tests").show();
58 equals( elem.css("display"), expected, "Show using correct display type for " + selector );
62 test("show(Number) - other displays", function() {
67 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>');
69 var old = jQuery("#show-tests table").show().css("display") !== "table",
79 "table" : old ? "block" : "table",
80 "thead" : old ? "block" : "table-header-group",
81 "tbody" : old ? "block" : "table-row-group",
82 "tr" : old ? "block" : "table-row",
83 "th" : old ? "block" : "table-cell",
84 "td" : old ? "block" : "table-cell",
86 "li" : old ? "block" : "list-item"
89 jQuery.each(test, function(selector, expected) {
90 var elem = jQuery(selector, "#show-tests").show(1, function() {
91 equals( elem.css("display"), expected, "Show using correct display type for " + selector );
99 test("animate(Hash, Object, Function)", function() {
102 var hash = {opacity: 'show'};
103 var hashCopy = jQuery.extend({}, hash);
104 jQuery('#foo').animate(hash, 0, function() {
105 equals( hash.opacity, hashCopy.opacity, 'Check if animate changed the hash parameter' );
110 test("animate negative height", function() {
113 jQuery("#foo").animate({ height: -100 }, 100, function() {
114 equals( this.offsetHeight, 0, "Verify height." );
119 /* // This test ends up being flaky depending upon the CPU load
120 test("animate option (queue === false)", function () {
126 var $foo = jQuery("#foo");
127 $foo.animate({width:'100px'}, 3000, function () {
128 // should finish after unqueued animation so second
130 same( order, [ 1, 2 ], "Animations finished in the correct order" );
133 $foo.animate({fontSize:'2em'}, {queue:false, duration:10, complete:function () {
134 // short duration and out of queue so should finish first
140 test("animate with no properties", function() {
143 var divs = jQuery("div"), count = 0;
145 divs.animate({}, function(){
149 equals( divs.length, count, "Make sure that callback is called for each element in the set." );
153 var foo = jQuery("#foo");
156 foo.animate({top: 10}, 100, function(){
157 ok( true, "Animation was properly dequeued." );
162 test("animate duration 0", function() {
167 var $elems = jQuery([{ a:0 },{ a:0 }]), counter = 0;
169 equals( jQuery.timers.length, 0, "Make sure no animation was running from another test" );
171 $elems.eq(0).animate( {a:1}, 0, function(){
172 ok( true, "Animate a simple property." );
176 // Failed until [6115]
177 equals( jQuery.timers.length, 0, "Make sure synchronic animations are not left on jQuery.timers" );
179 equals( counter, 1, "One synchronic animations" );
181 $elems.animate( { a:2 }, 0, function(){
182 ok( true, "Animate a second simple property." );
186 equals( counter, 3, "Multiple synchronic animations" );
188 $elems.eq(0).animate( {a:3}, 0, function(){
189 ok( true, "Animate a third simple property." );
192 $elems.eq(1).animate( {a:3}, 200, function(){
194 // Failed until [6115]
195 equals( counter, 5, "One synchronic and one asynchronic" );
199 var $elem = jQuery("<div />");
200 $elem.show(0, function(){
201 ok(true, "Show callback with no duration");
203 $elem.hide(0, function(){
204 ok(true, "Hide callback with no duration");
208 test("animate hyphenated properties", function(){
212 jQuery("#nothiddendiv")
213 .css("font-size", 10)
214 .animate({"font-size": 20}, 200, function(){
215 equals( this.style.fontSize, "20px", "The font-size property was animated." );
220 test("animate non-element", function(){
224 var obj = { test: 0 };
226 jQuery(obj).animate({test: 200}, 200, function(){
227 equals( obj.test, 200, "The custom property should be modified." );
232 test("stop()", function() {
236 var $foo = jQuery("#nothiddendiv");
238 $foo.hide().width(200).width();
240 $foo.animate({ width:'show' }, 1000);
241 setTimeout(function(){
242 var nw = $foo.width();
243 notEqual( nw, w, "An animation occurred " + nw + "px " + w + "px");
247 notEqual( nw, w, "Stop didn't reset the animation " + nw + "px " + w + "px");
248 setTimeout(function(){
249 equals( nw, $foo.width(), "The animation didn't continue" );
255 test("stop() - several in queue", function() {
259 var $foo = jQuery("#nothiddendivchild");
261 $foo.hide().width(200).width();
263 $foo.animate({ width:'show' }, 1000);
264 $foo.animate({ width:'hide' }, 1000);
265 $foo.animate({ width:'show' }, 1000);
266 setTimeout(function(){
267 equals( $foo.queue().length, 3, "All 3 still in the queue" );
268 var nw = $foo.width();
269 notEqual( nw, w, "An animation occurred " + nw + "px " + w + "px");
273 notEqual( nw, w, "Stop didn't reset the animation " + nw + "px " + w + "px");
280 test("stop(clearQueue)", function() {
284 var $foo = jQuery("#nothiddendiv");
286 $foo.hide().width(200).width();
288 $foo.animate({ width:'show' }, 1000);
289 $foo.animate({ width:'hide' }, 1000);
290 $foo.animate({ width:'show' }, 1000);
291 setTimeout(function(){
292 var nw = $foo.width();
293 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
297 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
299 equals( $foo.queue().length, 0, "The animation queue was cleared" );
300 setTimeout(function(){
301 equals( nw, $foo.width(), "The animation didn't continue" );
307 test("stop(clearQueue, gotoEnd)", function() {
311 var $foo = jQuery("#nothiddendivchild");
313 $foo.hide().width(200).width();
315 $foo.animate({ width:'show' }, 1000);
316 $foo.animate({ width:'hide' }, 1000);
317 $foo.animate({ width:'show' }, 1000);
318 $foo.animate({ width:'hide' }, 1000);
319 setTimeout(function(){
320 var nw = $foo.width();
321 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
322 $foo.stop(false, true);
325 // Disabled, being flaky
326 //equals( nw, 1, "Stop() reset the animation" );
328 setTimeout(function(){
329 // Disabled, being flaky
330 //equals( $foo.queue().length, 2, "The next animation continued" );
337 test("toggle()", function() {
339 var x = jQuery("#nothiddendiv");
340 ok( x.is(":visible"), "is visible" );
342 ok( x.is(":hidden"), "is hidden" );
344 ok( x.is(":visible"), "is visible again" );
347 ok( x.is(":visible"), "is visible" );
349 ok( x.is(":hidden"), "is hidden" );
351 ok( x.is(":visible"), "is visible again" );
354 jQuery.checkOverflowDisplay = function(){
355 var o = jQuery.css( this, "overflow" );
357 equals(o, "visible", "Overflow should be visible: " + o);
358 equals(jQuery.css( this, "display" ), "inline", "Display shouldn't be tampered with.");
363 test("JS Overflow and Display", function() {
366 jQuery.makeTest( "JS Overflow and Display" )
367 .addClass("widewidth")
368 .css({ overflow: "visible", display: "inline" })
369 .addClass("widewidth")
370 .text("Some sample text.")
371 .before("text before")
373 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
376 test("CSS Overflow and Display", function() {
379 jQuery.makeTest( "CSS Overflow and Display" )
380 .addClass("overflow inline")
381 .addClass("widewidth")
382 .text("Some sample text.")
383 .before("text before")
385 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
389 "CSS Auto": function(elem,prop){
390 jQuery(elem).addClass("auto" + prop)
391 .text("This is a long string of text.");
394 "JS Auto": function(elem,prop){
395 jQuery(elem).css(prop,"")
396 .text("This is a long string of text.");
399 "CSS 100": function(elem,prop){
400 jQuery(elem).addClass("large" + prop);
403 "JS 100": function(elem,prop){
404 jQuery(elem).css(prop,prop == "opacity" ? 1 : "100px");
405 return prop == "opacity" ? 1 : 100;
407 "CSS 50": function(elem,prop){
408 jQuery(elem).addClass("med" + prop);
411 "JS 50": function(elem,prop){
412 jQuery(elem).css(prop,prop == "opacity" ? 0.50 : "50px");
413 return prop == "opacity" ? 0.5 : 50;
415 "CSS 0": function(elem,prop){
416 jQuery(elem).addClass("no" + prop);
419 "JS 0": function(elem,prop){
420 jQuery(elem).css(prop,prop == "opacity" ? 0 : "0px");
425 "show": function(elem,prop){
426 jQuery(elem).hide().addClass("wide"+prop);
429 "hide": function(elem,prop){
430 jQuery(elem).addClass("wide"+prop);
433 "100": function(elem,prop){
434 jQuery(elem).addClass("wide"+prop);
435 return prop == "opacity" ? 1 : 100;
437 "50": function(elem,prop){
438 return prop == "opacity" ? 0.50 : 50;
440 "0": function(elem,prop){
441 jQuery(elem).addClass("noback");
445 test(fn + " to " + tn, function() {
446 var elem = jQuery.makeTest( fn + " to " + tn );
448 var t_w = t( elem, "width" );
449 var f_w = f( elem, "width" );
450 var t_h = t( elem, "height" );
451 var f_h = f( elem, "height" );
452 var t_o = t( elem, "opacity" );
453 var f_o = f( elem, "opacity" );
457 if ( t_h == "show" ) num++;
458 if ( t_w == "show" ) num++;
459 if ( t_w == "hide"||t_w == "show" ) num++;
460 if ( t_h == "hide"||t_h == "show" ) num++;
461 if ( t_o == "hide"||t_o == "show" ) num++;
462 if ( t_w == "hide" ) num++;
463 if ( t_o.constructor == Number ) num += 2;
464 if ( t_w.constructor == Number ) num += 2;
465 if ( t_h.constructor == Number ) num +=2;
470 var anim = { width: t_w, height: t_h, opacity: t_o };
472 elem.animate(anim, 50, function(){
474 equals( this.style.display, "block", "Showing, display should block: " + this.style.display);
476 if ( t_w == "hide"||t_w == "show" )
477 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);
479 if ( t_h == "hide"||t_h == "show" )
480 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);
482 var cur_o = jQuery.style(this, "opacity");
484 if ( t_o == "hide" || t_o == "show" )
485 equals(cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o);
488 equals(this.style.display, "none", "Hiding, display should be none: " + this.style.display);
490 if ( t_o.constructor == Number ) {
491 equals(cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o);
493 ok(jQuery.css(this, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o);
496 if ( t_w.constructor == Number ) {
497 equals(this.style.width, t_w + "px", "Final width should be " + t_w + ": " + this.style.width);
499 var cur_w = jQuery.css(this,"width");
501 ok(this.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w);
504 if ( t_h.constructor == Number ) {
505 equals(this.style.height, t_h + "px", "Final height should be " + t_h + ": " + this.style.height);
507 var cur_h = jQuery.css(this,"height");
509 ok(this.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w);
512 if ( t_h == "show" ) {
513 var old_h = jQuery.css(this, "height");
514 jQuery(this).append("<br/>Some more text<br/>and some more...");
516 if ( /Auto/.test( fn ) ) {
517 notEqual(jQuery.css(this, "height"), old_h, "Make sure height is auto.");
519 equals(jQuery.css(this, "height"), old_h, "Make sure height is not auto.");
529 jQuery.fn.saveState = function(){
530 var check = ['opacity','height','width','display','overflow'];
531 expect(check.length);
534 return this.each(function(){
537 jQuery.each(check, function(i,c){
538 self.save[c] = self.style[ c ] || jQuery.css(self,c);
543 jQuery.checkState = function(){
545 jQuery.each(this.save, function(c,v){
546 var cur = self.style[ c ] || jQuery.css(self, c);
547 equals( cur, v, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")");
553 test("Chain fadeOut fadeIn", function() {
554 jQuery('#fadein div').saveState().fadeOut('fast').fadeIn('fast',jQuery.checkState);
556 test("Chain fadeIn fadeOut", function() {
557 jQuery('#fadeout div').saveState().fadeIn('fast').fadeOut('fast',jQuery.checkState);
560 test("Chain hide show", function() {
561 jQuery('#show div').saveState().hide('fast').show('fast',jQuery.checkState);
563 test("Chain show hide", function() {
564 jQuery('#hide div').saveState().show('fast').hide('fast',jQuery.checkState);
566 test("Chain show hide with easing and callback", function() {
567 jQuery('#hide div').saveState().show('fast').hide('fast','linear',jQuery.checkState);
570 test("Chain toggle in", function() {
571 jQuery('#togglein div').saveState().toggle('fast').toggle('fast',jQuery.checkState);
573 test("Chain toggle out", function() {
574 jQuery('#toggleout div').saveState().toggle('fast').toggle('fast',jQuery.checkState);
576 test("Chain toggle out with easing and callback", function() {
577 jQuery('#toggleout div').saveState().toggle('fast').toggle('fast','linear',jQuery.checkState);
579 test("Chain slideDown slideUp", function() {
580 jQuery('#slidedown div').saveState().slideDown('fast').slideUp('fast',jQuery.checkState);
582 test("Chain slideUp slideDown", function() {
583 jQuery('#slideup div').saveState().slideUp('fast').slideDown('fast',jQuery.checkState);
585 test("Chain slideUp slideDown with easing and callback", function() {
586 jQuery('#slideup div').saveState().slideUp('fast').slideDown('fast','linear',jQuery.checkState);
589 test("Chain slideToggle in", function() {
590 jQuery('#slidetogglein div').saveState().slideToggle('fast').slideToggle('fast',jQuery.checkState);
592 test("Chain slideToggle out", function() {
593 jQuery('#slidetoggleout div').saveState().slideToggle('fast').slideToggle('fast',jQuery.checkState);
596 test("Chain fadeTo 0.5 1.0 with easing and callback)", function() {
597 jQuery('#fadeto div').saveState().fadeTo('fast',0.5).fadeTo('fast',1.0,'linear',jQuery.checkState);
600 jQuery.makeTest = function( text ){
601 var elem = jQuery("<div></div>")
602 .attr("id", "test" + jQuery.makeTest.id++)
607 .appendTo("#fx-tests")
609 jQuery(this).next().toggle();
616 jQuery.makeTest.id = 1;
618 test("jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function () {
622 var $checkedtest = jQuery("#checkedtest");
623 // IE6 was clearing "checked" in jQuery(elem).show("fast");
624 $checkedtest.hide().show("fast", function() {
625 ok( !! jQuery(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
626 ok( ! jQuery(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
627 ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
628 ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
633 test("animate with per-property easing", function(){
638 var _test1_called = false;
639 var _test2_called = false;
640 var _default_test_called = false;
642 jQuery.easing['_test1'] = function() {
643 _test1_called = true;
646 jQuery.easing['_test2'] = function() {
647 _test2_called = true;
650 jQuery.easing['_default_test'] = function() {
651 _default_test_called = true;
654 jQuery({a:0,b:0,c:0}).animate({
658 }, 400, '_default_test', function(){
660 ok(_test1_called, "Easing function (1) called");
661 ok(_test2_called, "Easing function (2) called");
662 ok(_default_test_called, "Easing function (_default) called");