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' );
14 test("animate option (queue === false)", function () {
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 () {
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() {
59 var foo = $("#foo")[0];
60 var h = foo.style.height;
62 $("#foo").slideUp(1000);
63 setTimeout(function(){
64 var nh = foo.style.height;
65 ok( nh != h, "An animation occurred " + nh + " " + h );
68 nh = foo.style.height;
69 ok( nh != h, "Stop didn't reset the animation " + nh + " " + h );
70 setTimeout(function(){
71 equals( nh, foo.style.height, "The animation didn't continue" );
77 test("toggle()", function() {
80 ok( x.is(":visible") );
82 ok( x.is(":hidden") );
84 ok( x.is(":visible") );
88 Normal: function(elem){},
89 "CSS Hidden": function(elem){
90 $(this).addClass("hidden");
92 "JS Hidden": function(elem){
98 "CSS Auto": function(elem,prop){
99 $(elem).addClass("auto" + prop)
100 .text("This is a long string of text.");
103 "JS Auto": function(elem,prop){
104 $(elem).css(prop,"auto")
105 .text("This is a long string of text.");
108 "CSS 100": function(elem,prop){
109 $(elem).addClass("large" + prop);
112 "JS 100": function(elem,prop){
113 $(elem).css(prop,prop == "opacity" ? 1 : "100px");
114 return prop == "opacity" ? 1 : 100;
116 "CSS 50": function(elem,prop){
117 $(elem).addClass("med" + prop);
120 "JS 50": function(elem,prop){
121 $(elem).css(prop,prop == "opacity" ? 0.50 : "50px");
122 return prop == "opacity" ? 0.5 : 50;
124 "CSS 0": function(elem,prop){
125 $(elem).addClass("no" + prop);
128 "JS 0": function(elem,prop){
129 $(elem).css(prop,prop == "opacity" ? 0 : "0px");
135 "show": function(elem,prop){
136 $(elem).hide().addClass("wide"+prop);
139 "hide": function(elem,prop){
140 $(elem).addClass("wide"+prop);
143 "100": function(elem,prop){
144 $(elem).addClass("wide"+prop);
145 return prop == "opacity" ? 1 : 100;
147 "50": function(elem,prop){
148 return prop == "opacity" ? 0.50 : 50;
150 "0": function(elem,prop){
151 $(elem).addClass("noback");
156 function checkOverflowDisplay(){
157 var o = jQuery.css( this, "overflow" );
159 ok(o == "visible", "Overflow should be visible: " + o);
160 ok(jQuery.css( this, "display" ) == "inline", "Display shouldn't be tampered with.");
165 test("JS Overflow and Display", function() {
168 makeTest( "JS Overflow and Display" )
169 .addClass("widewidth")
170 .css({ overflow: "visible", display: "inline" })
171 .addClass("widewidth")
172 .text("Some sample text.")
173 .before("text before")
175 .animate({ opacity: 0.5 }, "slow", checkOverflowDisplay);
178 test("CSS Overflow and Display", function() {
181 makeTest( "CSS Overflow and Display" )
182 .addClass("overflow inline")
183 .addClass("widewidth")
184 .text("Some sample text.")
185 .before("text before")
187 .animate({ opacity: 0.5 }, "slow", checkOverflowDisplay);
190 jQuery.each( from, function(fn, f){
191 jQuery.each( to, function(tn, t){
192 test(fn + " to " + tn, function() {
193 var elem = makeTest( fn + " to " + tn );
195 var t_w = t( elem, "width" );
196 var f_w = f( elem, "width" );
197 var t_h = t( elem, "height" );
198 var f_h = f( elem, "height" );
199 var t_o = t( elem, "opacity" );
200 var f_o = f( elem, "opacity" );
204 if ( t_h == "show" ) num++;
205 if ( t_w == "show" ) num++;
206 if ( t_w == "hide"||t_w == "show" ) num++;
207 if ( t_h == "hide"||t_h == "show" ) num++;
208 if ( t_o == "hide"||t_o == "show" ) num++;
209 if ( t_w == "hide" ) num++;
210 if ( t_o.constructor == Number ) num += 2;
211 if ( t_w.constructor == Number ) num += 2;
212 if ( t_h.constructor == Number ) num +=2;
217 var anim = { width: t_w, height: t_h, opacity: t_o };
219 elem.animate(anim, 50, function(){
221 ok( this.style.display == "block", "Showing, display should block: " + this.style.display);
223 if ( t_w == "hide"||t_w == "show" )
224 ok(this.style.width.indexOf(f_w) == 0, "Width must be reset to " + f_w + ": " + this.style.width);
226 if ( t_h == "hide"||t_h == "show" )
227 ok(this.style.height.indexOf(f_h) == 0, "Height must be reset to " + f_h + ": " + this.style.height);
229 var cur_o = jQuery.attr(this.style, "opacity");
230 if ( cur_o !== "" ) cur_o = parseFloat( cur_o );
232 if ( t_o == "hide"||t_o == "show" )
233 ok(cur_o == f_o, "Opacity must be reset to " + f_o + ": " + cur_o);
236 ok(this.style.display == "none", "Hiding, display should be none: " + this.style.display);
238 if ( t_o.constructor == Number ) {
239 ok(cur_o == t_o, "Final opacity should be " + t_o + ": " + cur_o);
241 ok(jQuery.curCSS(this, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o);
244 if ( t_w.constructor == Number ) {
245 ok(this.style.width == t_w + "px", "Final width should be " + t_w + ": " + this.style.width);
247 var cur_w = jQuery.css(this,"width");
249 ok(this.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w);
252 if ( t_h.constructor == Number ) {
253 ok(this.style.height == t_h + "px", "Final height should be " + t_h + ": " + this.style.height);
255 var cur_h = jQuery.css(this,"height");
257 ok(this.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w);
260 if ( t_h == "show" ) {
261 var old_h = jQuery.curCSS(this, "height");
262 $(elem).append("<br/>Some more text<br/>and some more...");
263 ok(old_h != jQuery.css(this, "height" ), "Make sure height is auto.");
272 var check = ['opacity','height','width','display','overflow'];
274 jQuery.fn.saveState = function(){
275 expect(check.length);
277 return this.each(function(){
280 jQuery.each(check, function(i,c){
281 self.save[c] = jQuery.css(self,c);
286 function checkState(){
288 jQuery.each(this.save, function(c,v){
289 var cur = jQuery.css(self,c);
290 ok( v == cur, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")");
296 test("Chain fadeOut fadeIn", function() {
297 $('#fadein div').saveState().fadeOut('fast').fadeIn('fast',checkState);
299 test("Chain fadeIn fadeOut", function() {
300 $('#fadeout div').saveState().fadeIn('fast').fadeOut('fast',checkState);
303 test("Chain hide show", function() {
304 $('#show div').saveState().hide('fast').show('fast',checkState);
306 test("Chain show hide", function() {
307 $('#hide div').saveState().show('fast').hide('fast',checkState);
310 test("Chain toggle in", function() {
311 $('#togglein div').saveState().toggle('fast').toggle('fast',checkState);
313 test("Chain toggle out", function() {
314 $('#toggleout div').saveState().toggle('fast').toggle('fast',checkState);
317 test("Chain slideDown slideUp", function() {
318 $('#slidedown div').saveState().slideDown('fast').slideUp('fast',checkState);
320 test("Chain slideUp slideDown", function() {
321 $('#slideup div').saveState().slideUp('fast').slideDown('fast',checkState);
324 test("Chain slideToggle in", function() {
325 $('#slidetogglein div').saveState().slideToggle('fast').slideToggle('fast',checkState);
327 test("Chain slideToggle out", function() {
328 $('#slidetoggleout div').saveState().slideToggle('fast').slideToggle('fast',checkState);
331 function makeTest( text ){
332 var elem = $("<div></div>")
333 .attr("id", "test" + makeTest.id++)
338 .appendTo("#fx-tests")
340 $(this).next().toggle();