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' );
13 test("animate option (queue === false)", function () {
20 $foo.animate({width:'100px'}, 200, function () {
21 // should finish after unqueued animation so second
24 $foo.animate({fontSize:'2em'}, {queue:false, duration:10, complete:function () {
25 // short duration and out of queue so should finish first
28 $foo.animate({height:'100px'}, 10, function() {
29 // queued behind the first animation so should finish third
31 isSet( order, [ 1, 2, 3], "Animations finished in the correct order" );
36 test("queue() defaults to 'fx' type", function () {
41 $foo.queue("fx", [ "sample", "array" ]);
42 var arr = $foo.queue();
43 isSet(arr, [ "sample", "array" ], "queue() got an array set with type 'fx'");
44 $foo.queue([ "another", "one" ]);
45 var arr = $foo.queue("fx");
46 isSet(arr, [ "another", "one" ], "queue('fx') got an array set with no type");
47 // clean up after test
53 test("stop()", function() {
57 var $foo = $("#nothiddendiv");
59 $foo.hide().width(200).width();
61 $foo.animate({ width:'show' }, 1000);
62 setTimeout(function(){
63 var nw = $foo.width();
64 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
68 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
69 setTimeout(function(){
70 equals( nw, $foo.width(), "The animation didn't continue" );
76 test("stop() - several in queue", function() {
80 var $foo = $("#nothiddendiv");
82 $foo.hide().width(200).width();
84 $foo.animate({ width:'show' }, 1000);
85 $foo.animate({ width:'hide' }, 1000);
86 $foo.animate({ width:'show' }, 1000);
87 setTimeout(function(){
88 equals( $foo.queue().length, 3, "All 3 still in the queue" );
89 var nw = $foo.width();
90 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
94 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
95 equals( $foo.queue().length, 2, "The next animation continued" );
101 test("stop(clearQueue)", function() {
105 var $foo = $("#nothiddendiv");
107 $foo.hide().width(200).width();
109 $foo.animate({ width:'show' }, 1000);
110 $foo.animate({ width:'hide' }, 1000);
111 $foo.animate({ width:'show' }, 1000);
112 setTimeout(function(){
113 var nw = $foo.width();
114 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
118 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
120 equals( $foo.queue().length, 0, "The animation queue was cleared" );
121 setTimeout(function(){
122 equals( nw, $foo.width(), "The animation didn't continue" );
128 test("stop(clearQueue, gotoEnd)", function() {
132 var $foo = $("#nothiddendiv");
134 $foo.hide().width(200).width();
136 $foo.animate({ width:'show' }, 1000);
137 $foo.animate({ width:'hide' }, 1000);
138 $foo.animate({ width:'show' }, 1000);
139 $foo.animate({ width:'hide' }, 1000);
140 setTimeout(function(){
141 var nw = $foo.width();
142 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
143 $foo.stop(false, true);
146 equals( nw, 200, "Stop() reset the animation" );
148 setTimeout(function(){
149 equals( $foo.queue().length, 3, "The next animation continued" );
156 test("toggle()", function() {
159 ok( x.is(":visible"), "is visible" );
161 ok( x.is(":hidden"), "is hidden" );
163 ok( x.is(":visible"), "is visible again" );
167 Normal: function(elem){},
168 "CSS Hidden": function(elem){
169 $(this).addClass("hidden");
171 "JS Hidden": function(elem){
177 "CSS Auto": function(elem,prop){
178 $(elem).addClass("auto" + prop)
179 .text("This is a long string of text.");
182 "JS Auto": function(elem,prop){
183 $(elem).css(prop,"auto")
184 .text("This is a long string of text.");
187 "CSS 100": function(elem,prop){
188 $(elem).addClass("large" + prop);
191 "JS 100": function(elem,prop){
192 $(elem).css(prop,prop == "opacity" ? 1 : "100px");
193 return prop == "opacity" ? 1 : 100;
195 "CSS 50": function(elem,prop){
196 $(elem).addClass("med" + prop);
199 "JS 50": function(elem,prop){
200 $(elem).css(prop,prop == "opacity" ? 0.50 : "50px");
201 return prop == "opacity" ? 0.5 : 50;
203 "CSS 0": function(elem,prop){
204 $(elem).addClass("no" + prop);
207 "JS 0": function(elem,prop){
208 $(elem).css(prop,prop == "opacity" ? 0 : "0px");
214 "show": function(elem,prop){
215 $(elem).hide().addClass("wide"+prop);
218 "hide": function(elem,prop){
219 $(elem).addClass("wide"+prop);
222 "100": function(elem,prop){
223 $(elem).addClass("wide"+prop);
224 return prop == "opacity" ? 1 : 100;
226 "50": function(elem,prop){
227 return prop == "opacity" ? 0.50 : 50;
229 "0": function(elem,prop){
230 $(elem).addClass("noback");
235 function checkOverflowDisplay(){
236 var o = jQuery.css( this, "overflow" );
238 ok(o == "visible", "Overflow should be visible: " + o);
239 ok(jQuery.css( this, "display" ) == "inline", "Display shouldn't be tampered with.");
244 test("JS Overflow and Display", function() {
247 makeTest( "JS Overflow and Display" )
248 .addClass("widewidth")
249 .css({ overflow: "visible", display: "inline" })
250 .addClass("widewidth")
251 .text("Some sample text.")
252 .before("text before")
254 .animate({ opacity: 0.5 }, "slow", checkOverflowDisplay);
257 test("CSS Overflow and Display", function() {
260 makeTest( "CSS Overflow and Display" )
261 .addClass("overflow inline")
262 .addClass("widewidth")
263 .text("Some sample text.")
264 .before("text before")
266 .animate({ opacity: 0.5 }, "slow", checkOverflowDisplay);
269 jQuery.each( from, function(fn, f){
270 jQuery.each( to, function(tn, t){
271 test(fn + " to " + tn, function() {
272 var elem = makeTest( fn + " to " + tn );
274 var t_w = t( elem, "width" );
275 var f_w = f( elem, "width" );
276 var t_h = t( elem, "height" );
277 var f_h = f( elem, "height" );
278 var t_o = t( elem, "opacity" );
279 var f_o = f( elem, "opacity" );
283 if ( t_h == "show" ) num++;
284 if ( t_w == "show" ) num++;
285 if ( t_w == "hide"||t_w == "show" ) num++;
286 if ( t_h == "hide"||t_h == "show" ) num++;
287 if ( t_o == "hide"||t_o == "show" ) num++;
288 if ( t_w == "hide" ) num++;
289 if ( t_o.constructor == Number ) num += 2;
290 if ( t_w.constructor == Number ) num += 2;
291 if ( t_h.constructor == Number ) num +=2;
296 var anim = { width: t_w, height: t_h, opacity: t_o };
298 elem.animate(anim, 50, function(){
300 ok( this.style.display == "block", "Showing, display should block: " + this.style.display);
302 if ( t_w == "hide"||t_w == "show" )
303 ok(this.style.width.indexOf(f_w) == 0, "Width must be reset to " + f_w + ": " + this.style.width);
305 if ( t_h == "hide"||t_h == "show" )
306 ok(this.style.height.indexOf(f_h) == 0, "Height must be reset to " + f_h + ": " + this.style.height);
308 var cur_o = jQuery.attr(this.style, "opacity");
309 if ( cur_o !== "" ) cur_o = parseFloat( cur_o );
311 if ( t_o == "hide"||t_o == "show" )
312 ok(cur_o == f_o, "Opacity must be reset to " + f_o + ": " + cur_o);
315 ok(this.style.display == "none", "Hiding, display should be none: " + this.style.display);
317 if ( t_o.constructor == Number ) {
318 ok(cur_o == t_o, "Final opacity should be " + t_o + ": " + cur_o);
320 ok(jQuery.curCSS(this, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o);
323 if ( t_w.constructor == Number ) {
324 ok(this.style.width == t_w + "px", "Final width should be " + t_w + ": " + this.style.width);
326 var cur_w = jQuery.css(this,"width");
328 ok(this.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w);
331 if ( t_h.constructor == Number ) {
332 ok(this.style.height == t_h + "px", "Final height should be " + t_h + ": " + this.style.height);
334 var cur_h = jQuery.css(this,"height");
336 ok(this.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w);
339 if ( t_h == "show" ) {
340 var old_h = jQuery.curCSS(this, "height");
341 $(elem).append("<br/>Some more text<br/>and some more...");
342 ok(old_h != jQuery.css(this, "height" ), "Make sure height is auto.");
351 var check = ['opacity','height','width','display','overflow'];
353 jQuery.fn.saveState = function(){
354 expect(check.length);
356 return this.each(function(){
359 jQuery.each(check, function(i,c){
360 self.save[c] = jQuery.css(self,c);
365 function checkState(){
367 jQuery.each(this.save, function(c,v){
368 var cur = jQuery.css(self,c);
369 ok( v == cur, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")");
375 test("Chain fadeOut fadeIn", function() {
376 $('#fadein div').saveState().fadeOut('fast').fadeIn('fast',checkState);
378 test("Chain fadeIn fadeOut", function() {
379 $('#fadeout div').saveState().fadeIn('fast').fadeOut('fast',checkState);
382 test("Chain hide show", function() {
383 $('#show div').saveState().hide('fast').show('fast',checkState);
385 test("Chain show hide", function() {
386 $('#hide div').saveState().show('fast').hide('fast',checkState);
389 test("Chain toggle in", function() {
390 $('#togglein div').saveState().toggle('fast').toggle('fast',checkState);
392 test("Chain toggle out", function() {
393 $('#toggleout div').saveState().toggle('fast').toggle('fast',checkState);
396 test("Chain slideDown slideUp", function() {
397 $('#slidedown div').saveState().slideDown('fast').slideUp('fast',checkState);
399 test("Chain slideUp slideDown", function() {
400 $('#slideup div').saveState().slideUp('fast').slideDown('fast',checkState);
403 test("Chain slideToggle in", function() {
404 $('#slidetogglein div').saveState().slideToggle('fast').slideToggle('fast',checkState);
406 test("Chain slideToggle out", function() {
407 $('#slidetoggleout div').saveState().slideToggle('fast').slideToggle('fast',checkState);
410 function makeTest( text ){
411 var elem = $("<div></div>")
412 .attr("id", "test" + makeTest.id++)
417 .appendTo("#fx-tests")
419 $(this).next().toggle();