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("queue() defaults to 'fx' type", function () {
41 var $foo = jQuery("#foo");
42 $foo.queue("fx", [ "sample", "array" ]);
43 var arr = $foo.queue();
44 isSet(arr, [ "sample", "array" ], "queue() got an array set with type 'fx'");
45 $foo.queue([ "another", "one" ]);
46 var arr = $foo.queue("fx");
47 isSet(arr, [ "another", "one" ], "queue('fx') got an array set with no type");
48 // clean up after test
54 test("stop()", function() {
58 var $foo = jQuery("#nothiddendiv");
60 $foo.hide().width(200).width();
62 $foo.animate({ width:'show' }, 1000);
63 setTimeout(function(){
64 var nw = $foo.width();
65 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
69 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
70 setTimeout(function(){
71 equals( nw, $foo.width(), "The animation didn't continue" );
77 test("stop() - several in queue", function() {
81 var $foo = jQuery("#nothiddendiv");
83 $foo.hide().width(200).width();
85 $foo.animate({ width:'show' }, 1000);
86 $foo.animate({ width:'hide' }, 1000);
87 $foo.animate({ width:'show' }, 1000);
88 setTimeout(function(){
89 equals( $foo.queue().length, 3, "All 3 still in the queue" );
90 var nw = $foo.width();
91 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
95 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
96 equals( $foo.queue().length, 2, "The next animation continued" );
102 test("stop(clearQueue)", function() {
106 var $foo = jQuery("#nothiddendiv");
108 $foo.hide().width(200).width();
110 $foo.animate({ width:'show' }, 1000);
111 $foo.animate({ width:'hide' }, 1000);
112 $foo.animate({ width:'show' }, 1000);
113 setTimeout(function(){
114 var nw = $foo.width();
115 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
119 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
121 equals( $foo.queue().length, 0, "The animation queue was cleared" );
122 setTimeout(function(){
123 equals( nw, $foo.width(), "The animation didn't continue" );
129 test("stop(clearQueue, gotoEnd)", function() {
133 var $foo = jQuery("#nothiddendiv");
135 $foo.hide().width(200).width();
137 $foo.animate({ width:'show' }, 1000);
138 $foo.animate({ width:'hide' }, 1000);
139 $foo.animate({ width:'show' }, 1000);
140 $foo.animate({ width:'hide' }, 1000);
141 setTimeout(function(){
142 var nw = $foo.width();
143 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
144 $foo.stop(false, true);
147 equals( nw, 200, "Stop() reset the animation" );
149 setTimeout(function(){
150 equals( $foo.queue().length, 3, "The next animation continued" );
157 test("toggle()", function() {
159 var x = jQuery("#foo");
160 ok( x.is(":visible"), "is visible" );
162 ok( x.is(":hidden"), "is hidden" );
164 ok( x.is(":visible"), "is visible again" );
168 Normal: function(elem){},
169 "CSS Hidden": function(elem){
170 jQuery(this).addClass("hidden");
172 "JS Hidden": function(elem){
178 "CSS Auto": function(elem,prop){
179 jQuery(elem).addClass("auto" + prop)
180 .text("This is a long string of text.");
183 "JS Auto": function(elem,prop){
184 jQuery(elem).css(prop,"auto")
185 .text("This is a long string of text.");
188 "CSS 100": function(elem,prop){
189 jQuery(elem).addClass("large" + prop);
192 "JS 100": function(elem,prop){
193 jQuery(elem).css(prop,prop == "opacity" ? 1 : "100px");
194 return prop == "opacity" ? 1 : 100;
196 "CSS 50": function(elem,prop){
197 jQuery(elem).addClass("med" + prop);
200 "JS 50": function(elem,prop){
201 jQuery(elem).css(prop,prop == "opacity" ? 0.50 : "50px");
202 return prop == "opacity" ? 0.5 : 50;
204 "CSS 0": function(elem,prop){
205 jQuery(elem).addClass("no" + prop);
208 "JS 0": function(elem,prop){
209 jQuery(elem).css(prop,prop == "opacity" ? 0 : "0px");
215 "show": function(elem,prop){
216 jQuery(elem).hide().addClass("wide"+prop);
219 "hide": function(elem,prop){
220 jQuery(elem).addClass("wide"+prop);
223 "100": function(elem,prop){
224 jQuery(elem).addClass("wide"+prop);
225 return prop == "opacity" ? 1 : 100;
227 "50": function(elem,prop){
228 return prop == "opacity" ? 0.50 : 50;
230 "0": function(elem,prop){
231 jQuery(elem).addClass("noback");
236 function checkOverflowDisplay(){
237 var o = jQuery.css( this, "overflow" );
239 equals(o, "visible", "Overflow should be visible: " + o);
240 equals(jQuery.css( this, "display" ), "inline", "Display shouldn't be tampered with.");
245 test("JS Overflow and Display", function() {
248 makeTest( "JS Overflow and Display" )
249 .addClass("widewidth")
250 .css({ overflow: "visible", display: "inline" })
251 .addClass("widewidth")
252 .text("Some sample text.")
253 .before("text before")
255 .animate({ opacity: 0.5 }, "slow", checkOverflowDisplay);
258 test("CSS Overflow and Display", function() {
261 makeTest( "CSS Overflow and Display" )
262 .addClass("overflow inline")
263 .addClass("widewidth")
264 .text("Some sample text.")
265 .before("text before")
267 .animate({ opacity: 0.5 }, "slow", checkOverflowDisplay);
270 jQuery.each( from, function(fn, f){
271 jQuery.each( to, function(tn, t){
272 test(fn + " to " + tn, function() {
273 var elem = makeTest( fn + " to " + tn );
275 var t_w = t( elem, "width" );
276 var f_w = f( elem, "width" );
277 var t_h = t( elem, "height" );
278 var f_h = f( elem, "height" );
279 var t_o = t( elem, "opacity" );
280 var f_o = f( elem, "opacity" );
284 if ( t_h == "show" ) num++;
285 if ( t_w == "show" ) num++;
286 if ( t_w == "hide"||t_w == "show" ) num++;
287 if ( t_h == "hide"||t_h == "show" ) num++;
288 if ( t_o == "hide"||t_o == "show" ) num++;
289 if ( t_w == "hide" ) num++;
290 if ( t_o.constructor == Number ) num += 2;
291 if ( t_w.constructor == Number ) num += 2;
292 if ( t_h.constructor == Number ) num +=2;
297 var anim = { width: t_w, height: t_h, opacity: t_o };
299 elem.animate(anim, 50, function(){
301 equals( this.style.display, "block", "Showing, display should block: " + this.style.display);
303 if ( t_w == "hide"||t_w == "show" )
304 equals(this.style.width.indexOf(f_w), 0, "Width must be reset to " + f_w + ": " + this.style.width);
306 if ( t_h == "hide"||t_h == "show" )
307 equals(this.style.height.indexOf(f_h), 0, "Height must be reset to " + f_h + ": " + this.style.height);
309 var cur_o = jQuery.attr(this.style, "opacity");
310 if ( cur_o !== "" ) cur_o = parseFloat( cur_o );
312 if ( t_o == "hide"||t_o == "show" )
313 equals(cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o);
316 equals(this.style.display, "none", "Hiding, display should be none: " + this.style.display);
318 if ( t_o.constructor == Number ) {
319 equals(cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o);
321 ok(jQuery.curCSS(this, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o);
324 if ( t_w.constructor == Number ) {
325 equals(this.style.width, t_w + "px", "Final width should be " + t_w + ": " + this.style.width);
327 var cur_w = jQuery.css(this,"width");
329 ok(this.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w);
332 if ( t_h.constructor == Number ) {
333 equals(this.style.height, t_h + "px", "Final height should be " + t_h + ": " + this.style.height);
335 var cur_h = jQuery.css(this,"height");
337 ok(this.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w);
340 if ( t_h == "show" ) {
341 var old_h = jQuery.curCSS(this, "height");
342 jQuery(elem).append("<br/>Some more text<br/>and some more...");
343 ok(old_h != jQuery.css(this, "height" ), "Make sure height is auto.");
352 var check = ['opacity','height','width','display','overflow'];
354 jQuery.fn.saveState = function(){
355 expect(check.length);
357 return this.each(function(){
360 jQuery.each(check, function(i,c){
361 self.save[c] = jQuery.css(self,c);
366 function checkState(){
368 jQuery.each(this.save, function(c,v){
369 var cur = jQuery.css(self,c);
370 equals( v, cur, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")");
376 test("Chain fadeOut fadeIn", function() {
377 jQuery('#fadein div').saveState().fadeOut('fast').fadeIn('fast',checkState);
379 test("Chain fadeIn fadeOut", function() {
380 jQuery('#fadeout div').saveState().fadeIn('fast').fadeOut('fast',checkState);
383 test("Chain hide show", function() {
384 jQuery('#show div').saveState().hide('fast').show('fast',checkState);
386 test("Chain show hide", function() {
387 jQuery('#hide div').saveState().show('fast').hide('fast',checkState);
390 test("Chain toggle in", function() {
391 jQuery('#togglein div').saveState().toggle('fast').toggle('fast',checkState);
393 test("Chain toggle out", function() {
394 jQuery('#toggleout div').saveState().toggle('fast').toggle('fast',checkState);
397 test("Chain slideDown slideUp", function() {
398 jQuery('#slidedown div').saveState().slideDown('fast').slideUp('fast',checkState);
400 test("Chain slideUp slideDown", function() {
401 jQuery('#slideup div').saveState().slideUp('fast').slideDown('fast',checkState);
404 test("Chain slideToggle in", function() {
405 jQuery('#slidetogglein div').saveState().slideToggle('fast').slideToggle('fast',checkState);
407 test("Chain slideToggle out", function() {
408 jQuery('#slidetoggleout div').saveState().slideToggle('fast').slideToggle('fast',checkState);
411 function makeTest( text ){
412 var elem = jQuery("<div></div>")
413 .attr("id", "test" + makeTest.id++)
418 .appendTo("#fx-tests")
420 jQuery(this).next().toggle();