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 /* // This test ends up being flaky depending upon the CPU load
56 test("animate option (queue === false)", function () {
62 var $foo = jQuery("#foo");
63 $foo.animate({width:'100px'}, 3000, function () {
64 // should finish after unqueued animation so second
66 same( order, [ 1, 2 ], "Animations finished in the correct order" );
69 $foo.animate({fontSize:'2em'}, {queue:false, duration:10, complete:function () {
70 // short duration and out of queue so should finish first
76 test("animate with no properties", function() {
79 var divs = jQuery("div"), count = 0;
81 divs.animate({}, function(){
85 equals( divs.length, count, "Make sure that callback is called for each element in the set." );
88 test("animate duration 0", function() {
93 var $elems = jQuery([{ a:0 },{ a:0 }]), counter = 0;
95 equals( jQuery.timers.length, 0, "Make sure no animation was running from another test" );
97 $elems.eq(0).animate( {a:1}, 0, function(){
98 ok( true, "Animate a simple property." );
102 // Failed until [6115]
103 equals( jQuery.timers.length, 0, "Make sure synchronic animations are not left on jQuery.timers" );
105 equals( counter, 1, "One synchronic animations" );
107 $elems.animate( { a:2 }, 0, function(){
108 ok( true, "Animate a second simple property." );
112 equals( counter, 3, "Multiple synchronic animations" );
114 $elems.eq(0).animate( {a:3}, 0, function(){
115 ok( true, "Animate a third simple property." );
118 $elems.eq(1).animate( {a:3}, 200, function(){
120 // Failed until [6115]
121 equals( counter, 5, "One synchronic and one asynchronic" );
125 var $elem = jQuery("<div />");
126 $elem.show(0, function(){
127 ok(true, "Show callback with no duration");
129 $elem.hide(0, function(){
130 ok(true, "Hide callback with no duration");
134 test("animate hyphenated properties", function(){
138 jQuery("#nothiddendiv")
139 .css("font-size", 10)
140 .animate({"font-size": 20}, 200, function(){
141 equals( this.style.fontSize, "20px", "The font-size property was animated." );
146 test("animate non-element", function(){
150 var obj = { test: 0 };
152 jQuery(obj).animate({test: 200}, 200, function(){
153 equals( obj.test, 200, "The custom property should be modified." );
158 test("stop()", function() {
162 var $foo = jQuery("#nothiddendiv");
164 $foo.hide().width(200).width();
166 $foo.animate({ width:'show' }, 1000);
167 setTimeout(function(){
168 var nw = $foo.width();
169 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
173 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
174 setTimeout(function(){
175 equals( nw, $foo.width(), "The animation didn't continue" );
181 test("stop() - several in queue", function() {
185 var $foo = jQuery("#nothiddendivchild");
187 $foo.hide().width(200).width();
189 $foo.animate({ width:'show' }, 1000);
190 $foo.animate({ width:'hide' }, 1000);
191 $foo.animate({ width:'show' }, 1000);
192 setTimeout(function(){
193 equals( $foo.queue().length, 3, "All 3 still in the queue" );
194 var nw = $foo.width();
195 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
199 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
200 // Disabled, being flaky
201 //equals( $foo.queue().length, 1, "The next animation continued" );
207 test("stop(clearQueue)", function() {
211 var $foo = jQuery("#nothiddendiv");
213 $foo.hide().width(200).width();
215 $foo.animate({ width:'show' }, 1000);
216 $foo.animate({ width:'hide' }, 1000);
217 $foo.animate({ width:'show' }, 1000);
218 setTimeout(function(){
219 var nw = $foo.width();
220 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
224 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
226 equals( $foo.queue().length, 0, "The animation queue was cleared" );
227 setTimeout(function(){
228 equals( nw, $foo.width(), "The animation didn't continue" );
234 test("stop(clearQueue, gotoEnd)", function() {
238 var $foo = jQuery("#nothiddendivchild");
240 $foo.hide().width(200).width();
242 $foo.animate({ width:'show' }, 1000);
243 $foo.animate({ width:'hide' }, 1000);
244 $foo.animate({ width:'show' }, 1000);
245 $foo.animate({ width:'hide' }, 1000);
246 setTimeout(function(){
247 var nw = $foo.width();
248 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
249 $foo.stop(false, true);
252 // Disabled, being flaky
253 //equals( nw, 1, "Stop() reset the animation" );
255 setTimeout(function(){
256 // Disabled, being flaky
257 //equals( $foo.queue().length, 2, "The next animation continued" );
264 test("toggle()", function() {
266 var x = jQuery("#nothiddendiv");
267 ok( x.is(":visible"), "is visible" );
269 ok( x.is(":hidden"), "is hidden" );
271 ok( x.is(":visible"), "is visible again" );
274 ok( x.is(":visible"), "is visible" );
276 ok( x.is(":hidden"), "is hidden" );
278 ok( x.is(":visible"), "is visible again" );
281 jQuery.checkOverflowDisplay = function(){
282 var o = jQuery.css( this, "overflow" );
284 equals(o, "visible", "Overflow should be visible: " + o);
285 equals(jQuery.css( this, "display" ), "inline", "Display shouldn't be tampered with.");
290 test("JS Overflow and Display", function() {
293 jQuery.makeTest( "JS Overflow and Display" )
294 .addClass("widewidth")
295 .css({ overflow: "visible", display: "inline" })
296 .addClass("widewidth")
297 .text("Some sample text.")
298 .before("text before")
300 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
303 test("CSS Overflow and Display", function() {
306 jQuery.makeTest( "CSS Overflow and Display" )
307 .addClass("overflow inline")
308 .addClass("widewidth")
309 .text("Some sample text.")
310 .before("text before")
312 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
316 "CSS Auto": function(elem,prop){
317 jQuery(elem).addClass("auto" + prop)
318 .text("This is a long string of text.");
321 "JS Auto": function(elem,prop){
322 jQuery(elem).css(prop,"auto")
323 .text("This is a long string of text.");
326 "CSS 100": function(elem,prop){
327 jQuery(elem).addClass("large" + prop);
330 "JS 100": function(elem,prop){
331 jQuery(elem).css(prop,prop == "opacity" ? 1 : "100px");
332 return prop == "opacity" ? 1 : 100;
334 "CSS 50": function(elem,prop){
335 jQuery(elem).addClass("med" + prop);
338 "JS 50": function(elem,prop){
339 jQuery(elem).css(prop,prop == "opacity" ? 0.50 : "50px");
340 return prop == "opacity" ? 0.5 : 50;
342 "CSS 0": function(elem,prop){
343 jQuery(elem).addClass("no" + prop);
346 "JS 0": function(elem,prop){
347 jQuery(elem).css(prop,prop == "opacity" ? 0 : "0px");
352 "show": function(elem,prop){
353 jQuery(elem).hide().addClass("wide"+prop);
356 "hide": function(elem,prop){
357 jQuery(elem).addClass("wide"+prop);
360 "100": function(elem,prop){
361 jQuery(elem).addClass("wide"+prop);
362 return prop == "opacity" ? 1 : 100;
364 "50": function(elem,prop){
365 return prop == "opacity" ? 0.50 : 50;
367 "0": function(elem,prop){
368 jQuery(elem).addClass("noback");
372 test(fn + " to " + tn, function() {
373 var elem = jQuery.makeTest( fn + " to " + tn );
375 var t_w = t( elem, "width" );
376 var f_w = f( elem, "width" );
377 var t_h = t( elem, "height" );
378 var f_h = f( elem, "height" );
379 var t_o = t( elem, "opacity" );
380 var f_o = f( elem, "opacity" );
384 if ( t_h == "show" ) num++;
385 if ( t_w == "show" ) num++;
386 if ( t_w == "hide"||t_w == "show" ) num++;
387 if ( t_h == "hide"||t_h == "show" ) num++;
388 if ( t_o == "hide"||t_o == "show" ) num++;
389 if ( t_w == "hide" ) num++;
390 if ( t_o.constructor == Number ) num += 2;
391 if ( t_w.constructor == Number ) num += 2;
392 if ( t_h.constructor == Number ) num +=2;
397 var anim = { width: t_w, height: t_h, opacity: t_o };
399 elem.animate(anim, 50, function(){
401 equals( this.style.display, "block", "Showing, display should block: " + this.style.display);
403 if ( t_w == "hide"||t_w == "show" )
404 equals(this.style.width.indexOf(f_w), 0, "Width must be reset to " + f_w + ": " + this.style.width);
406 if ( t_h == "hide"||t_h == "show" )
407 equals(this.style.height.indexOf(f_h), 0, "Height must be reset to " + f_h + ": " + this.style.height);
409 var cur_o = jQuery.style(this, "opacity");
410 if ( cur_o !== "" ) cur_o = parseFloat( cur_o );
412 if ( t_o == "hide"||t_o == "show" )
413 equals(cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o);
416 equals(this.style.display, "none", "Hiding, display should be none: " + this.style.display);
418 if ( t_o.constructor == Number ) {
419 equals(cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o);
421 ok(jQuery.curCSS(this, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o);
424 if ( t_w.constructor == Number ) {
425 equals(this.style.width, t_w + "px", "Final width should be " + t_w + ": " + this.style.width);
427 var cur_w = jQuery.css(this,"width");
429 ok(this.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w);
432 if ( t_h.constructor == Number ) {
433 equals(this.style.height, t_h + "px", "Final height should be " + t_h + ": " + this.style.height);
435 var cur_h = jQuery.css(this,"height");
437 ok(this.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w);
440 if ( t_h == "show" ) {
441 var old_h = jQuery.curCSS(this, "height");
442 jQuery(elem).append("<br/>Some more text<br/>and some more...");
443 ok(old_h != jQuery.css(this, "height" ), "Make sure height is auto.");
452 jQuery.fn.saveState = function(){
453 var check = ['opacity','height','width','display','overflow'];
454 expect(check.length);
457 return this.each(function(){
460 jQuery.each(check, function(i,c){
461 self.save[c] = jQuery.css(self,c);
466 jQuery.checkState = function(){
468 jQuery.each(this.save, function(c,v){
469 var cur = jQuery.css(self,c);
470 equals( v, cur, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")");
476 test("Chain fadeOut fadeIn", function() {
477 jQuery('#fadein div').saveState().fadeOut('fast').fadeIn('fast',jQuery.checkState);
479 test("Chain fadeIn fadeOut", function() {
480 jQuery('#fadeout div').saveState().fadeIn('fast').fadeOut('fast',jQuery.checkState);
483 test("Chain hide show", function() {
484 jQuery('#show div').saveState().hide('fast').show('fast',jQuery.checkState);
486 test("Chain show hide", function() {
487 jQuery('#hide div').saveState().show('fast').hide('fast',jQuery.checkState);
490 test("Chain toggle in", function() {
491 jQuery('#togglein div').saveState().toggle('fast').toggle('fast',jQuery.checkState);
493 test("Chain toggle out", function() {
494 jQuery('#toggleout div').saveState().toggle('fast').toggle('fast',jQuery.checkState);
497 test("Chain slideDown slideUp", function() {
498 jQuery('#slidedown div').saveState().slideDown('fast').slideUp('fast',jQuery.checkState);
500 test("Chain slideUp slideDown", function() {
501 jQuery('#slideup div').saveState().slideUp('fast').slideDown('fast',jQuery.checkState);
504 test("Chain slideToggle in", function() {
505 jQuery('#slidetogglein div').saveState().slideToggle('fast').slideToggle('fast',jQuery.checkState);
507 test("Chain slideToggle out", function() {
508 jQuery('#slidetoggleout div').saveState().slideToggle('fast').slideToggle('fast',jQuery.checkState);
511 jQuery.makeTest = function( text ){
512 var elem = jQuery("<div></div>")
513 .attr("id", "test" + jQuery.makeTest.id++)
518 .appendTo("#fx-tests")
520 jQuery(this).next().toggle();
527 jQuery.makeTest.id = 1;