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;
12 div.hide().show(null).each(function() {
13 if ( this.style.display == "none" ) pass = false;
15 ok( pass, "Show will null speed");
17 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>');
19 var old = jQuery("#show-tests table").show().css("display") !== "table";
28 "table" : old ? "block" : "table",
29 "thead" : old ? "block" : "table-header-group",
30 "tbody" : old ? "block" : "table-row-group",
31 "tr" : old ? "block" : "table-row",
32 "th" : old ? "block" : "table-cell",
33 "td" : old ? "block" : "table-cell",
35 "li" : old ? "block" : "list-item"
38 jQuery.each(test, function(selector, expected) {
39 var elem = jQuery(selector, "#show-tests").show();
40 equals( elem.css("display"), expected, "Show using correct display type for " + selector );
44 test("show(Number) - other displays", function() {
49 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>');
51 var old = jQuery("#show-tests table").show().css("display") !== "table",
61 "table" : old ? "block" : "table",
62 "thead" : old ? "block" : "table-header-group",
63 "tbody" : old ? "block" : "table-row-group",
64 "tr" : old ? "block" : "table-row",
65 "th" : old ? "block" : "table-cell",
66 "td" : old ? "block" : "table-cell",
68 "li" : old ? "block" : "list-item"
71 jQuery.each(test, function(selector, expected) {
72 var elem = jQuery(selector, "#show-tests").show(1, function() {
73 equals( elem.css("display"), expected, "Show using correct display type for " + selector );
81 test("animate(Hash, Object, Function)", function() {
84 var hash = {opacity: 'show'};
85 var hashCopy = jQuery.extend({}, hash);
86 jQuery('#foo').animate(hash, 0, function() {
87 equals( hash.opacity, hashCopy.opacity, 'Check if animate changed the hash parameter' );
92 test("animate negative height", function() {
95 jQuery("#foo").animate({ height: -100 }, 100, function() {
96 equals( this.offsetHeight, 0, "Verify height." );
101 /* // This test ends up being flaky depending upon the CPU load
102 test("animate option (queue === false)", function () {
108 var $foo = jQuery("#foo");
109 $foo.animate({width:'100px'}, 3000, function () {
110 // should finish after unqueued animation so second
112 same( order, [ 1, 2 ], "Animations finished in the correct order" );
115 $foo.animate({fontSize:'2em'}, {queue:false, duration:10, complete:function () {
116 // short duration and out of queue so should finish first
122 test("animate with no properties", function() {
125 var divs = jQuery("div"), count = 0;
127 divs.animate({}, function(){
131 equals( divs.length, count, "Make sure that callback is called for each element in the set." );
135 var foo = jQuery("#foo");
138 foo.animate({top: 10}, 100, function(){
139 ok( true, "Animation was properly dequeued." );
144 test("animate duration 0", function() {
149 var $elems = jQuery([{ a:0 },{ a:0 }]), counter = 0;
151 equals( jQuery.timers.length, 0, "Make sure no animation was running from another test" );
153 $elems.eq(0).animate( {a:1}, 0, function(){
154 ok( true, "Animate a simple property." );
158 // Failed until [6115]
159 equals( jQuery.timers.length, 0, "Make sure synchronic animations are not left on jQuery.timers" );
161 equals( counter, 1, "One synchronic animations" );
163 $elems.animate( { a:2 }, 0, function(){
164 ok( true, "Animate a second simple property." );
168 equals( counter, 3, "Multiple synchronic animations" );
170 $elems.eq(0).animate( {a:3}, 0, function(){
171 ok( true, "Animate a third simple property." );
174 $elems.eq(1).animate( {a:3}, 200, function(){
176 // Failed until [6115]
177 equals( counter, 5, "One synchronic and one asynchronic" );
181 var $elem = jQuery("<div />");
182 $elem.show(0, function(){
183 ok(true, "Show callback with no duration");
185 $elem.hide(0, function(){
186 ok(true, "Hide callback with no duration");
190 test("animate hyphenated properties", function(){
194 jQuery("#nothiddendiv")
195 .css("font-size", 10)
196 .animate({"font-size": 20}, 200, function(){
197 equals( this.style.fontSize, "20px", "The font-size property was animated." );
202 test("animate non-element", function(){
206 var obj = { test: 0 };
208 jQuery(obj).animate({test: 200}, 200, function(){
209 equals( obj.test, 200, "The custom property should be modified." );
214 test("stop()", function() {
218 var $foo = jQuery("#nothiddendiv");
220 $foo.hide().width(200).width();
222 $foo.animate({ width:'show' }, 1000);
223 setTimeout(function(){
224 var nw = $foo.width();
225 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
229 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
230 setTimeout(function(){
231 equals( nw, $foo.width(), "The animation didn't continue" );
237 test("stop() - several in queue", function() {
241 var $foo = jQuery("#nothiddendivchild");
243 $foo.hide().width(200).width();
245 $foo.animate({ width:'show' }, 1000);
246 $foo.animate({ width:'hide' }, 1000);
247 $foo.animate({ width:'show' }, 1000);
248 setTimeout(function(){
249 equals( $foo.queue().length, 3, "All 3 still in the queue" );
250 var nw = $foo.width();
251 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
255 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
256 // Disabled, being flaky
257 //equals( $foo.queue().length, 1, "The next animation continued" );
263 test("stop(clearQueue)", function() {
267 var $foo = jQuery("#nothiddendiv");
269 $foo.hide().width(200).width();
271 $foo.animate({ width:'show' }, 1000);
272 $foo.animate({ width:'hide' }, 1000);
273 $foo.animate({ width:'show' }, 1000);
274 setTimeout(function(){
275 var nw = $foo.width();
276 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
280 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
282 equals( $foo.queue().length, 0, "The animation queue was cleared" );
283 setTimeout(function(){
284 equals( nw, $foo.width(), "The animation didn't continue" );
290 test("stop(clearQueue, gotoEnd)", function() {
294 var $foo = jQuery("#nothiddendivchild");
296 $foo.hide().width(200).width();
298 $foo.animate({ width:'show' }, 1000);
299 $foo.animate({ width:'hide' }, 1000);
300 $foo.animate({ width:'show' }, 1000);
301 $foo.animate({ width:'hide' }, 1000);
302 setTimeout(function(){
303 var nw = $foo.width();
304 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
305 $foo.stop(false, true);
308 // Disabled, being flaky
309 //equals( nw, 1, "Stop() reset the animation" );
311 setTimeout(function(){
312 // Disabled, being flaky
313 //equals( $foo.queue().length, 2, "The next animation continued" );
320 test("toggle()", function() {
322 var x = jQuery("#nothiddendiv");
323 ok( x.is(":visible"), "is visible" );
325 ok( x.is(":hidden"), "is hidden" );
327 ok( x.is(":visible"), "is visible again" );
330 ok( x.is(":visible"), "is visible" );
332 ok( x.is(":hidden"), "is hidden" );
334 ok( x.is(":visible"), "is visible again" );
337 jQuery.checkOverflowDisplay = function(){
338 var o = jQuery.css( this, "overflow" );
340 equals(o, "visible", "Overflow should be visible: " + o);
341 equals(jQuery.css( this, "display" ), "inline", "Display shouldn't be tampered with.");
346 test("JS Overflow and Display", function() {
349 jQuery.makeTest( "JS Overflow and Display" )
350 .addClass("widewidth")
351 .css({ overflow: "visible", display: "inline" })
352 .addClass("widewidth")
353 .text("Some sample text.")
354 .before("text before")
356 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
359 test("CSS Overflow and Display", function() {
362 jQuery.makeTest( "CSS Overflow and Display" )
363 .addClass("overflow inline")
364 .addClass("widewidth")
365 .text("Some sample text.")
366 .before("text before")
368 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
372 "CSS Auto": function(elem,prop){
373 jQuery(elem).addClass("auto" + prop)
374 .text("This is a long string of text.");
377 "JS Auto": function(elem,prop){
378 jQuery(elem).css(prop,"auto")
379 .text("This is a long string of text.");
382 "CSS 100": function(elem,prop){
383 jQuery(elem).addClass("large" + prop);
386 "JS 100": function(elem,prop){
387 jQuery(elem).css(prop,prop == "opacity" ? 1 : "100px");
388 return prop == "opacity" ? 1 : 100;
390 "CSS 50": function(elem,prop){
391 jQuery(elem).addClass("med" + prop);
394 "JS 50": function(elem,prop){
395 jQuery(elem).css(prop,prop == "opacity" ? 0.50 : "50px");
396 return prop == "opacity" ? 0.5 : 50;
398 "CSS 0": function(elem,prop){
399 jQuery(elem).addClass("no" + prop);
402 "JS 0": function(elem,prop){
403 jQuery(elem).css(prop,prop == "opacity" ? 0 : "0px");
408 "show": function(elem,prop){
409 jQuery(elem).hide().addClass("wide"+prop);
412 "hide": function(elem,prop){
413 jQuery(elem).addClass("wide"+prop);
416 "100": function(elem,prop){
417 jQuery(elem).addClass("wide"+prop);
418 return prop == "opacity" ? 1 : 100;
420 "50": function(elem,prop){
421 return prop == "opacity" ? 0.50 : 50;
423 "0": function(elem,prop){
424 jQuery(elem).addClass("noback");
428 test(fn + " to " + tn, function() {
429 var elem = jQuery.makeTest( fn + " to " + tn );
431 var t_w = t( elem, "width" );
432 var f_w = f( elem, "width" );
433 var t_h = t( elem, "height" );
434 var f_h = f( elem, "height" );
435 var t_o = t( elem, "opacity" );
436 var f_o = f( elem, "opacity" );
440 if ( t_h == "show" ) num++;
441 if ( t_w == "show" ) num++;
442 if ( t_w == "hide"||t_w == "show" ) num++;
443 if ( t_h == "hide"||t_h == "show" ) num++;
444 if ( t_o == "hide"||t_o == "show" ) num++;
445 if ( t_w == "hide" ) num++;
446 if ( t_o.constructor == Number ) num += 2;
447 if ( t_w.constructor == Number ) num += 2;
448 if ( t_h.constructor == Number ) num +=2;
453 var anim = { width: t_w, height: t_h, opacity: t_o };
455 elem.animate(anim, 50, function(){
457 equals( this.style.display, "block", "Showing, display should block: " + this.style.display);
459 if ( t_w == "hide"||t_w == "show" )
460 equals(this.style.width.indexOf(f_w), 0, "Width must be reset to " + f_w + ": " + this.style.width);
462 if ( t_h == "hide"||t_h == "show" )
463 equals(this.style.height.indexOf(f_h), 0, "Height must be reset to " + f_h + ": " + this.style.height);
465 var cur_o = jQuery.style(this, "opacity");
466 if ( cur_o !== "" ) cur_o = parseFloat( cur_o );
468 if ( t_o == "hide"||t_o == "show" )
469 equals(cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o);
472 equals(this.style.display, "none", "Hiding, display should be none: " + this.style.display);
474 if ( t_o.constructor == Number ) {
475 equals(cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o);
477 ok(jQuery.curCSS(this, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o);
480 if ( t_w.constructor == Number ) {
481 equals(this.style.width, t_w + "px", "Final width should be " + t_w + ": " + this.style.width);
483 var cur_w = jQuery.css(this,"width");
485 ok(this.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w);
488 if ( t_h.constructor == Number ) {
489 equals(this.style.height, t_h + "px", "Final height should be " + t_h + ": " + this.style.height);
491 var cur_h = jQuery.css(this,"height");
493 ok(this.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w);
496 if ( t_h == "show" ) {
497 var old_h = jQuery.curCSS(this, "height");
498 jQuery(elem).append("<br/>Some more text<br/>and some more...");
499 ok(old_h != jQuery.css(this, "height" ), "Make sure height is auto.");
508 jQuery.fn.saveState = function(){
509 var check = ['opacity','height','width','display','overflow'];
510 expect(check.length);
513 return this.each(function(){
516 jQuery.each(check, function(i,c){
517 self.save[c] = jQuery.css(self,c);
522 jQuery.checkState = function(){
524 jQuery.each(this.save, function(c,v){
525 var cur = jQuery.css(self,c);
526 equals( v, cur, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")");
532 test("Chain fadeOut fadeIn", function() {
533 jQuery('#fadein div').saveState().fadeOut('fast').fadeIn('fast',jQuery.checkState);
535 test("Chain fadeIn fadeOut", function() {
536 jQuery('#fadeout div').saveState().fadeIn('fast').fadeOut('fast',jQuery.checkState);
539 test("Chain hide show", function() {
540 jQuery('#show div').saveState().hide('fast').show('fast',jQuery.checkState);
542 test("Chain show hide", function() {
543 jQuery('#hide div').saveState().show('fast').hide('fast',jQuery.checkState);
546 test("Chain toggle in", function() {
547 jQuery('#togglein div').saveState().toggle('fast').toggle('fast',jQuery.checkState);
549 test("Chain toggle out", function() {
550 jQuery('#toggleout div').saveState().toggle('fast').toggle('fast',jQuery.checkState);
553 test("Chain slideDown slideUp", function() {
554 jQuery('#slidedown div').saveState().slideDown('fast').slideUp('fast',jQuery.checkState);
556 test("Chain slideUp slideDown", function() {
557 jQuery('#slideup div').saveState().slideUp('fast').slideDown('fast',jQuery.checkState);
560 test("Chain slideToggle in", function() {
561 jQuery('#slidetogglein div').saveState().slideToggle('fast').slideToggle('fast',jQuery.checkState);
563 test("Chain slideToggle out", function() {
564 jQuery('#slidetoggleout div').saveState().slideToggle('fast').slideToggle('fast',jQuery.checkState);
567 jQuery.makeTest = function( text ){
568 var elem = jQuery("<div></div>")
569 .attr("id", "test" + jQuery.makeTest.id++)
574 .appendTo("#fx-tests")
576 jQuery(this).next().toggle();
583 jQuery.makeTest.id = 1;
585 test("jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function () {
589 var $checkedtest = jQuery("#checkedtest");
590 // IE6 was clearing "checked" in jQuery(elem).show("fast");
591 $checkedtest.hide().show("fast", function() {
592 ok( !! jQuery(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
593 ok( ! jQuery(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
594 ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
595 ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
600 test("animate with per-property easing", function(){
605 var _test1_called = false;
606 var _test2_called = false;
607 var _default_test_called = false;
609 jQuery.easing['_test1'] = function() {
610 _test1_called = true;
613 jQuery.easing['_test2'] = function() {
614 _test2_called = true;
617 jQuery.easing['_default_test'] = function() {
618 _default_test_called = true;
621 jQuery({a:0,b:0,c:0}).animate({
625 }, 400, '_default_test', function(){
627 ok(_test1_called, "Easing function (1) called");
628 ok(_test2_called, "Easing function (2) called");
629 ok(_default_test_called, "Easing function (_default) called");