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 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
247 ok( 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 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
273 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
274 // Disabled, being flaky
275 //equals( $foo.queue().length, 1, "The next animation continued" );
281 test("stop(clearQueue)", function() {
285 var $foo = jQuery("#nothiddendiv");
287 $foo.hide().width(200).width();
289 $foo.animate({ width:'show' }, 1000);
290 $foo.animate({ width:'hide' }, 1000);
291 $foo.animate({ width:'show' }, 1000);
292 setTimeout(function(){
293 var nw = $foo.width();
294 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
298 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
300 equals( $foo.queue().length, 0, "The animation queue was cleared" );
301 setTimeout(function(){
302 equals( nw, $foo.width(), "The animation didn't continue" );
308 test("stop(clearQueue, gotoEnd)", function() {
312 var $foo = jQuery("#nothiddendivchild");
314 $foo.hide().width(200).width();
316 $foo.animate({ width:'show' }, 1000);
317 $foo.animate({ width:'hide' }, 1000);
318 $foo.animate({ width:'show' }, 1000);
319 $foo.animate({ width:'hide' }, 1000);
320 setTimeout(function(){
321 var nw = $foo.width();
322 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
323 $foo.stop(false, true);
326 // Disabled, being flaky
327 //equals( nw, 1, "Stop() reset the animation" );
329 setTimeout(function(){
330 // Disabled, being flaky
331 //equals( $foo.queue().length, 2, "The next animation continued" );
338 test("toggle()", function() {
340 var x = jQuery("#nothiddendiv");
341 ok( x.is(":visible"), "is visible" );
343 ok( x.is(":hidden"), "is hidden" );
345 ok( x.is(":visible"), "is visible again" );
348 ok( x.is(":visible"), "is visible" );
350 ok( x.is(":hidden"), "is hidden" );
352 ok( x.is(":visible"), "is visible again" );
355 jQuery.checkOverflowDisplay = function(){
356 var o = jQuery.css( this, "overflow" );
358 equals(o, "visible", "Overflow should be visible: " + o);
359 equals(jQuery.css( this, "display" ), "inline", "Display shouldn't be tampered with.");
364 test("JS Overflow and Display", function() {
367 jQuery.makeTest( "JS Overflow and Display" )
368 .addClass("widewidth")
369 .css({ overflow: "visible", display: "inline" })
370 .addClass("widewidth")
371 .text("Some sample text.")
372 .before("text before")
374 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
377 test("CSS Overflow and Display", function() {
380 jQuery.makeTest( "CSS Overflow and Display" )
381 .addClass("overflow inline")
382 .addClass("widewidth")
383 .text("Some sample text.")
384 .before("text before")
386 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
390 "CSS Auto": function(elem,prop){
391 jQuery(elem).addClass("auto" + prop)
392 .text("This is a long string of text.");
395 "JS Auto": function(elem,prop){
396 jQuery(elem).css(prop,"auto")
397 .text("This is a long string of text.");
400 "CSS 100": function(elem,prop){
401 jQuery(elem).addClass("large" + prop);
404 "JS 100": function(elem,prop){
405 jQuery(elem).css(prop,prop == "opacity" ? 1 : "100px");
406 return prop == "opacity" ? 1 : 100;
408 "CSS 50": function(elem,prop){
409 jQuery(elem).addClass("med" + prop);
412 "JS 50": function(elem,prop){
413 jQuery(elem).css(prop,prop == "opacity" ? 0.50 : "50px");
414 return prop == "opacity" ? 0.5 : 50;
416 "CSS 0": function(elem,prop){
417 jQuery(elem).addClass("no" + prop);
420 "JS 0": function(elem,prop){
421 jQuery(elem).css(prop,prop == "opacity" ? 0 : "0px");
426 "show": function(elem,prop){
427 jQuery(elem).hide().addClass("wide"+prop);
430 "hide": function(elem,prop){
431 jQuery(elem).addClass("wide"+prop);
434 "100": function(elem,prop){
435 jQuery(elem).addClass("wide"+prop);
436 return prop == "opacity" ? 1 : 100;
438 "50": function(elem,prop){
439 return prop == "opacity" ? 0.50 : 50;
441 "0": function(elem,prop){
442 jQuery(elem).addClass("noback");
446 test(fn + " to " + tn, function() {
447 var elem = jQuery.makeTest( fn + " to " + tn );
449 var t_w = t( elem, "width" );
450 var f_w = f( elem, "width" );
451 var t_h = t( elem, "height" );
452 var f_h = f( elem, "height" );
453 var t_o = t( elem, "opacity" );
454 var f_o = f( elem, "opacity" );
458 if ( t_h == "show" ) num++;
459 if ( t_w == "show" ) num++;
460 if ( t_w == "hide"||t_w == "show" ) num++;
461 if ( t_h == "hide"||t_h == "show" ) num++;
462 if ( t_o == "hide"||t_o == "show" ) num++;
463 if ( t_w == "hide" ) num++;
464 if ( t_o.constructor == Number ) num += 2;
465 if ( t_w.constructor == Number ) num += 2;
466 if ( t_h.constructor == Number ) num +=2;
471 var anim = { width: t_w, height: t_h, opacity: t_o };
473 elem.animate(anim, 50, function(){
475 equals( this.style.display, "block", "Showing, display should block: " + this.style.display);
477 if ( t_w == "hide"||t_w == "show" )
478 equals(this.style.width.indexOf(f_w), 0, "Width must be reset to " + f_w + ": " + this.style.width);
480 if ( t_h == "hide"||t_h == "show" )
481 equals(this.style.height.indexOf(f_h), 0, "Height must be reset to " + f_h + ": " + this.style.height);
483 var cur_o = jQuery.style(this, "opacity");
484 if ( cur_o !== "" ) cur_o = parseFloat( cur_o );
486 if ( t_o == "hide"||t_o == "show" )
487 equals(cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o);
490 equals(this.style.display, "none", "Hiding, display should be none: " + this.style.display);
492 if ( t_o.constructor == Number ) {
493 equals(cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o);
495 ok(jQuery.curCSS(this, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o);
498 if ( t_w.constructor == Number ) {
499 equals(this.style.width, t_w + "px", "Final width should be " + t_w + ": " + this.style.width);
501 var cur_w = jQuery.css(this,"width");
503 ok(this.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w);
506 if ( t_h.constructor == Number ) {
507 equals(this.style.height, t_h + "px", "Final height should be " + t_h + ": " + this.style.height);
509 var cur_h = jQuery.css(this,"height");
511 ok(this.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w);
514 if ( t_h == "show" ) {
515 var old_h = jQuery.curCSS(this, "height");
516 jQuery(elem).append("<br/>Some more text<br/>and some more...");
517 ok(old_h != jQuery.css(this, "height" ), "Make sure height is auto.");
526 jQuery.fn.saveState = function(){
527 var check = ['opacity','height','width','display','overflow'];
528 expect(check.length);
531 return this.each(function(){
534 jQuery.each(check, function(i,c){
535 self.save[c] = jQuery.css(self,c);
540 jQuery.checkState = function(){
542 jQuery.each(this.save, function(c,v){
543 var cur = jQuery.css(self,c);
544 equals( v, cur, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")");
550 test("Chain fadeOut fadeIn", function() {
551 jQuery('#fadein div').saveState().fadeOut('fast').fadeIn('fast',jQuery.checkState);
553 test("Chain fadeIn fadeOut", function() {
554 jQuery('#fadeout div').saveState().fadeIn('fast').fadeOut('fast',jQuery.checkState);
557 test("Chain hide show", function() {
558 jQuery('#show div').saveState().hide('fast').show('fast',jQuery.checkState);
560 test("Chain show hide", function() {
561 jQuery('#hide div').saveState().show('fast').hide('fast',jQuery.checkState);
564 test("Chain toggle in", function() {
565 jQuery('#togglein div').saveState().toggle('fast').toggle('fast',jQuery.checkState);
567 test("Chain toggle out", function() {
568 jQuery('#toggleout div').saveState().toggle('fast').toggle('fast',jQuery.checkState);
571 test("Chain slideDown slideUp", function() {
572 jQuery('#slidedown div').saveState().slideDown('fast').slideUp('fast',jQuery.checkState);
574 test("Chain slideUp slideDown", function() {
575 jQuery('#slideup div').saveState().slideUp('fast').slideDown('fast',jQuery.checkState);
578 test("Chain slideToggle in", function() {
579 jQuery('#slidetogglein div').saveState().slideToggle('fast').slideToggle('fast',jQuery.checkState);
581 test("Chain slideToggle out", function() {
582 jQuery('#slidetoggleout div').saveState().slideToggle('fast').slideToggle('fast',jQuery.checkState);
585 jQuery.makeTest = function( text ){
586 var elem = jQuery("<div></div>")
587 .attr("id", "test" + jQuery.makeTest.id++)
592 .appendTo("#fx-tests")
594 jQuery(this).next().toggle();
601 jQuery.makeTest.id = 1;
603 test("jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function () {
607 var $checkedtest = jQuery("#checkedtest");
608 // IE6 was clearing "checked" in jQuery(elem).show("fast");
609 $checkedtest.hide().show("fast", function() {
610 ok( !! jQuery(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
611 ok( ! jQuery(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
612 ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
613 ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
618 test("animate with per-property easing", function(){
623 var _test1_called = false;
624 var _test2_called = false;
625 var _default_test_called = false;
627 jQuery.easing['_test1'] = function() {
628 _test1_called = true;
631 jQuery.easing['_test2'] = function() {
632 _test2_called = true;
635 jQuery.easing['_default_test'] = function() {
636 _default_test_called = true;
639 jQuery({a:0,b:0,c:0}).animate({
643 }, 400, '_default_test', function(){
645 ok(_test1_called, "Easing function (1) called");
646 ok(_test2_called, "Easing function (2) called");
647 ok(_default_test_called, "Easing function (_default) called");