Clean trailing whitespace from all files.
[jquery.git] / test / unit / effects.js
1 module("effects");
2
3 test("sanity check", function() {
4         expect(1);
5         ok( jQuery("#dl:visible, #main:visible, #foo:visible").length === 3, "QUnit state is correct for testing effects" );
6 });
7
8 test("show()", function() {
9         expect(28);
10
11         var hiddendiv = jQuery("div.hidden");
12
13         hiddendiv.hide().show();
14
15         equals( hiddendiv.css("display"), "block", "Make sure a pre-hidden div is visible." );
16
17         var div = jQuery("<div>").hide().appendTo("body").show();
18
19         equal( div.css("display"), "block", "Make sure pre-hidden divs show" );
20
21         QUnit.reset();
22
23         hiddendiv = jQuery("div.hidden");
24
25         equal(jQuery.css( hiddendiv[0], "display"), "none", "hiddendiv is display: none");
26
27         hiddendiv.css("display", "block");
28         equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block");
29
30         hiddendiv.show();
31         equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block");
32
33         hiddendiv.css("display","");
34
35         var pass = true, div = jQuery("#main div");
36         div.show().each(function(){
37                 if ( this.style.display == "none" ) pass = false;
38         });
39         ok( pass, "Show" );
40
41         var speeds = {
42           "null speed": null,
43           "undefined speed": undefined,
44           "empty string speed": "",
45           "false speed": false
46         };
47
48         jQuery.each(speeds, function(name, speed) {
49     pass = true;
50         div.hide().show(speed).each(function() {
51                 if ( this.style.display == "none" ) pass = false;
52         });
53         ok( pass, "Show with " + name);
54   });
55
56
57         jQuery.each(speeds, function(name, speed) {
58     pass = true;
59         div.hide().show(speed, function() {
60                         pass = false;
61                 });
62                 ok( pass, "Show with " + name + " does not call animate callback" );
63         });
64
65         // #show-tests * is set display: none in CSS
66         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>');
67
68         var old = jQuery("#test-table").show().css("display") !== "table";
69         jQuery("#test-table").remove();
70
71         var test = {
72                 "div"      : "block",
73                 "p"        : "block",
74                 "a"        : "inline",
75                 "code"     : "inline",
76                 "pre"      : "block",
77                 "span"     : "inline",
78                 "table"    : old ? "block" : "table",
79                 "thead"    : old ? "block" : "table-header-group",
80                 "tbody"    : old ? "block" : "table-row-group",
81                 "tr"       : old ? "block" : "table-row",
82                 "th"       : old ? "block" : "table-cell",
83                 "td"       : old ? "block" : "table-cell",
84                 "ul"       : "block",
85                 "li"       : old ? "block" : "list-item"
86         };
87
88         jQuery.each(test, function(selector, expected) {
89                 var elem = jQuery(selector, "#show-tests").show();
90                 equals( elem.css("display"), expected, "Show using correct display type for " + selector );
91         });
92 });
93
94 test("show(Number) - other displays", function() {
95         expect(15);
96         QUnit.reset();
97         stop();
98
99         // #show-tests * is set display: none in CSS
100         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>');
101
102         var old = jQuery("#test-table").show().css("display") !== "table",
103                 num = 0;
104         jQuery("#test-table").remove();
105
106         var test = {
107                 "div"      : "block",
108                 "p"        : "block",
109                 "a"        : "inline",
110                 "code"     : "inline",
111                 "pre"      : "block",
112                 "span"     : "inline",
113                 "table"    : old ? "block" : "table",
114                 "thead"    : old ? "block" : "table-header-group",
115                 "tbody"    : old ? "block" : "table-row-group",
116                 "tr"       : old ? "block" : "table-row",
117                 "th"       : old ? "block" : "table-cell",
118                 "td"       : old ? "block" : "table-cell",
119                 "ul"       : "block",
120                 "li"       : old ? "block" : "list-item"
121         };
122
123         jQuery.each(test, function(selector, expected) {
124                 var elem = jQuery(selector, "#show-tests").show(1, function() {
125                         equals( elem.css("display"), expected, "Show using correct display type for " + selector );
126                         if ( ++num === 15 ) {
127                                 start();
128                         }
129                 });
130         });
131 });
132
133
134
135 //  Supports #7397
136 test("Persist correct display value", function() {
137   expect(3);
138         QUnit.reset();
139         stop();
140
141         // #show-tests * is set display: none in CSS
142         jQuery("#main").append('<div id="show-tests"><span style="position:absolute;">foo</span></div>');
143
144         var $span = jQuery("#show-tests span"),
145           displayNone = $span.css("display"),
146           display = '', num = 0;
147
148   $span.show();
149
150   display = $span.css("display");
151
152   $span.hide();
153
154   $span.fadeIn(100, function() {
155
156     equals($span.css("display"), display, "Expecting display: " + display);
157
158     $span.fadeOut(100, function () {
159
160       equals($span.css("display"), displayNone, "Expecting display: " + displayNone);
161
162       $span.fadeIn(100, function() {
163
164         equals($span.css("display"), display, "Expecting display: " + display);
165
166         start();
167       });
168     });
169   });
170 });
171
172 test("animate(Hash, Object, Function)", function() {
173         expect(1);
174         stop();
175         var hash = {opacity: 'show'};
176         var hashCopy = jQuery.extend({}, hash);
177         jQuery('#foo').animate(hash, 0, function() {
178                 equals( hash.opacity, hashCopy.opacity, 'Check if animate changed the hash parameter' );
179                 start();
180         });
181 });
182
183 test("animate negative height", function() {
184         expect(1);
185         stop();
186         jQuery("#foo").animate({ height: -100 }, 100, function() {
187                 equals( this.offsetHeight, 0, "Verify height." );
188                 start();
189         });
190 });
191
192 test("animate block as inline width/height", function() {
193         expect(3);
194
195         var span = jQuery("<span>").css("display", "inline-block").appendTo("body"),
196                 expected = span.css("display");
197
198         span.remove();
199
200         if ( jQuery.support.inlineBlockNeedsLayout || expected === "inline-block" ) {
201                 stop();
202
203                 jQuery("#foo").css({ display: "inline", width: '', height: '' }).animate({ width: 42, height: 42 }, 100, function() {
204                         equals( jQuery(this).css("display"), jQuery.support.inlineBlockNeedsLayout ? "inline" : "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
205                         equals( this.offsetWidth, 42, "width was animated" );
206                         equals( this.offsetHeight, 42, "height was animated" );
207                         start();
208                 });
209
210         // Browser doesn't support inline-block
211         } else {
212                 ok( true, "Browser doesn't support inline-block" );
213                 ok( true, "Browser doesn't support inline-block" );
214                 ok( true, "Browser doesn't support inline-block" );
215         }
216 });
217
218 test("animate native inline width/height", function() {
219         expect(3);
220
221         var span = jQuery("<span>").css("display", "inline-block").appendTo("body"),
222                 expected = span.css("display");
223
224         span.remove();
225
226         if ( jQuery.support.inlineBlockNeedsLayout || expected === "inline-block" ) {
227                 stop();
228                 jQuery("#foo").css({ display: "", width: '', height: '' })
229                         .append('<span>text</span>')
230                         .children('span')
231                                 .animate({ width: 42, height: 42 }, 100, function() {
232                                         equals( jQuery(this).css("display"), "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
233                                         equals( this.offsetWidth, 42, "width was animated" );
234                                         equals( this.offsetHeight, 42, "height was animated" );
235                                         start();
236                                 });
237
238         // Browser doesn't support inline-block
239         } else {
240                 ok( true, "Browser doesn't support inline-block" );
241                 ok( true, "Browser doesn't support inline-block" );
242                 ok( true, "Browser doesn't support inline-block" );
243         }
244 });
245
246 test("animate block width/height", function() {
247         expect(3);
248         stop();
249         jQuery("#foo").css({ display: "block", width: 20, height: 20 }).animate({ width: 42, height: 42 }, 100, function() {
250                 equals( jQuery(this).css("display"), "block", "inline-block was not set on block element when animating width/height" );
251                 equals( this.offsetWidth, 42, "width was animated" );
252                 equals( this.offsetHeight, 42, "height was animated" );
253                 start();
254         });
255 });
256
257 test("animate table width/height", function() {
258         expect(1);
259         stop();
260
261         var displayMode = jQuery("#table").css("display") !== "table" ? "block" : "table";
262
263         jQuery("#table").animate({ width: 42, height: 42 }, 100, function() {
264                 equals( jQuery(this).css("display"), displayMode, "display mode is correct" );
265                 start();
266         });
267 });
268
269 test("animate table-row width/height", function() {
270         expect(3);
271         stop();
272         var tr = jQuery("#table")
273                 .attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 })
274                 .html("<tr style='height:42px;'><td style='padding:0;'><div style='width:20px;height:20px;'></div></td></tr>")
275                 .find("tr");
276
277         // IE<8 uses “block” instead of the correct display type
278         var displayMode = tr.css("display") !== "table-row" ? "block" : "table-row";
279
280         tr.animate({ width: 10, height: 10 }, 100, function() {
281                 equals( jQuery(this).css("display"), displayMode, "display mode is correct" );
282                 equals( this.offsetWidth, 20, "width animated to shrink wrap point" );
283                 equals( this.offsetHeight, 20, "height animated to shrink wrap point" );
284                 start();
285         });
286 });
287
288 test("animate table-cell width/height", function() {
289         expect(3);
290         stop();
291         var td = jQuery("#table")
292                 .attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 })
293                 .html("<tr><td style='width:42px;height:42px;padding:0;'><div style='width:20px;height:20px;'></div></td></tr>")
294                 .find("td");
295
296         // IE<8 uses “block” instead of the correct display type
297         var displayMode = td.css("display") !== "table-cell" ? "block" : "table-cell";
298
299         td.animate({ width: 10, height: 10 }, 100, function() {
300                 equals( jQuery(this).css("display"), displayMode, "display mode is correct" );
301                 equals( this.offsetWidth, 20, "width animated to shrink wrap point" );
302                 equals( this.offsetHeight, 20, "height animated to shrink wrap point" );
303                 start();
304         });
305 });
306
307 test("animate resets overflow-x and overflow-y when finished", function() {
308         expect(2);
309         stop();
310         jQuery("#foo")
311                 .css({ display: "block", width: 20, height: 20, overflowX: "visible", overflowY: "auto" })
312                 .animate({ width: 42, height: 42 }, 100, function() {
313                         equals( this.style.overflowX, "visible", "overflow-x is visible" );
314                         equals( this.style.overflowY, "auto", "overflow-y is auto" );
315                         start();
316                 });
317 });
318
319 /* // This test ends up being flaky depending upon the CPU load
320 test("animate option (queue === false)", function () {
321         expect(1);
322         stop();
323
324         var order = [];
325
326         var $foo = jQuery("#foo");
327         $foo.animate({width:'100px'}, 3000, function () {
328                 // should finish after unqueued animation so second
329                 order.push(2);
330                 same( order, [ 1, 2 ], "Animations finished in the correct order" );
331                 start();
332         });
333         $foo.animate({fontSize:'2em'}, {queue:false, duration:10, complete:function () {
334                 // short duration and out of queue so should finish first
335                 order.push(1);
336         }});
337 });
338 */
339
340 test("animate with no properties", function() {
341         expect(2);
342
343         var divs = jQuery("div"), count = 0;
344
345         divs.animate({}, function(){
346                 count++;
347         });
348
349         equals( divs.length, count, "Make sure that callback is called for each element in the set." );
350
351         stop();
352
353         var foo = jQuery("#foo");
354
355         foo.animate({});
356         foo.animate({top: 10}, 100, function(){
357                 ok( true, "Animation was properly dequeued." );
358                 start();
359         });
360 });
361
362 test("animate duration 0", function() {
363         expect(11);
364
365         stop();
366
367         var $elems = jQuery([{ a:0 },{ a:0 }]), counter = 0;
368
369         equals( jQuery.timers.length, 0, "Make sure no animation was running from another test" );
370
371         $elems.eq(0).animate( {a:1}, 0, function(){
372                 ok( true, "Animate a simple property." );
373                 counter++;
374         });
375
376         // Failed until [6115]
377         equals( jQuery.timers.length, 0, "Make sure synchronic animations are not left on jQuery.timers" );
378
379         equals( counter, 1, "One synchronic animations" );
380
381         $elems.animate( { a:2 }, 0, function(){
382                 ok( true, "Animate a second simple property." );
383                 counter++;
384         });
385
386         equals( counter, 3, "Multiple synchronic animations" );
387
388         $elems.eq(0).animate( {a:3}, 0, function(){
389                 ok( true, "Animate a third simple property." );
390                 counter++;
391         });
392         $elems.eq(1).animate( {a:3}, 200, function(){
393                 counter++;
394                 // Failed until [6115]
395                 equals( counter, 5, "One synchronic and one asynchronic" );
396                 start();
397         });
398
399         var $elem = jQuery("<div />");
400         $elem.show(0, function(){
401                 ok(true, "Show callback with no duration");
402         });
403         $elem.hide(0, function(){
404                 ok(true, "Hide callback with no duration");
405         });
406 });
407
408 test("animate hyphenated properties", function(){
409         expect(1);
410         stop();
411
412         jQuery("#nothiddendiv")
413                 .css("font-size", 10)
414                 .animate({"font-size": 20}, 200, function(){
415                         equals( this.style.fontSize, "20px", "The font-size property was animated." );
416                         start();
417                 });
418 });
419
420 test("animate non-element", function(){
421         expect(1);
422         stop();
423
424         var obj = { test: 0 };
425
426         jQuery(obj).animate({test: 200}, 200, function(){
427                 equals( obj.test, 200, "The custom property should be modified." );
428                 start();
429         });
430 });
431
432 test("stop()", function() {
433         expect(3);
434         stop();
435
436         var $foo = jQuery("#nothiddendiv");
437         var w = 0;
438         $foo.hide().width(200).width();
439
440         $foo.animate({ width:'show' }, 1000);
441         setTimeout(function(){
442                 var nw = $foo.width();
443                 notEqual( nw, w, "An animation occurred " + nw + "px " + w + "px");
444                 $foo.stop();
445
446                 nw = $foo.width();
447                 notEqual( nw, w, "Stop didn't reset the animation " + nw + "px " + w + "px");
448                 setTimeout(function(){
449                         equals( nw, $foo.width(), "The animation didn't continue" );
450                         start();
451                 }, 100);
452         }, 100);
453 });
454
455 test("stop() - several in queue", function() {
456         expect(3);
457         stop();
458
459         var $foo = jQuery("#nothiddendivchild");
460         var w = 0;
461         $foo.hide().width(200).width();
462
463         $foo.animate({ width:'show' }, 1000);
464         $foo.animate({ width:'hide' }, 1000);
465         $foo.animate({ width:'show' }, 1000);
466         setTimeout(function(){
467                 equals( $foo.queue().length, 3, "All 3 still in the queue" );
468                 var nw = $foo.width();
469                 notEqual( nw, w, "An animation occurred " + nw + "px " + w + "px");
470                 $foo.stop();
471
472                 nw = $foo.width();
473                 notEqual( nw, w, "Stop didn't reset the animation " + nw + "px " + w + "px");
474
475                 $foo.stop(true);
476                 start();
477         }, 100);
478 });
479
480 test("stop(clearQueue)", function() {
481         expect(4);
482         stop();
483
484         var $foo = jQuery("#nothiddendiv");
485         var w = 0;
486         $foo.hide().width(200).width();
487
488         $foo.animate({ width:'show' }, 1000);
489         $foo.animate({ width:'hide' }, 1000);
490         $foo.animate({ width:'show' }, 1000);
491         setTimeout(function(){
492                 var nw = $foo.width();
493                 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
494                 $foo.stop(true);
495
496                 nw = $foo.width();
497                 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
498
499                 equals( $foo.queue().length, 0, "The animation queue was cleared" );
500                 setTimeout(function(){
501                         equals( nw, $foo.width(), "The animation didn't continue" );
502                         start();
503                 }, 100);
504         }, 100);
505 });
506
507 test("stop(clearQueue, gotoEnd)", function() {
508         expect(1);
509         stop();
510
511         var $foo = jQuery("#nothiddendivchild");
512         var w = 0;
513         $foo.hide().width(200).width();
514
515         $foo.animate({ width:'show' }, 1000);
516         $foo.animate({ width:'hide' }, 1000);
517         $foo.animate({ width:'show' }, 1000);
518         $foo.animate({ width:'hide' }, 1000);
519         setTimeout(function(){
520                 var nw = $foo.width();
521                 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
522                 $foo.stop(false, true);
523
524                 nw = $foo.width();
525                 // Disabled, being flaky
526                 //equals( nw, 1, "Stop() reset the animation" );
527
528                 setTimeout(function(){
529                         // Disabled, being flaky
530                         //equals( $foo.queue().length, 2, "The next animation continued" );
531                         $foo.stop(true);
532                         start();
533                 }, 100);
534         }, 100);
535 });
536
537 test("toggle()", function() {
538         expect(6);
539         var x = jQuery("#nothiddendiv");
540         ok( x.is(":visible"), "is visible" );
541         x.toggle();
542         ok( x.is(":hidden"), "is hidden" );
543         x.toggle();
544         ok( x.is(":visible"), "is visible again" );
545
546         x.toggle(true);
547         ok( x.is(":visible"), "is visible" );
548         x.toggle(false);
549         ok( x.is(":hidden"), "is hidden" );
550         x.toggle(true);
551         ok( x.is(":visible"), "is visible again" );
552 });
553
554 jQuery.checkOverflowDisplay = function(){
555         var o = jQuery.css( this, "overflow" );
556
557         equals(o, "visible", "Overflow should be visible: " + o);
558         equals(jQuery.css( this, "display" ), "inline", "Display shouldn't be tampered with.");
559
560         start();
561 }
562
563 test("JS Overflow and Display", function() {
564         expect(2);
565         stop();
566         jQuery.makeTest( "JS Overflow and Display" )
567                 .addClass("widewidth")
568                 .css({ overflow: "visible", display: "inline" })
569                 .addClass("widewidth")
570                 .text("Some sample text.")
571                 .before("text before")
572                 .after("text after")
573                 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
574 });
575
576 test("CSS Overflow and Display", function() {
577         expect(2);
578         stop();
579         jQuery.makeTest( "CSS Overflow and Display" )
580                 .addClass("overflow inline")
581                 .addClass("widewidth")
582                 .text("Some sample text.")
583                 .before("text before")
584                 .after("text after")
585                 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
586 });
587
588 jQuery.each( {
589         "CSS Auto": function(elem,prop){
590                 jQuery(elem).addClass("auto" + prop)
591                         .text("This is a long string of text.");
592                 return "";
593         },
594         "JS Auto": function(elem,prop){
595                 jQuery(elem).css(prop,"")
596                         .text("This is a long string of text.");
597                 return "";
598         },
599         "CSS 100": function(elem,prop){
600                 jQuery(elem).addClass("large" + prop);
601                 return "";
602         },
603         "JS 100": function(elem,prop){
604                 jQuery(elem).css(prop,prop == "opacity" ? 1 : "100px");
605                 return prop == "opacity" ? 1 : 100;
606         },
607         "CSS 50": function(elem,prop){
608                 jQuery(elem).addClass("med" + prop);
609                 return "";
610         },
611         "JS 50": function(elem,prop){
612                 jQuery(elem).css(prop,prop == "opacity" ? 0.50 : "50px");
613                 return prop == "opacity" ? 0.5 : 50;
614         },
615         "CSS 0": function(elem,prop){
616                 jQuery(elem).addClass("no" + prop);
617                 return "";
618         },
619         "JS 0": function(elem,prop){
620                 jQuery(elem).css(prop,prop == "opacity" ? 0 : "0px");
621                 return 0;
622         }
623 }, function(fn, f){
624         jQuery.each( {
625                 "show": function(elem,prop){
626                         jQuery(elem).hide().addClass("wide"+prop);
627                         return "show";
628                 },
629                 "hide": function(elem,prop){
630                         jQuery(elem).addClass("wide"+prop);
631                         return "hide";
632                 },
633                 "100": function(elem,prop){
634                         jQuery(elem).addClass("wide"+prop);
635                         return prop == "opacity" ? 1 : 100;
636                 },
637                 "50": function(elem,prop){
638                         return prop == "opacity" ? 0.50 : 50;
639                 },
640                 "0": function(elem,prop){
641                         jQuery(elem).addClass("noback");
642                         return 0;
643                 }
644         }, function(tn, t){
645                 test(fn + " to " + tn, function() {
646                         var elem = jQuery.makeTest( fn + " to " + tn );
647
648                         var t_w = t( elem, "width" );
649                         var f_w = f( elem, "width" );
650                         var t_h = t( elem, "height" );
651                         var f_h = f( elem, "height" );
652                         var t_o = t( elem, "opacity" );
653                         var f_o = f( elem, "opacity" );
654
655                         var num = 0;
656
657                         if ( t_h == "show" ) num++;
658                         if ( t_w == "show" ) num++;
659                         if ( t_w == "hide"||t_w == "show" ) num++;
660                         if ( t_h == "hide"||t_h == "show" ) num++;
661                         if ( t_o == "hide"||t_o == "show" ) num++;
662                         if ( t_w == "hide" ) num++;
663                         if ( t_o.constructor == Number ) num += 2;
664                         if ( t_w.constructor == Number ) num += 2;
665                         if ( t_h.constructor == Number ) num +=2;
666
667                         expect(num);
668                         stop();
669
670                         var anim = { width: t_w, height: t_h, opacity: t_o };
671
672                         elem.animate(anim, 50, function(){
673                                 if ( t_w == "show" )
674                                         equals( this.style.display, "block", "Showing, display should block: " + this.style.display);
675
676                                 if ( t_w == "hide"||t_w == "show" )
677                                         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);
678
679                                 if ( t_h == "hide"||t_h == "show" )
680                                         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);
681
682                                 var cur_o = jQuery.style(this, "opacity");
683
684                                 if ( t_o == "hide" || t_o == "show" )
685                                         equals(cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o);
686
687                                 if ( t_w == "hide" )
688                                         equals(this.style.display, "none", "Hiding, display should be none: " + this.style.display);
689
690                                 if ( t_o.constructor == Number ) {
691                                         equals(cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o);
692
693                                         ok(jQuery.css(this, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o);
694                                 }
695
696                                 if ( t_w.constructor == Number ) {
697                                         equals(this.style.width, t_w + "px", "Final width should be " + t_w + ": " + this.style.width);
698
699                                         var cur_w = jQuery.css(this,"width");
700
701                                         ok(this.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w);
702                                 }
703
704                                 if ( t_h.constructor == Number ) {
705                                         equals(this.style.height, t_h + "px", "Final height should be " + t_h + ": " + this.style.height);
706
707                                         var cur_h = jQuery.css(this,"height");
708
709                                         ok(this.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w);
710                                 }
711
712                                 if ( t_h == "show" ) {
713                                         var old_h = jQuery.css(this, "height");
714                                         jQuery(this).append("<br/>Some more text<br/>and some more...");
715
716                                         if ( /Auto/.test( fn ) ) {
717                                                 notEqual(jQuery.css(this, "height"), old_h, "Make sure height is auto.");
718                                         } else {
719                                                 equals(jQuery.css(this, "height"), old_h, "Make sure height is not auto.");
720                                         }
721                                 }
722
723                                 start();
724                         });
725                 });
726         });
727 });
728
729 jQuery.fn.saveState = function(hiddenOverflow){
730         var check = ['opacity','height','width','display','overflow'];
731         expect(check.length);
732
733         stop();
734         return this.each(function(){
735                 var self = this;
736                 self.save = {};
737                 jQuery.each(check, function(i,c){
738                         self.save[c] = c === "overflow" && hiddenOverflow ? "hidden" : self.style[ c ] || jQuery.css(self,c);
739                 });
740         });
741 };
742
743 jQuery.checkState = function(){
744         var self = this;
745         jQuery.each(this.save, function(c,v){
746                 var cur = self.style[ c ] || jQuery.css(self, c);
747                 equals( cur, v, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")");
748         });
749         start();
750 }
751
752 // Chaining Tests
753 test("Chain fadeOut fadeIn", function() {
754         jQuery('#fadein div').saveState().fadeOut('fast').fadeIn('fast',jQuery.checkState);
755 });
756 test("Chain fadeIn fadeOut", function() {
757         jQuery('#fadeout div').saveState().fadeIn('fast').fadeOut('fast',jQuery.checkState);
758 });
759
760 test("Chain hide show", function() {
761         jQuery('#show div').saveState(jQuery.support.shrinkWrapBlocks).hide('fast').show('fast',jQuery.checkState);
762 });
763 test("Chain show hide", function() {
764         jQuery('#hide div').saveState(jQuery.support.shrinkWrapBlocks).show('fast').hide('fast',jQuery.checkState);
765 });
766 test("Chain show hide with easing and callback", function() {
767         jQuery('#hide div').saveState().show('fast').hide('fast','linear',jQuery.checkState);
768 });
769
770 test("Chain toggle in", function() {
771         jQuery('#togglein div').saveState(jQuery.support.shrinkWrapBlocks).toggle('fast').toggle('fast',jQuery.checkState);
772 });
773 test("Chain toggle out", function() {
774         jQuery('#toggleout div').saveState(jQuery.support.shrinkWrapBlocks).toggle('fast').toggle('fast',jQuery.checkState);
775 });
776 test("Chain toggle out with easing and callback", function() {
777  jQuery('#toggleout div').saveState(jQuery.support.shrinkWrapBlocks).toggle('fast').toggle('fast','linear',jQuery.checkState);
778 });
779 test("Chain slideDown slideUp", function() {
780         jQuery('#slidedown div').saveState(jQuery.support.shrinkWrapBlocks).slideDown('fast').slideUp('fast',jQuery.checkState);
781 });
782 test("Chain slideUp slideDown", function() {
783         jQuery('#slideup div').saveState(jQuery.support.shrinkWrapBlocks).slideUp('fast').slideDown('fast',jQuery.checkState);
784 });
785 test("Chain slideUp slideDown with easing and callback", function() {
786         jQuery('#slideup div').saveState(jQuery.support.shrinkWrapBlocks).slideUp('fast').slideDown('fast','linear',jQuery.checkState);
787 });
788
789 test("Chain slideToggle in", function() {
790         jQuery('#slidetogglein div').saveState(jQuery.support.shrinkWrapBlocks).slideToggle('fast').slideToggle('fast',jQuery.checkState);
791 });
792 test("Chain slideToggle out", function() {
793         jQuery('#slidetoggleout div').saveState(jQuery.support.shrinkWrapBlocks).slideToggle('fast').slideToggle('fast',jQuery.checkState);
794 });
795
796 test("Chain fadeToggle in", function() {
797         jQuery('#fadetogglein div').saveState().fadeToggle('fast').fadeToggle('fast',jQuery.checkState);
798 });
799 test("Chain fadeToggle out", function() {
800         jQuery('#fadetoggleout div').saveState().fadeToggle('fast').fadeToggle('fast',jQuery.checkState);
801 });
802
803 test("Chain fadeTo 0.5 1.0 with easing and callback)", function() {
804         jQuery('#fadeto div').saveState().fadeTo('fast',0.5).fadeTo('fast',1.0,'linear',jQuery.checkState);
805 });
806
807 jQuery.makeTest = function( text ){
808         var elem = jQuery("<div></div>")
809                 .attr("id", "test" + jQuery.makeTest.id++)
810                 .addClass("box");
811
812         jQuery("<h4></h4>")
813                 .text( text )
814                 .appendTo("#fx-tests")
815                 .click(function(){
816                         jQuery(this).next().toggle();
817                 })
818                 .after( elem );
819
820         return elem;
821 }
822
823 jQuery.makeTest.id = 1;
824
825 test("jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function () {
826         expect(4);
827   stop();
828
829         var $checkedtest = jQuery("#checkedtest");
830         // IE6 was clearing "checked" in jQuery(elem).show("fast");
831         $checkedtest.hide().show("fast", function() {
832         ok( !! jQuery(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
833         ok( ! jQuery(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
834         ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
835         ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
836         start();
837         });
838 });
839
840 test("animate with per-property easing", function(){
841
842         expect(3);
843         stop();
844
845         var _test1_called = false;
846         var _test2_called = false;
847         var _default_test_called = false;
848
849         jQuery.easing['_test1'] = function() {
850                 _test1_called = true;
851         };
852
853         jQuery.easing['_test2'] = function() {
854                 _test2_called = true;
855         };
856
857         jQuery.easing['_default_test'] = function() {
858                 _default_test_called = true;
859         };
860
861         jQuery({a:0,b:0,c:0}).animate({
862                 a: [100, '_test1'],
863                 b: [100, '_test2'],
864                 c: 100
865         }, 400, '_default_test', function(){
866                 start();
867                 ok(_test1_called, "Easing function (1) called");
868                 ok(_test2_called, "Easing function (2) called");
869                 ok(_default_test_called, "Easing function (_default) called");
870         });
871
872 });
873
874 test("hide hidden elements (bug #7141)", function() {
875         expect(3);
876         QUnit.reset();
877
878         var div = jQuery("<div style='display:none'></div>").appendTo("#main");
879         equals( div.css("display"), "none", "Element is hidden by default" );
880         div.hide();
881         ok( !div.data("olddisplay"), "olddisplay is undefined after hiding an already-hidden element" );
882         div.show();
883         equals( div.css("display"), "block", "Show a double-hidden element" );
884
885         div.remove();
886 });
887
888 test("hide hidden elements, with animation (bug #7141)", function() {
889         expect(3);
890         QUnit.reset();
891         stop();
892
893         var div = jQuery("<div style='display:none'></div>").appendTo("#main");
894         equals( div.css("display"), "none", "Element is hidden by default" );
895         div.hide(1, function () {
896                 ok( !div.data("olddisplay"), "olddisplay is undefined after hiding an already-hidden element" );
897                 div.show(1, function () {
898                         equals( div.css("display"), "block", "Show a double-hidden element" );
899                         start();
900                 });
901         });
902 });