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;
11 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>');
13 var old = jQuery("#show-tests table").show().css("display") !== "table";
22 "table" : old ? "block" : "table",
23 "thead" : old ? "block" : "table-header-group",
24 "tbody" : old ? "block" : "table-row-group",
25 "tr" : old ? "block" : "table-row",
26 "th" : old ? "block" : "table-cell",
27 "td" : old ? "block" : "table-cell",
29 "li" : old ? "block" : "list-item"
32 jQuery.each(test, function(selector, expected) {
33 var elem = jQuery(selector, "#show-tests").show();
34 equals( elem.css("display"), expected, "Show using correct display type for " + selector );
38 test("animate(Hash, Object, Function)", function() {
41 var hash = {opacity: 'show'};
42 var hashCopy = jQuery.extend({}, hash);
43 jQuery('#foo').animate(hash, 0, function() {
44 equals( hash.opacity, hashCopy.opacity, 'Check if animate changed the hash parameter' );
49 test("animate option (queue === false)", function () {
55 var $foo = jQuery("#foo");
56 $foo.animate({width:'100px'}, 200, function () {
57 // should finish after unqueued animation so second
60 $foo.animate({fontSize:'2em'}, {queue:false, duration:10, complete:function () {
61 // short duration and out of queue so should finish first
64 $foo.animate({height:'100px'}, 10, function() {
65 // queued behind the first animation so should finish third
67 isSet( order, [ 1, 2, 3], "Animations finished in the correct order" );
72 test("animate duration 0", function() {
77 var $elems = jQuery([{ a:0 },{ a:0 }]),
83 equals( jQuery.timers.length, 0, "Make sure no animation was running from another test" );
85 $elems.eq(0).animate( {a:1}, 0, count );
87 // Failed until [6115]
88 equals( jQuery.timers.length, 0, "Make sure synchronic animations are not left on jQuery.timers" );
90 equals( counter, 1, "One synchronic animations" );
92 $elems.animate( { a:2 }, 0, count );
94 equals( counter, 3, "Multiple synchronic animations" );
96 $elems.eq(0).animate( {a:3}, 0, count );
97 $elems.eq(1).animate( {a:3}, 20, function(){
99 // Failed until [6115]
100 equals( counter, 5, "One synchronic and one asynchronic" );
105 test("animate non-element", function(){
109 var obj = { test: 0 };
111 jQuery(obj).animate({test: 200}, 200, function(){
112 equals( obj.test, 200, "The custom property should be modified." );
117 test("stop()", function() {
121 var $foo = jQuery("#nothiddendiv");
123 $foo.hide().width(200).width();
125 $foo.animate({ width:'show' }, 1000);
126 setTimeout(function(){
127 var nw = $foo.width();
128 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
132 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
133 setTimeout(function(){
134 equals( nw, $foo.width(), "The animation didn't continue" );
140 test("stop() - several in queue", function() {
144 var $foo = jQuery("#nothiddendivchild");
146 $foo.hide().width(200).width();
148 $foo.animate({ width:'show' }, 1000);
149 $foo.animate({ width:'hide' }, 1000);
150 $foo.animate({ width:'show' }, 1000);
151 setTimeout(function(){
152 equals( $foo.queue().length, 3, "All 3 still in the queue" );
153 var nw = $foo.width();
154 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
158 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
159 // Disabled, being flaky
160 //equals( $foo.queue().length, 1, "The next animation continued" );
166 test("stop(clearQueue)", function() {
170 var $foo = jQuery("#nothiddendiv");
172 $foo.hide().width(200).width();
174 $foo.animate({ width:'show' }, 1000);
175 $foo.animate({ width:'hide' }, 1000);
176 $foo.animate({ width:'show' }, 1000);
177 setTimeout(function(){
178 var nw = $foo.width();
179 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
183 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
185 equals( $foo.queue().length, 0, "The animation queue was cleared" );
186 setTimeout(function(){
187 equals( nw, $foo.width(), "The animation didn't continue" );
193 test("stop(clearQueue, gotoEnd)", function() {
197 var $foo = jQuery("#nothiddendivchild");
199 $foo.hide().width(200).width();
201 $foo.animate({ width:'show' }, 1000);
202 $foo.animate({ width:'hide' }, 1000);
203 $foo.animate({ width:'show' }, 1000);
204 $foo.animate({ width:'hide' }, 1000);
205 setTimeout(function(){
206 var nw = $foo.width();
207 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
208 $foo.stop(false, true);
211 // Disabled, being flaky
212 //equals( nw, 1, "Stop() reset the animation" );
214 setTimeout(function(){
215 // Disabled, being flaky
216 //equals( $foo.queue().length, 2, "The next animation continued" );
223 test("toggle()", function() {
225 var x = jQuery("#nothiddendiv");
226 ok( x.is(":visible"), "is visible" );
228 ok( x.is(":hidden"), "is hidden" );
230 ok( x.is(":visible"), "is visible again" );
233 ok( x.is(":visible"), "is visible" );
235 ok( x.is(":hidden"), "is hidden" );
237 ok( x.is(":visible"), "is visible again" );
240 jQuery.checkOverflowDisplay = function(){
241 var o = jQuery.css( this, "overflow" );
243 equals(o, "visible", "Overflow should be visible: " + o);
244 equals(jQuery.css( this, "display" ), "inline", "Display shouldn't be tampered with.");
249 test("JS Overflow and Display", function() {
252 jQuery.makeTest( "JS Overflow and Display" )
253 .addClass("widewidth")
254 .css({ overflow: "visible", display: "inline" })
255 .addClass("widewidth")
256 .text("Some sample text.")
257 .before("text before")
259 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
262 test("CSS Overflow and Display", function() {
265 jQuery.makeTest( "CSS Overflow and Display" )
266 .addClass("overflow inline")
267 .addClass("widewidth")
268 .text("Some sample text.")
269 .before("text before")
271 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
275 "CSS Auto": function(elem,prop){
276 jQuery(elem).addClass("auto" + prop)
277 .text("This is a long string of text.");
280 "JS Auto": function(elem,prop){
281 jQuery(elem).css(prop,"auto")
282 .text("This is a long string of text.");
285 "CSS 100": function(elem,prop){
286 jQuery(elem).addClass("large" + prop);
289 "JS 100": function(elem,prop){
290 jQuery(elem).css(prop,prop == "opacity" ? 1 : "100px");
291 return prop == "opacity" ? 1 : 100;
293 "CSS 50": function(elem,prop){
294 jQuery(elem).addClass("med" + prop);
297 "JS 50": function(elem,prop){
298 jQuery(elem).css(prop,prop == "opacity" ? 0.50 : "50px");
299 return prop == "opacity" ? 0.5 : 50;
301 "CSS 0": function(elem,prop){
302 jQuery(elem).addClass("no" + prop);
305 "JS 0": function(elem,prop){
306 jQuery(elem).css(prop,prop == "opacity" ? 0 : "0px");
311 "show": function(elem,prop){
312 jQuery(elem).hide().addClass("wide"+prop);
315 "hide": function(elem,prop){
316 jQuery(elem).addClass("wide"+prop);
319 "100": function(elem,prop){
320 jQuery(elem).addClass("wide"+prop);
321 return prop == "opacity" ? 1 : 100;
323 "50": function(elem,prop){
324 return prop == "opacity" ? 0.50 : 50;
326 "0": function(elem,prop){
327 jQuery(elem).addClass("noback");
331 test(fn + " to " + tn, function() {
332 var elem = jQuery.makeTest( fn + " to " + tn );
334 var t_w = t( elem, "width" );
335 var f_w = f( elem, "width" );
336 var t_h = t( elem, "height" );
337 var f_h = f( elem, "height" );
338 var t_o = t( elem, "opacity" );
339 var f_o = f( elem, "opacity" );
343 if ( t_h == "show" ) num++;
344 if ( t_w == "show" ) num++;
345 if ( t_w == "hide"||t_w == "show" ) num++;
346 if ( t_h == "hide"||t_h == "show" ) num++;
347 if ( t_o == "hide"||t_o == "show" ) num++;
348 if ( t_w == "hide" ) num++;
349 if ( t_o.constructor == Number ) num += 2;
350 if ( t_w.constructor == Number ) num += 2;
351 if ( t_h.constructor == Number ) num +=2;
356 var anim = { width: t_w, height: t_h, opacity: t_o };
358 elem.animate(anim, 50, function(){
360 equals( this.style.display, "block", "Showing, display should block: " + this.style.display);
362 if ( t_w == "hide"||t_w == "show" )
363 equals(this.style.width.indexOf(f_w), 0, "Width must be reset to " + f_w + ": " + this.style.width);
365 if ( t_h == "hide"||t_h == "show" )
366 equals(this.style.height.indexOf(f_h), 0, "Height must be reset to " + f_h + ": " + this.style.height);
368 var cur_o = jQuery.style(this, "opacity");
369 if ( cur_o !== "" ) cur_o = parseFloat( cur_o );
371 if ( t_o == "hide"||t_o == "show" )
372 equals(cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o);
375 equals(this.style.display, "none", "Hiding, display should be none: " + this.style.display);
377 if ( t_o.constructor == Number ) {
378 equals(cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o);
380 ok(jQuery.curCSS(this, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o);
383 if ( t_w.constructor == Number ) {
384 equals(this.style.width, t_w + "px", "Final width should be " + t_w + ": " + this.style.width);
386 var cur_w = jQuery.css(this,"width");
388 ok(this.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w);
391 if ( t_h.constructor == Number ) {
392 equals(this.style.height, t_h + "px", "Final height should be " + t_h + ": " + this.style.height);
394 var cur_h = jQuery.css(this,"height");
396 ok(this.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w);
399 if ( t_h == "show" ) {
400 var old_h = jQuery.curCSS(this, "height");
401 jQuery(elem).append("<br/>Some more text<br/>and some more...");
402 ok(old_h != jQuery.css(this, "height" ), "Make sure height is auto.");
411 jQuery.fn.saveState = function(){
412 var check = ['opacity','height','width','display','overflow'];
413 expect(check.length);
416 return this.each(function(){
419 jQuery.each(check, function(i,c){
420 self.save[c] = jQuery.css(self,c);
425 jQuery.checkState = function(){
427 jQuery.each(this.save, function(c,v){
428 var cur = jQuery.css(self,c);
429 equals( v, cur, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")");
435 test("Chain fadeOut fadeIn", function() {
436 jQuery('#fadein div').saveState().fadeOut('fast').fadeIn('fast',jQuery.checkState);
438 test("Chain fadeIn fadeOut", function() {
439 jQuery('#fadeout div').saveState().fadeIn('fast').fadeOut('fast',jQuery.checkState);
442 test("Chain hide show", function() {
443 jQuery('#show div').saveState().hide('fast').show('fast',jQuery.checkState);
445 test("Chain show hide", function() {
446 jQuery('#hide div').saveState().show('fast').hide('fast',jQuery.checkState);
449 test("Chain toggle in", function() {
450 jQuery('#togglein div').saveState().toggle('fast').toggle('fast',jQuery.checkState);
452 test("Chain toggle out", function() {
453 jQuery('#toggleout div').saveState().toggle('fast').toggle('fast',jQuery.checkState);
456 test("Chain slideDown slideUp", function() {
457 jQuery('#slidedown div').saveState().slideDown('fast').slideUp('fast',jQuery.checkState);
459 test("Chain slideUp slideDown", function() {
460 jQuery('#slideup div').saveState().slideUp('fast').slideDown('fast',jQuery.checkState);
463 test("Chain slideToggle in", function() {
464 jQuery('#slidetogglein div').saveState().slideToggle('fast').slideToggle('fast',jQuery.checkState);
466 test("Chain slideToggle out", function() {
467 jQuery('#slidetoggleout div').saveState().slideToggle('fast').slideToggle('fast',jQuery.checkState);
470 jQuery.makeTest = function( text ){
471 var elem = jQuery("<div></div>")
472 .attr("id", "test" + jQuery.makeTest.id++)
477 .appendTo("#fx-tests")
479 jQuery(this).next().toggle();
486 jQuery.makeTest.id = 1;