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");
36 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>');
38 var old = jQuery("#show-tests table").show().css("display") !== "table";
47 "table" : old ? "block" : "table",
48 "thead" : old ? "block" : "table-header-group",
49 "tbody" : old ? "block" : "table-row-group",
50 "tr" : old ? "block" : "table-row",
51 "th" : old ? "block" : "table-cell",
52 "td" : old ? "block" : "table-cell",
54 "li" : old ? "block" : "list-item"
57 jQuery.each(test, function(selector, expected) {
58 var elem = jQuery(selector, "#show-tests").show();
59 equals( elem.css("display"), expected, "Show using correct display type for " + selector );
63 test("show(Number) - other displays", function() {
68 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>');
70 var old = jQuery("#show-tests table").show().css("display") !== "table",
80 "table" : old ? "block" : "table",
81 "thead" : old ? "block" : "table-header-group",
82 "tbody" : old ? "block" : "table-row-group",
83 "tr" : old ? "block" : "table-row",
84 "th" : old ? "block" : "table-cell",
85 "td" : old ? "block" : "table-cell",
87 "li" : old ? "block" : "list-item"
90 jQuery.each(test, function(selector, expected) {
91 var elem = jQuery(selector, "#show-tests").show(1, function() {
92 equals( elem.css("display"), expected, "Show using correct display type for " + selector );
100 test("animate(Hash, Object, Function)", function() {
103 var hash = {opacity: 'show'};
104 var hashCopy = jQuery.extend({}, hash);
105 jQuery('#foo').animate(hash, 0, function() {
106 equals( hash.opacity, hashCopy.opacity, 'Check if animate changed the hash parameter' );
111 test("animate negative height", function() {
114 jQuery("#foo").animate({ height: -100 }, 100, function() {
115 equals( this.offsetHeight, 0, "Verify height." );
120 /* // This test ends up being flaky depending upon the CPU load
121 test("animate option (queue === false)", function () {
127 var $foo = jQuery("#foo");
128 $foo.animate({width:'100px'}, 3000, function () {
129 // should finish after unqueued animation so second
131 same( order, [ 1, 2 ], "Animations finished in the correct order" );
134 $foo.animate({fontSize:'2em'}, {queue:false, duration:10, complete:function () {
135 // short duration and out of queue so should finish first
141 test("animate with no properties", function() {
144 var divs = jQuery("div"), count = 0;
146 divs.animate({}, function(){
150 equals( divs.length, count, "Make sure that callback is called for each element in the set." );
154 var foo = jQuery("#foo");
157 foo.animate({top: 10}, 100, function(){
158 ok( true, "Animation was properly dequeued." );
163 test("animate duration 0", function() {
168 var $elems = jQuery([{ a:0 },{ a:0 }]), counter = 0;
170 equals( jQuery.timers.length, 0, "Make sure no animation was running from another test" );
172 $elems.eq(0).animate( {a:1}, 0, function(){
173 ok( true, "Animate a simple property." );
177 // Failed until [6115]
178 equals( jQuery.timers.length, 0, "Make sure synchronic animations are not left on jQuery.timers" );
180 equals( counter, 1, "One synchronic animations" );
182 $elems.animate( { a:2 }, 0, function(){
183 ok( true, "Animate a second simple property." );
187 equals( counter, 3, "Multiple synchronic animations" );
189 $elems.eq(0).animate( {a:3}, 0, function(){
190 ok( true, "Animate a third simple property." );
193 $elems.eq(1).animate( {a:3}, 200, function(){
195 // Failed until [6115]
196 equals( counter, 5, "One synchronic and one asynchronic" );
200 var $elem = jQuery("<div />");
201 $elem.show(0, function(){
202 ok(true, "Show callback with no duration");
204 $elem.hide(0, function(){
205 ok(true, "Hide callback with no duration");
209 test("animate hyphenated properties", function(){
213 jQuery("#nothiddendiv")
214 .css("font-size", 10)
215 .animate({"font-size": 20}, 200, function(){
216 equals( this.style.fontSize, "20px", "The font-size property was animated." );
221 test("animate non-element", function(){
225 var obj = { test: 0 };
227 jQuery(obj).animate({test: 200}, 200, function(){
228 equals( obj.test, 200, "The custom property should be modified." );
233 test("stop()", function() {
237 var $foo = jQuery("#nothiddendiv");
239 $foo.hide().width(200).width();
241 $foo.animate({ width:'show' }, 1000);
242 setTimeout(function(){
243 var nw = $foo.width();
244 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
248 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
249 setTimeout(function(){
250 equals( nw, $foo.width(), "The animation didn't continue" );
256 test("stop() - several in queue", function() {
260 var $foo = jQuery("#nothiddendivchild");
262 $foo.hide().width(200).width();
264 $foo.animate({ width:'show' }, 1000);
265 $foo.animate({ width:'hide' }, 1000);
266 $foo.animate({ width:'show' }, 1000);
267 setTimeout(function(){
268 equals( $foo.queue().length, 3, "All 3 still in the queue" );
269 var nw = $foo.width();
270 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
274 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
275 // Disabled, being flaky
276 //equals( $foo.queue().length, 1, "The next animation continued" );
282 test("stop(clearQueue)", function() {
286 var $foo = jQuery("#nothiddendiv");
288 $foo.hide().width(200).width();
290 $foo.animate({ width:'show' }, 1000);
291 $foo.animate({ width:'hide' }, 1000);
292 $foo.animate({ width:'show' }, 1000);
293 setTimeout(function(){
294 var nw = $foo.width();
295 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
299 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
301 equals( $foo.queue().length, 0, "The animation queue was cleared" );
302 setTimeout(function(){
303 equals( nw, $foo.width(), "The animation didn't continue" );
309 test("stop(clearQueue, gotoEnd)", function() {
313 var $foo = jQuery("#nothiddendivchild");
315 $foo.hide().width(200).width();
317 $foo.animate({ width:'show' }, 1000);
318 $foo.animate({ width:'hide' }, 1000);
319 $foo.animate({ width:'show' }, 1000);
320 $foo.animate({ width:'hide' }, 1000);
321 setTimeout(function(){
322 var nw = $foo.width();
323 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
324 $foo.stop(false, true);
327 // Disabled, being flaky
328 //equals( nw, 1, "Stop() reset the animation" );
330 setTimeout(function(){
331 // Disabled, being flaky
332 //equals( $foo.queue().length, 2, "The next animation continued" );
339 test("toggle()", function() {
341 var x = jQuery("#nothiddendiv");
342 ok( x.is(":visible"), "is visible" );
344 ok( x.is(":hidden"), "is hidden" );
346 ok( x.is(":visible"), "is visible again" );
349 ok( x.is(":visible"), "is visible" );
351 ok( x.is(":hidden"), "is hidden" );
353 ok( x.is(":visible"), "is visible again" );
356 jQuery.checkOverflowDisplay = function(){
357 var o = jQuery.css( this, "overflow" );
359 equals(o, "visible", "Overflow should be visible: " + o);
360 equals(jQuery.css( this, "display" ), "inline", "Display shouldn't be tampered with.");
365 test("JS Overflow and Display", function() {
368 jQuery.makeTest( "JS Overflow and Display" )
369 .addClass("widewidth")
370 .css({ overflow: "visible", display: "inline" })
371 .addClass("widewidth")
372 .text("Some sample text.")
373 .before("text before")
375 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
378 test("CSS Overflow and Display", function() {
381 jQuery.makeTest( "CSS Overflow and Display" )
382 .addClass("overflow inline")
383 .addClass("widewidth")
384 .text("Some sample text.")
385 .before("text before")
387 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
391 "CSS Auto": function(elem,prop){
392 jQuery(elem).addClass("auto" + prop)
393 .text("This is a long string of text.");
396 "JS Auto": function(elem,prop){
397 jQuery(elem).css(prop,"auto")
398 .text("This is a long string of text.");
401 "CSS 100": function(elem,prop){
402 jQuery(elem).addClass("large" + prop);
405 "JS 100": function(elem,prop){
406 jQuery(elem).css(prop,prop == "opacity" ? 1 : "100px");
407 return prop == "opacity" ? 1 : 100;
409 "CSS 50": function(elem,prop){
410 jQuery(elem).addClass("med" + prop);
413 "JS 50": function(elem,prop){
414 jQuery(elem).css(prop,prop == "opacity" ? 0.50 : "50px");
415 return prop == "opacity" ? 0.5 : 50;
417 "CSS 0": function(elem,prop){
418 jQuery(elem).addClass("no" + prop);
421 "JS 0": function(elem,prop){
422 jQuery(elem).css(prop,prop == "opacity" ? 0 : "0px");
427 "show": function(elem,prop){
428 jQuery(elem).hide().addClass("wide"+prop);
431 "hide": function(elem,prop){
432 jQuery(elem).addClass("wide"+prop);
435 "100": function(elem,prop){
436 jQuery(elem).addClass("wide"+prop);
437 return prop == "opacity" ? 1 : 100;
439 "50": function(elem,prop){
440 return prop == "opacity" ? 0.50 : 50;
442 "0": function(elem,prop){
443 jQuery(elem).addClass("noback");
447 test(fn + " to " + tn, function() {
448 var elem = jQuery.makeTest( fn + " to " + tn );
450 var t_w = t( elem, "width" );
451 var f_w = f( elem, "width" );
452 var t_h = t( elem, "height" );
453 var f_h = f( elem, "height" );
454 var t_o = t( elem, "opacity" );
455 var f_o = f( elem, "opacity" );
459 if ( t_h == "show" ) num++;
460 if ( t_w == "show" ) num++;
461 if ( t_w == "hide"||t_w == "show" ) num++;
462 if ( t_h == "hide"||t_h == "show" ) num++;
463 if ( t_o == "hide"||t_o == "show" ) num++;
464 if ( t_w == "hide" ) num++;
465 if ( t_o.constructor == Number ) num += 2;
466 if ( t_w.constructor == Number ) num += 2;
467 if ( t_h.constructor == Number ) num +=2;
472 var anim = { width: t_w, height: t_h, opacity: t_o };
474 elem.animate(anim, 50, function(){
476 equals( this.style.display, "block", "Showing, display should block: " + this.style.display);
478 if ( t_w == "hide"||t_w == "show" )
479 equals(this.style.width.indexOf(f_w), 0, "Width must be reset to " + f_w + ": " + this.style.width);
481 if ( t_h == "hide"||t_h == "show" )
482 equals(this.style.height.indexOf(f_h), 0, "Height must be reset to " + f_h + ": " + this.style.height);
484 var cur_o = jQuery.style(this, "opacity");
485 if ( cur_o !== "" ) cur_o = parseFloat( cur_o );
487 if ( t_o == "hide"||t_o == "show" )
488 equals(cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o);
491 equals(this.style.display, "none", "Hiding, display should be none: " + this.style.display);
493 if ( t_o.constructor == Number ) {
494 equals(cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o);
496 ok(jQuery.curCSS(this, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o);
499 if ( t_w.constructor == Number ) {
500 equals(this.style.width, t_w + "px", "Final width should be " + t_w + ": " + this.style.width);
502 var cur_w = jQuery.css(this,"width");
504 ok(this.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w);
507 if ( t_h.constructor == Number ) {
508 equals(this.style.height, t_h + "px", "Final height should be " + t_h + ": " + this.style.height);
510 var cur_h = jQuery.css(this,"height");
512 ok(this.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w);
515 if ( t_h == "show" ) {
516 var old_h = jQuery.curCSS(this, "height");
517 jQuery(elem).append("<br/>Some more text<br/>and some more...");
518 ok(old_h != jQuery.css(this, "height" ), "Make sure height is auto.");
527 jQuery.fn.saveState = function(){
528 var check = ['opacity','height','width','display','overflow'];
529 expect(check.length);
532 return this.each(function(){
535 jQuery.each(check, function(i,c){
536 self.save[c] = jQuery.css(self,c);
541 jQuery.checkState = function(){
543 jQuery.each(this.save, function(c,v){
544 var cur = jQuery.css(self,c);
545 equals( v, cur, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")");
551 test("Chain fadeOut fadeIn", function() {
552 jQuery('#fadein div').saveState().fadeOut('fast').fadeIn('fast',jQuery.checkState);
554 test("Chain fadeIn fadeOut", function() {
555 jQuery('#fadeout div').saveState().fadeIn('fast').fadeOut('fast',jQuery.checkState);
558 test("Chain hide show", function() {
559 jQuery('#show div').saveState().hide('fast').show('fast',jQuery.checkState);
561 test("Chain show hide", function() {
562 jQuery('#hide div').saveState().show('fast').hide('fast',jQuery.checkState);
565 test("Chain toggle in", function() {
566 jQuery('#togglein div').saveState().toggle('fast').toggle('fast',jQuery.checkState);
568 test("Chain toggle out", function() {
569 jQuery('#toggleout div').saveState().toggle('fast').toggle('fast',jQuery.checkState);
572 test("Chain slideDown slideUp", function() {
573 jQuery('#slidedown div').saveState().slideDown('fast').slideUp('fast',jQuery.checkState);
575 test("Chain slideUp slideDown", function() {
576 jQuery('#slideup div').saveState().slideUp('fast').slideDown('fast',jQuery.checkState);
579 test("Chain slideToggle in", function() {
580 jQuery('#slidetogglein div').saveState().slideToggle('fast').slideToggle('fast',jQuery.checkState);
582 test("Chain slideToggle out", function() {
583 jQuery('#slidetoggleout div').saveState().slideToggle('fast').slideToggle('fast',jQuery.checkState);
586 jQuery.makeTest = function( text ){
587 var elem = jQuery("<div></div>")
588 .attr("id", "test" + jQuery.makeTest.id++)
593 .appendTo("#fx-tests")
595 jQuery(this).next().toggle();
602 jQuery.makeTest.id = 1;
604 test("jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function () {
608 var $checkedtest = jQuery("#checkedtest");
609 // IE6 was clearing "checked" in jQuery(elem).show("fast");
610 $checkedtest.hide().show("fast", function() {
611 ok( !! jQuery(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
612 ok( ! jQuery(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
613 ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
614 ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
619 test("animate with per-property easing", function(){
624 var _test1_called = false;
625 var _test2_called = false;
626 var _default_test_called = false;
628 jQuery.easing['_test1'] = function() {
629 _test1_called = true;
632 jQuery.easing['_test2'] = function() {
633 _test2_called = true;
636 jQuery.easing['_default_test'] = function() {
637 _default_test_called = true;
640 jQuery({a:0,b:0,c:0}).animate({
644 }, 400, '_default_test', function(){
646 ok(_test1_called, "Easing function (1) called");
647 ok(_test2_called, "Easing function (2) called");
648 ok(_default_test_called, "Easing function (_default) called");