3 test("animate(Hash, Object, Function)", function() {
6 var hash = {opacity: 'show'};
7 var hashCopy = $.extend({}, hash);
8 $('#foo').animate(hash, 0, function() {
9 ok( hash.opacity == hashCopy.opacity, 'Check if animate changed the hash parameter' );
11 // using contents will get comments regular, text, and comment nodes
12 $("#nonnodes").contents().animate({paddingLeft:"5px"}, 100, function () {
13 equals(this.nodeType, 1, "Check node,textnode,comment animate just does real nodes" );
14 equals($(this).css("paddingLeft"), "5px", "Check node,textnode,comment animate just does real nodes" );
19 test("animate option (queue === false)", function () {
26 $foo.animate({width:'100px'}, 200, function () {
27 // should finish after unqueued animation so second
30 $foo.animate({fontSize:'2em'}, {queue:false, duration:10, complete:function () {
31 // short duration and out of queue so should finish first
34 $foo.animate({height:'100px'}, 10, function() {
35 // queued behind the first animation so should finish third
37 isSet( order, [ 1, 2, 3], "Animations finished in the correct order" );
42 test("queue() defaults to 'fx' type", function () {
47 $foo.queue("fx", [ "sample", "array" ]);
48 var arr = $foo.queue();
49 isSet(arr, [ "sample", "array" ], "queue() got an array set with type 'fx'");
50 $foo.queue([ "another", "one" ]);
51 var arr = $foo.queue("fx");
52 isSet(arr, [ "another", "one" ], "queue('fx') got an array set with no type");
53 // clean up after test
59 test("stop()", function() {
63 var $foo = $("#nothiddendiv");
65 $foo.hide().width(200).width();
67 $foo.animate({ width:'show' }, 1000);
68 setTimeout(function(){
69 var nw = $foo.width();
70 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
74 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
75 setTimeout(function(){
76 equals( nw, $foo.width(), "The animation didn't continue" );
82 test("stop() - several in queue", function() {
86 var $foo = $("#nothiddendiv");
88 $foo.hide().width(200).width();
90 $foo.animate({ width:'show' }, 1000);
91 $foo.animate({ width:'hide' }, 1000);
92 $foo.animate({ width:'show' }, 1000);
93 setTimeout(function(){
94 equals( $foo.queue().length, 3, "All 3 still in the queue" );
95 var nw = $foo.width();
96 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
100 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
101 equals( $foo.queue().length, 2, "The next animation continued" );
107 test("stop(clearQueue)", function() {
111 var $foo = $("#nothiddendiv");
113 $foo.hide().width(200).width();
115 $foo.animate({ width:'show' }, 1000);
116 $foo.animate({ width:'hide' }, 1000);
117 $foo.animate({ width:'show' }, 1000);
118 setTimeout(function(){
119 var nw = $foo.width();
120 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
124 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
126 equals( $foo.queue().length, 0, "The animation queue was cleared" );
127 setTimeout(function(){
128 equals( nw, $foo.width(), "The animation didn't continue" );
134 test("stop(clearQueue, gotoEnd)", function() {
138 var $foo = $("#nothiddendiv");
140 $foo.hide().width(200).width();
142 $foo.animate({ width:'show' }, 1000);
143 $foo.animate({ width:'hide' }, 1000);
144 $foo.animate({ width:'show' }, 1000);
145 $foo.animate({ width:'hide' }, 1000);
146 setTimeout(function(){
147 var nw = $foo.width();
148 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
149 $foo.stop(false, true);
152 equals( nw, 200, "Stop() reset the animation" );
154 setTimeout(function(){
155 equals( $foo.queue().length, 3, "The next animation continued" );
162 test("toggle()", function() {
165 ok( x.is(":visible"), "is visible" );
167 ok( x.is(":hidden"), "is hidden" );
169 ok( x.is(":visible"), "is visible again" );
173 Normal: function(elem){},
174 "CSS Hidden": function(elem){
175 $(this).addClass("hidden");
177 "JS Hidden": function(elem){
183 "CSS Auto": function(elem,prop){
184 $(elem).addClass("auto" + prop)
185 .text("This is a long string of text.");
188 "JS Auto": function(elem,prop){
189 $(elem).css(prop,"auto")
190 .text("This is a long string of text.");
193 "CSS 100": function(elem,prop){
194 $(elem).addClass("large" + prop);
197 "JS 100": function(elem,prop){
198 $(elem).css(prop,prop == "opacity" ? 1 : "100px");
199 return prop == "opacity" ? 1 : 100;
201 "CSS 50": function(elem,prop){
202 $(elem).addClass("med" + prop);
205 "JS 50": function(elem,prop){
206 $(elem).css(prop,prop == "opacity" ? 0.50 : "50px");
207 return prop == "opacity" ? 0.5 : 50;
209 "CSS 0": function(elem,prop){
210 $(elem).addClass("no" + prop);
213 "JS 0": function(elem,prop){
214 $(elem).css(prop,prop == "opacity" ? 0 : "0px");
220 "show": function(elem,prop){
221 $(elem).hide().addClass("wide"+prop);
224 "hide": function(elem,prop){
225 $(elem).addClass("wide"+prop);
228 "100": function(elem,prop){
229 $(elem).addClass("wide"+prop);
230 return prop == "opacity" ? 1 : 100;
232 "50": function(elem,prop){
233 return prop == "opacity" ? 0.50 : 50;
235 "0": function(elem,prop){
236 $(elem).addClass("noback");
241 function checkOverflowDisplay(){
242 var o = jQuery.css( this, "overflow" );
244 ok(o == "visible", "Overflow should be visible: " + o);
245 ok(jQuery.css( this, "display" ) == "inline", "Display shouldn't be tampered with.");
250 test("JS Overflow and Display", function() {
253 makeTest( "JS Overflow and Display" )
254 .addClass("widewidth")
255 .css({ overflow: "visible", display: "inline" })
256 .addClass("widewidth")
257 .text("Some sample text.")
258 .before("text before")
260 .animate({ opacity: 0.5 }, "slow", checkOverflowDisplay);
263 test("CSS Overflow and Display", function() {
266 makeTest( "CSS Overflow and Display" )
267 .addClass("overflow inline")
268 .addClass("widewidth")
269 .text("Some sample text.")
270 .before("text before")
272 .animate({ opacity: 0.5 }, "slow", checkOverflowDisplay);
275 jQuery.each( from, function(fn, f){
276 jQuery.each( to, function(tn, t){
277 test(fn + " to " + tn, function() {
278 var elem = makeTest( fn + " to " + tn );
280 var t_w = t( elem, "width" );
281 var f_w = f( elem, "width" );
282 var t_h = t( elem, "height" );
283 var f_h = f( elem, "height" );
284 var t_o = t( elem, "opacity" );
285 var f_o = f( elem, "opacity" );
289 if ( t_h == "show" ) num++;
290 if ( t_w == "show" ) num++;
291 if ( t_w == "hide"||t_w == "show" ) num++;
292 if ( t_h == "hide"||t_h == "show" ) num++;
293 if ( t_o == "hide"||t_o == "show" ) num++;
294 if ( t_w == "hide" ) num++;
295 if ( t_o.constructor == Number ) num += 2;
296 if ( t_w.constructor == Number ) num += 2;
297 if ( t_h.constructor == Number ) num +=2;
302 var anim = { width: t_w, height: t_h, opacity: t_o };
304 elem.animate(anim, 50, function(){
306 ok( this.style.display == "block", "Showing, display should block: " + this.style.display);
308 if ( t_w == "hide"||t_w == "show" )
309 ok(this.style.width.indexOf(f_w) == 0, "Width must be reset to " + f_w + ": " + this.style.width);
311 if ( t_h == "hide"||t_h == "show" )
312 ok(this.style.height.indexOf(f_h) == 0, "Height must be reset to " + f_h + ": " + this.style.height);
314 var cur_o = jQuery.attr(this.style, "opacity");
315 if ( cur_o !== "" ) cur_o = parseFloat( cur_o );
317 if ( t_o == "hide"||t_o == "show" )
318 ok(cur_o == f_o, "Opacity must be reset to " + f_o + ": " + cur_o);
321 ok(this.style.display == "none", "Hiding, display should be none: " + this.style.display);
323 if ( t_o.constructor == Number ) {
324 ok(cur_o == t_o, "Final opacity should be " + t_o + ": " + cur_o);
326 ok(jQuery.curCSS(this, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o);
329 if ( t_w.constructor == Number ) {
330 ok(this.style.width == t_w + "px", "Final width should be " + t_w + ": " + this.style.width);
332 var cur_w = jQuery.css(this,"width");
334 ok(this.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w);
337 if ( t_h.constructor == Number ) {
338 ok(this.style.height == t_h + "px", "Final height should be " + t_h + ": " + this.style.height);
340 var cur_h = jQuery.css(this,"height");
342 ok(this.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w);
345 if ( t_h == "show" ) {
346 var old_h = jQuery.curCSS(this, "height");
347 $(elem).append("<br/>Some more text<br/>and some more...");
348 ok(old_h != jQuery.css(this, "height" ), "Make sure height is auto.");
357 var check = ['opacity','height','width','display','overflow'];
359 jQuery.fn.saveState = function(){
360 expect(check.length);
362 return this.each(function(){
365 jQuery.each(check, function(i,c){
366 self.save[c] = jQuery.css(self,c);
371 function checkState(){
373 jQuery.each(this.save, function(c,v){
374 var cur = jQuery.css(self,c);
375 ok( v == cur, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")");
381 test("Chain fadeOut fadeIn", function() {
382 $('#fadein div').saveState().fadeOut('fast').fadeIn('fast',checkState);
384 test("Chain fadeIn fadeOut", function() {
385 $('#fadeout div').saveState().fadeIn('fast').fadeOut('fast',checkState);
388 test("Chain hide show", function() {
389 $('#show div').saveState().hide('fast').show('fast',checkState);
391 test("Chain show hide", function() {
392 $('#hide div').saveState().show('fast').hide('fast',checkState);
395 test("Chain toggle in", function() {
396 $('#togglein div').saveState().toggle('fast').toggle('fast',checkState);
398 test("Chain toggle out", function() {
399 $('#toggleout div').saveState().toggle('fast').toggle('fast',checkState);
402 test("Chain slideDown slideUp", function() {
403 $('#slidedown div').saveState().slideDown('fast').slideUp('fast',checkState);
405 test("Chain slideUp slideDown", function() {
406 $('#slideup div').saveState().slideUp('fast').slideDown('fast',checkState);
409 test("Chain slideToggle in", function() {
410 $('#slidetogglein div').saveState().slideToggle('fast').slideToggle('fast',checkState);
412 test("Chain slideToggle out", function() {
413 $('#slidetoggleout div').saveState().slideToggle('fast').slideToggle('fast',checkState);
416 function makeTest( text ){
417 var elem = $("<div></div>")
418 .attr("id", "test" + makeTest.id++)
423 .appendTo("#fx-tests")
425 $(this).next().toggle();