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("animate(Hash, Object, Function)", function() {
47 var hash = {opacity: 'show'};
48 var hashCopy = jQuery.extend({}, hash);
49 jQuery('#foo').animate(hash, 0, function() {
50 equals( hash.opacity, hashCopy.opacity, 'Check if animate changed the hash parameter' );
55 test("animate negative height", function() {
58 jQuery("#foo").animate({ height: -100 }, 100, function() {
59 equals( this.offsetHeight, 0, "Verify height." );
64 /* // This test ends up being flaky depending upon the CPU load
65 test("animate option (queue === false)", function () {
71 var $foo = jQuery("#foo");
72 $foo.animate({width:'100px'}, 3000, function () {
73 // should finish after unqueued animation so second
75 same( order, [ 1, 2 ], "Animations finished in the correct order" );
78 $foo.animate({fontSize:'2em'}, {queue:false, duration:10, complete:function () {
79 // short duration and out of queue so should finish first
85 test("animate with no properties", function() {
88 var divs = jQuery("div"), count = 0;
90 divs.animate({}, function(){
94 equals( divs.length, count, "Make sure that callback is called for each element in the set." );
97 test("animate duration 0", function() {
102 var $elems = jQuery([{ a:0 },{ a:0 }]), counter = 0;
104 equals( jQuery.timers.length, 0, "Make sure no animation was running from another test" );
106 $elems.eq(0).animate( {a:1}, 0, function(){
107 ok( true, "Animate a simple property." );
111 // Failed until [6115]
112 equals( jQuery.timers.length, 0, "Make sure synchronic animations are not left on jQuery.timers" );
114 equals( counter, 1, "One synchronic animations" );
116 $elems.animate( { a:2 }, 0, function(){
117 ok( true, "Animate a second simple property." );
121 equals( counter, 3, "Multiple synchronic animations" );
123 $elems.eq(0).animate( {a:3}, 0, function(){
124 ok( true, "Animate a third simple property." );
127 $elems.eq(1).animate( {a:3}, 200, function(){
129 // Failed until [6115]
130 equals( counter, 5, "One synchronic and one asynchronic" );
134 var $elem = jQuery("<div />");
135 $elem.show(0, function(){
136 ok(true, "Show callback with no duration");
138 $elem.hide(0, function(){
139 ok(true, "Hide callback with no duration");
143 test("animate hyphenated properties", function(){
147 jQuery("#nothiddendiv")
148 .css("font-size", 10)
149 .animate({"font-size": 20}, 200, function(){
150 equals( this.style.fontSize, "20px", "The font-size property was animated." );
155 test("animate non-element", function(){
159 var obj = { test: 0 };
161 jQuery(obj).animate({test: 200}, 200, function(){
162 equals( obj.test, 200, "The custom property should be modified." );
167 test("stop()", function() {
171 var $foo = jQuery("#nothiddendiv");
173 $foo.hide().width(200).width();
175 $foo.animate({ width:'show' }, 1000);
176 setTimeout(function(){
177 var nw = $foo.width();
178 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
182 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
183 setTimeout(function(){
184 equals( nw, $foo.width(), "The animation didn't continue" );
190 test("stop() - several in queue", function() {
194 var $foo = jQuery("#nothiddendivchild");
196 $foo.hide().width(200).width();
198 $foo.animate({ width:'show' }, 1000);
199 $foo.animate({ width:'hide' }, 1000);
200 $foo.animate({ width:'show' }, 1000);
201 setTimeout(function(){
202 equals( $foo.queue().length, 3, "All 3 still in the queue" );
203 var nw = $foo.width();
204 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
208 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
209 // Disabled, being flaky
210 //equals( $foo.queue().length, 1, "The next animation continued" );
216 test("stop(clearQueue)", function() {
220 var $foo = jQuery("#nothiddendiv");
222 $foo.hide().width(200).width();
224 $foo.animate({ width:'show' }, 1000);
225 $foo.animate({ width:'hide' }, 1000);
226 $foo.animate({ width:'show' }, 1000);
227 setTimeout(function(){
228 var nw = $foo.width();
229 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
233 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
235 equals( $foo.queue().length, 0, "The animation queue was cleared" );
236 setTimeout(function(){
237 equals( nw, $foo.width(), "The animation didn't continue" );
243 test("stop(clearQueue, gotoEnd)", function() {
247 var $foo = jQuery("#nothiddendivchild");
249 $foo.hide().width(200).width();
251 $foo.animate({ width:'show' }, 1000);
252 $foo.animate({ width:'hide' }, 1000);
253 $foo.animate({ width:'show' }, 1000);
254 $foo.animate({ width:'hide' }, 1000);
255 setTimeout(function(){
256 var nw = $foo.width();
257 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
258 $foo.stop(false, true);
261 // Disabled, being flaky
262 //equals( nw, 1, "Stop() reset the animation" );
264 setTimeout(function(){
265 // Disabled, being flaky
266 //equals( $foo.queue().length, 2, "The next animation continued" );
273 test("toggle()", function() {
275 var x = jQuery("#nothiddendiv");
276 ok( x.is(":visible"), "is visible" );
278 ok( x.is(":hidden"), "is hidden" );
280 ok( x.is(":visible"), "is visible again" );
283 ok( x.is(":visible"), "is visible" );
285 ok( x.is(":hidden"), "is hidden" );
287 ok( x.is(":visible"), "is visible again" );
290 jQuery.checkOverflowDisplay = function(){
291 var o = jQuery.css( this, "overflow" );
293 equals(o, "visible", "Overflow should be visible: " + o);
294 equals(jQuery.css( this, "display" ), "inline", "Display shouldn't be tampered with.");
299 test("JS Overflow and Display", function() {
302 jQuery.makeTest( "JS Overflow and Display" )
303 .addClass("widewidth")
304 .css({ overflow: "visible", display: "inline" })
305 .addClass("widewidth")
306 .text("Some sample text.")
307 .before("text before")
309 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
312 test("CSS Overflow and Display", function() {
315 jQuery.makeTest( "CSS Overflow and Display" )
316 .addClass("overflow inline")
317 .addClass("widewidth")
318 .text("Some sample text.")
319 .before("text before")
321 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
325 "CSS Auto": function(elem,prop){
326 jQuery(elem).addClass("auto" + prop)
327 .text("This is a long string of text.");
330 "JS Auto": function(elem,prop){
331 jQuery(elem).css(prop,"auto")
332 .text("This is a long string of text.");
335 "CSS 100": function(elem,prop){
336 jQuery(elem).addClass("large" + prop);
339 "JS 100": function(elem,prop){
340 jQuery(elem).css(prop,prop == "opacity" ? 1 : "100px");
341 return prop == "opacity" ? 1 : 100;
343 "CSS 50": function(elem,prop){
344 jQuery(elem).addClass("med" + prop);
347 "JS 50": function(elem,prop){
348 jQuery(elem).css(prop,prop == "opacity" ? 0.50 : "50px");
349 return prop == "opacity" ? 0.5 : 50;
351 "CSS 0": function(elem,prop){
352 jQuery(elem).addClass("no" + prop);
355 "JS 0": function(elem,prop){
356 jQuery(elem).css(prop,prop == "opacity" ? 0 : "0px");
361 "show": function(elem,prop){
362 jQuery(elem).hide().addClass("wide"+prop);
365 "hide": function(elem,prop){
366 jQuery(elem).addClass("wide"+prop);
369 "100": function(elem,prop){
370 jQuery(elem).addClass("wide"+prop);
371 return prop == "opacity" ? 1 : 100;
373 "50": function(elem,prop){
374 return prop == "opacity" ? 0.50 : 50;
376 "0": function(elem,prop){
377 jQuery(elem).addClass("noback");
381 test(fn + " to " + tn, function() {
382 var elem = jQuery.makeTest( fn + " to " + tn );
384 var t_w = t( elem, "width" );
385 var f_w = f( elem, "width" );
386 var t_h = t( elem, "height" );
387 var f_h = f( elem, "height" );
388 var t_o = t( elem, "opacity" );
389 var f_o = f( elem, "opacity" );
393 if ( t_h == "show" ) num++;
394 if ( t_w == "show" ) num++;
395 if ( t_w == "hide"||t_w == "show" ) num++;
396 if ( t_h == "hide"||t_h == "show" ) num++;
397 if ( t_o == "hide"||t_o == "show" ) num++;
398 if ( t_w == "hide" ) num++;
399 if ( t_o.constructor == Number ) num += 2;
400 if ( t_w.constructor == Number ) num += 2;
401 if ( t_h.constructor == Number ) num +=2;
406 var anim = { width: t_w, height: t_h, opacity: t_o };
408 elem.animate(anim, 50, function(){
410 equals( this.style.display, "block", "Showing, display should block: " + this.style.display);
412 if ( t_w == "hide"||t_w == "show" )
413 equals(this.style.width.indexOf(f_w), 0, "Width must be reset to " + f_w + ": " + this.style.width);
415 if ( t_h == "hide"||t_h == "show" )
416 equals(this.style.height.indexOf(f_h), 0, "Height must be reset to " + f_h + ": " + this.style.height);
418 var cur_o = jQuery.style(this, "opacity");
419 if ( cur_o !== "" ) cur_o = parseFloat( cur_o );
421 if ( t_o == "hide"||t_o == "show" )
422 equals(cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o);
425 equals(this.style.display, "none", "Hiding, display should be none: " + this.style.display);
427 if ( t_o.constructor == Number ) {
428 equals(cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o);
430 ok(jQuery.curCSS(this, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o);
433 if ( t_w.constructor == Number ) {
434 equals(this.style.width, t_w + "px", "Final width should be " + t_w + ": " + this.style.width);
436 var cur_w = jQuery.css(this,"width");
438 ok(this.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w);
441 if ( t_h.constructor == Number ) {
442 equals(this.style.height, t_h + "px", "Final height should be " + t_h + ": " + this.style.height);
444 var cur_h = jQuery.css(this,"height");
446 ok(this.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w);
449 if ( t_h == "show" ) {
450 var old_h = jQuery.curCSS(this, "height");
451 jQuery(elem).append("<br/>Some more text<br/>and some more...");
452 ok(old_h != jQuery.css(this, "height" ), "Make sure height is auto.");
461 jQuery.fn.saveState = function(){
462 var check = ['opacity','height','width','display','overflow'];
463 expect(check.length);
466 return this.each(function(){
469 jQuery.each(check, function(i,c){
470 self.save[c] = jQuery.css(self,c);
475 jQuery.checkState = function(){
477 jQuery.each(this.save, function(c,v){
478 var cur = jQuery.css(self,c);
479 equals( v, cur, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")");
485 test("Chain fadeOut fadeIn", function() {
486 jQuery('#fadein div').saveState().fadeOut('fast').fadeIn('fast',jQuery.checkState);
488 test("Chain fadeIn fadeOut", function() {
489 jQuery('#fadeout div').saveState().fadeIn('fast').fadeOut('fast',jQuery.checkState);
492 test("Chain hide show", function() {
493 jQuery('#show div').saveState().hide('fast').show('fast',jQuery.checkState);
495 test("Chain show hide", function() {
496 jQuery('#hide div').saveState().show('fast').hide('fast',jQuery.checkState);
499 test("Chain toggle in", function() {
500 jQuery('#togglein div').saveState().toggle('fast').toggle('fast',jQuery.checkState);
502 test("Chain toggle out", function() {
503 jQuery('#toggleout div').saveState().toggle('fast').toggle('fast',jQuery.checkState);
506 test("Chain slideDown slideUp", function() {
507 jQuery('#slidedown div').saveState().slideDown('fast').slideUp('fast',jQuery.checkState);
509 test("Chain slideUp slideDown", function() {
510 jQuery('#slideup div').saveState().slideUp('fast').slideDown('fast',jQuery.checkState);
513 test("Chain slideToggle in", function() {
514 jQuery('#slidetogglein div').saveState().slideToggle('fast').slideToggle('fast',jQuery.checkState);
516 test("Chain slideToggle out", function() {
517 jQuery('#slidetoggleout div').saveState().slideToggle('fast').slideToggle('fast',jQuery.checkState);
520 jQuery.makeTest = function( text ){
521 var elem = jQuery("<div></div>")
522 .attr("id", "test" + jQuery.makeTest.id++)
527 .appendTo("#fx-tests")
529 jQuery(this).next().toggle();
536 jQuery.makeTest.id = 1;
538 test("jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function () {
542 var $checkedtest = jQuery("#checkedtest");
543 // IE6 was clearing "checked" in jQuery(elem).show("fast");
544 $checkedtest.hide().show("fast", function() {
545 ok( !! jQuery(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
546 ok( ! jQuery(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
547 ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
548 ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );