3 test("animate(Hash, Object, Function)", function() {
6 var hash = {opacity: 'show'};
7 var hashCopy = jQuery.extend({}, hash);
8 jQuery('#foo').animate(hash, 0, function() {
9 equals( hash.opacity, hashCopy.opacity, 'Check if animate changed the hash parameter' );
14 test("animate option (queue === false)", function () {
20 var $foo = jQuery("#foo");
21 $foo.animate({width:'100px'}, 200, function () {
22 // should finish after unqueued animation so second
25 $foo.animate({fontSize:'2em'}, {queue:false, duration:10, complete:function () {
26 // short duration and out of queue so should finish first
29 $foo.animate({height:'100px'}, 10, function() {
30 // queued behind the first animation so should finish third
32 isSet( order, [ 1, 2, 3], "Animations finished in the correct order" );
37 test("animate duration 0", function() {
42 var $elems = jQuery([{ a:0 },{ a:0 }]),
48 equals( jQuery.timers.length, 0, "Make sure no animation was running from another test" );
50 $elems.eq(0).animate( {a:1}, 0, count );
52 // Failed until [6115]
53 equals( jQuery.timers.length, 0, "Make sure synchronic animations are not left on jQuery.timers" );
55 equals( counter, 1, "One synchronic animations" );
57 $elems.animate( { a:2 }, 0, count );
59 equals( counter, 3, "Multiple synchronic animations" );
61 $elems.eq(0).animate( {a:3}, 0, count );
62 $elems.eq(1).animate( {a:3}, 20, function(){
64 // Failed until [6115]
65 equals( counter, 5, "One synchronic and one asynchronic" );
70 test("animate non-element", function(){
74 var obj = { test: 0 };
76 jQuery(obj).animate({test: 200}, 200, function(){
77 equals( obj.test, 200, "The custom property should be modified." );
82 test("stop()", function() {
86 var $foo = jQuery("#nothiddendiv");
88 $foo.hide().width(200).width();
90 $foo.animate({ width:'show' }, 1000);
91 setTimeout(function(){
92 var nw = $foo.width();
93 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
97 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
98 setTimeout(function(){
99 equals( nw, $foo.width(), "The animation didn't continue" );
105 test("stop() - several in queue", function() {
109 var $foo = jQuery("#nothiddendivchild");
111 $foo.hide().width(200).width();
113 $foo.animate({ width:'show' }, 1000);
114 $foo.animate({ width:'hide' }, 1000);
115 $foo.animate({ width:'show' }, 1000);
116 setTimeout(function(){
117 equals( $foo.queue().length, 3, "All 3 still in the queue" );
118 var nw = $foo.width();
119 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
123 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
124 // Disabled, being flaky
125 //equals( $foo.queue().length, 1, "The next animation continued" );
131 test("stop(clearQueue)", function() {
135 var $foo = jQuery("#nothiddendiv");
137 $foo.hide().width(200).width();
139 $foo.animate({ width:'show' }, 1000);
140 $foo.animate({ width:'hide' }, 1000);
141 $foo.animate({ width:'show' }, 1000);
142 setTimeout(function(){
143 var nw = $foo.width();
144 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
148 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
150 equals( $foo.queue().length, 0, "The animation queue was cleared" );
151 setTimeout(function(){
152 equals( nw, $foo.width(), "The animation didn't continue" );
158 test("stop(clearQueue, gotoEnd)", function() {
162 var $foo = jQuery("#nothiddendivchild");
164 $foo.hide().width(200).width();
166 $foo.animate({ width:'show' }, 1000);
167 $foo.animate({ width:'hide' }, 1000);
168 $foo.animate({ width:'show' }, 1000);
169 $foo.animate({ width:'hide' }, 1000);
170 setTimeout(function(){
171 var nw = $foo.width();
172 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
173 $foo.stop(false, true);
176 // Disabled, being flaky
177 //equals( nw, 1, "Stop() reset the animation" );
179 setTimeout(function(){
180 // Disabled, being flaky
181 //equals( $foo.queue().length, 2, "The next animation continued" );
188 test("toggle()", function() {
190 var x = jQuery("#nothiddendiv");
191 ok( x.is(":visible"), "is visible" );
193 ok( x.is(":hidden"), "is hidden" );
195 ok( x.is(":visible"), "is visible again" );
198 ok( x.is(":visible"), "is visible" );
200 ok( x.is(":hidden"), "is hidden" );
202 ok( x.is(":visible"), "is visible again" );
205 jQuery.checkOverflowDisplay = function(){
206 var o = jQuery.css( this, "overflow" );
208 equals(o, "visible", "Overflow should be visible: " + o);
209 equals(jQuery.css( this, "display" ), "inline", "Display shouldn't be tampered with.");
214 test("JS Overflow and Display", function() {
217 jQuery.makeTest( "JS Overflow and Display" )
218 .addClass("widewidth")
219 .css({ overflow: "visible", display: "inline" })
220 .addClass("widewidth")
221 .text("Some sample text.")
222 .before("text before")
224 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
227 test("CSS Overflow and Display", function() {
230 jQuery.makeTest( "CSS Overflow and Display" )
231 .addClass("overflow inline")
232 .addClass("widewidth")
233 .text("Some sample text.")
234 .before("text before")
236 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
240 "CSS Auto": function(elem,prop){
241 jQuery(elem).addClass("auto" + prop)
242 .text("This is a long string of text.");
245 "JS Auto": function(elem,prop){
246 jQuery(elem).css(prop,"auto")
247 .text("This is a long string of text.");
250 "CSS 100": function(elem,prop){
251 jQuery(elem).addClass("large" + prop);
254 "JS 100": function(elem,prop){
255 jQuery(elem).css(prop,prop == "opacity" ? 1 : "100px");
256 return prop == "opacity" ? 1 : 100;
258 "CSS 50": function(elem,prop){
259 jQuery(elem).addClass("med" + prop);
262 "JS 50": function(elem,prop){
263 jQuery(elem).css(prop,prop == "opacity" ? 0.50 : "50px");
264 return prop == "opacity" ? 0.5 : 50;
266 "CSS 0": function(elem,prop){
267 jQuery(elem).addClass("no" + prop);
270 "JS 0": function(elem,prop){
271 jQuery(elem).css(prop,prop == "opacity" ? 0 : "0px");
276 "show": function(elem,prop){
277 jQuery(elem).hide().addClass("wide"+prop);
280 "hide": function(elem,prop){
281 jQuery(elem).addClass("wide"+prop);
284 "100": function(elem,prop){
285 jQuery(elem).addClass("wide"+prop);
286 return prop == "opacity" ? 1 : 100;
288 "50": function(elem,prop){
289 return prop == "opacity" ? 0.50 : 50;
291 "0": function(elem,prop){
292 jQuery(elem).addClass("noback");
296 test(fn + " to " + tn, function() {
297 var elem = jQuery.makeTest( fn + " to " + tn );
299 var t_w = t( elem, "width" );
300 var f_w = f( elem, "width" );
301 var t_h = t( elem, "height" );
302 var f_h = f( elem, "height" );
303 var t_o = t( elem, "opacity" );
304 var f_o = f( elem, "opacity" );
308 if ( t_h == "show" ) num++;
309 if ( t_w == "show" ) num++;
310 if ( t_w == "hide"||t_w == "show" ) num++;
311 if ( t_h == "hide"||t_h == "show" ) num++;
312 if ( t_o == "hide"||t_o == "show" ) num++;
313 if ( t_w == "hide" ) num++;
314 if ( t_o.constructor == Number ) num += 2;
315 if ( t_w.constructor == Number ) num += 2;
316 if ( t_h.constructor == Number ) num +=2;
321 var anim = { width: t_w, height: t_h, opacity: t_o };
323 elem.animate(anim, 50, function(){
325 equals( this.style.display, "block", "Showing, display should block: " + this.style.display);
327 if ( t_w == "hide"||t_w == "show" )
328 equals(this.style.width.indexOf(f_w), 0, "Width must be reset to " + f_w + ": " + this.style.width);
330 if ( t_h == "hide"||t_h == "show" )
331 equals(this.style.height.indexOf(f_h), 0, "Height must be reset to " + f_h + ": " + this.style.height);
333 var cur_o = jQuery.attr(this.style, "opacity");
334 if ( cur_o !== "" ) cur_o = parseFloat( cur_o );
336 if ( t_o == "hide"||t_o == "show" )
337 equals(cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o);
340 equals(this.style.display, "none", "Hiding, display should be none: " + this.style.display);
342 if ( t_o.constructor == Number ) {
343 equals(cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o);
345 ok(jQuery.curCSS(this, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o);
348 if ( t_w.constructor == Number ) {
349 equals(this.style.width, t_w + "px", "Final width should be " + t_w + ": " + this.style.width);
351 var cur_w = jQuery.css(this,"width");
353 ok(this.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w);
356 if ( t_h.constructor == Number ) {
357 equals(this.style.height, t_h + "px", "Final height should be " + t_h + ": " + this.style.height);
359 var cur_h = jQuery.css(this,"height");
361 ok(this.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w);
364 if ( t_h == "show" ) {
365 var old_h = jQuery.curCSS(this, "height");
366 jQuery(elem).append("<br/>Some more text<br/>and some more...");
367 ok(old_h != jQuery.css(this, "height" ), "Make sure height is auto.");
376 jQuery.fn.saveState = function(){
377 var check = ['opacity','height','width','display','overflow'];
378 expect(check.length);
381 return this.each(function(){
384 jQuery.each(check, function(i,c){
385 self.save[c] = jQuery.css(self,c);
390 jQuery.checkState = function(){
392 jQuery.each(this.save, function(c,v){
393 var cur = jQuery.css(self,c);
394 equals( v, cur, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")");
400 test("Chain fadeOut fadeIn", function() {
401 jQuery('#fadein div').saveState().fadeOut('fast').fadeIn('fast',jQuery.checkState);
403 test("Chain fadeIn fadeOut", function() {
404 jQuery('#fadeout div').saveState().fadeIn('fast').fadeOut('fast',jQuery.checkState);
407 test("Chain hide show", function() {
408 jQuery('#show div').saveState().hide('fast').show('fast',jQuery.checkState);
410 test("Chain show hide", function() {
411 jQuery('#hide div').saveState().show('fast').hide('fast',jQuery.checkState);
414 test("Chain toggle in", function() {
415 jQuery('#togglein div').saveState().toggle('fast').toggle('fast',jQuery.checkState);
417 test("Chain toggle out", function() {
418 jQuery('#toggleout div').saveState().toggle('fast').toggle('fast',jQuery.checkState);
421 test("Chain slideDown slideUp", function() {
422 jQuery('#slidedown div').saveState().slideDown('fast').slideUp('fast',jQuery.checkState);
424 test("Chain slideUp slideDown", function() {
425 jQuery('#slideup div').saveState().slideUp('fast').slideDown('fast',jQuery.checkState);
428 test("Chain slideToggle in", function() {
429 jQuery('#slidetogglein div').saveState().slideToggle('fast').slideToggle('fast',jQuery.checkState);
431 test("Chain slideToggle out", function() {
432 jQuery('#slidetoggleout div').saveState().slideToggle('fast').slideToggle('fast',jQuery.checkState);
435 jQuery.makeTest = function( text ){
436 var elem = jQuery("<div></div>")
437 .attr("id", "test" + jQuery.makeTest.id++)
442 .appendTo("#fx-tests")
444 jQuery(this).next().toggle();
451 jQuery.makeTest.id = 1;