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] );
37 test("stop()", function() {
42 var foo = $("#foo")[0];
43 var h = foo.style.height;
45 $("#foo").slideUp(1000);
46 setTimeout(function(){
47 var nh = foo.style.height;
48 ok( nh != h, "An animation occurred " + nh + " " + h );
51 nh = foo.style.height;
52 ok( nh != h, "Stop didn't reset the animation " + nh + " " + h );
53 setTimeout(function(){
54 equals( nh, foo.style.height, "The animation didn't continue" );
60 test("toggle()", function() {
63 ok( x.is(":visible") );
65 ok( x.is(":hidden") );
67 ok( x.is(":visible") );
71 Normal: function(elem){},
72 "CSS Hidden": function(elem){
73 $(this).addClass("hidden");
75 "JS Hidden": function(elem){
81 "CSS Auto": function(elem,prop){
82 $(elem).addClass("auto" + prop)
83 .text("This is a long string of text.");
86 "JS Auto": function(elem,prop){
87 $(elem).css(prop,"auto")
88 .text("This is a long string of text.");
91 "CSS 100": function(elem,prop){
92 $(elem).addClass("large" + prop);
95 "JS 100": function(elem,prop){
96 $(elem).css(prop,prop == "opacity" ? 1 : "100px");
97 return prop == "opacity" ? 1 : 100;
99 "CSS 50": function(elem,prop){
100 $(elem).addClass("med" + prop);
103 "JS 50": function(elem,prop){
104 $(elem).css(prop,prop == "opacity" ? 0.50 : "50px");
105 return prop == "opacity" ? 0.5 : 50;
107 "CSS 0": function(elem,prop){
108 $(elem).addClass("no" + prop);
111 "JS 0": function(elem,prop){
112 $(elem).css(prop,prop == "opacity" ? 0 : "0px");
118 "show": function(elem,prop){
119 $(elem).hide().addClass("wide"+prop);
122 "hide": function(elem,prop){
123 $(elem).addClass("wide"+prop);
126 "100": function(elem,prop){
127 $(elem).addClass("wide"+prop);
128 return prop == "opacity" ? 1 : 100;
130 "50": function(elem,prop){
131 return prop == "opacity" ? 0.50 : 50;
133 "0": function(elem,prop){
134 $(elem).addClass("noback");
139 function checkOverflowDisplay(){
140 var o = jQuery.css( this, "overflow" );
142 ok(o == "visible", "Overflow should be visible: " + o);
143 ok(jQuery.css( this, "display" ) == "inline", "Display shouldn't be tampered with.");
148 test("JS Overflow and Display", function() {
151 makeTest( "JS Overflow and Display" )
152 .addClass("widewidth")
153 .css({ overflow: "visible", display: "inline" })
154 .addClass("widewidth")
155 .text("Some sample text.")
156 .before("text before")
158 .animate({ opacity: 0.5 }, "slow", checkOverflowDisplay);
161 test("CSS Overflow and Display", function() {
164 makeTest( "CSS Overflow and Display" )
165 .addClass("overflow inline")
166 .addClass("widewidth")
167 .text("Some sample text.")
168 .before("text before")
170 .animate({ opacity: 0.5 }, "slow", checkOverflowDisplay);
173 jQuery.each( from, function(fn, f){
174 jQuery.each( to, function(tn, t){
175 test(fn + " to " + tn, function() {
176 var elem = makeTest( fn + " to " + tn );
178 var t_w = t( elem, "width" );
179 var f_w = f( elem, "width" );
180 var t_h = t( elem, "height" );
181 var f_h = f( elem, "height" );
182 var t_o = t( elem, "opacity" );
183 var f_o = f( elem, "opacity" );
187 if ( t_h == "show" ) num++;
188 if ( t_w == "show" ) num++;
189 if ( t_w == "hide"||t_w == "show" ) num++;
190 if ( t_h == "hide"||t_h == "show" ) num++;
191 if ( t_o == "hide"||t_o == "show" ) num++;
192 if ( t_w == "hide" ) num++;
193 if ( t_o.constructor == Number ) num += 2;
194 if ( t_w.constructor == Number ) num += 2;
195 if ( t_h.constructor == Number ) num +=2;
200 var anim = { width: t_w, height: t_h, opacity: t_o };
202 elem.animate(anim, 50, function(){
204 ok( this.style.display == "block", "Showing, display should block: " + this.style.display);
206 if ( t_w == "hide"||t_w == "show" )
207 ok(this.style.width.indexOf(f_w) == 0, "Width must be reset to " + f_w + ": " + this.style.width);
209 if ( t_h == "hide"||t_h == "show" )
210 ok(this.style.height.indexOf(f_h) == 0, "Height must be reset to " + f_h + ": " + this.style.height);
212 var cur_o = jQuery.attr(this.style, "opacity");
213 if ( cur_o !== "" ) cur_o = parseFloat( cur_o );
215 if ( t_o == "hide"||t_o == "show" )
216 ok(cur_o == f_o, "Opacity must be reset to " + f_o + ": " + cur_o);
219 ok(this.style.display == "none", "Hiding, display should be none: " + this.style.display);
221 if ( t_o.constructor == Number ) {
222 ok(cur_o == t_o, "Final opacity should be " + t_o + ": " + cur_o);
224 ok(jQuery.curCSS(this, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o);
227 if ( t_w.constructor == Number ) {
228 ok(this.style.width == t_w + "px", "Final width should be " + t_w + ": " + this.style.width);
230 var cur_w = jQuery.css(this,"width");
232 ok(this.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w);
235 if ( t_h.constructor == Number ) {
236 ok(this.style.height == t_h + "px", "Final height should be " + t_h + ": " + this.style.height);
238 var cur_h = jQuery.css(this,"height");
240 ok(this.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w);
243 if ( t_h == "show" ) {
244 var old_h = jQuery.curCSS(this, "height");
245 $(elem).append("<br/>Some more text<br/>and some more...");
246 ok(old_h != jQuery.css(this, "height" ), "Make sure height is auto.");
255 var check = ['opacity','height','width','display','overflow'];
257 jQuery.fn.saveState = function(){
258 expect(check.length);
260 return this.each(function(){
263 jQuery.each(check, function(i,c){
264 self.save[c] = jQuery.css(self,c);
269 function checkState(){
271 jQuery.each(this.save, function(c,v){
272 var cur = jQuery.css(self,c);
273 ok( v == cur, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")");
279 test("Chain fadeOut fadeIn", function() {
280 $('#fadein div').saveState().fadeOut('fast').fadeIn('fast',checkState);
282 test("Chain fadeIn fadeOut", function() {
283 $('#fadeout div').saveState().fadeIn('fast').fadeOut('fast',checkState);
286 test("Chain hide show", function() {
287 $('#show div').saveState().hide('fast').show('fast',checkState);
289 test("Chain show hide", function() {
290 $('#hide div').saveState().show('fast').hide('fast',checkState);
293 test("Chain toggle in", function() {
294 $('#togglein div').saveState().toggle('fast').toggle('fast',checkState);
296 test("Chain toggle out", function() {
297 $('#toggleout div').saveState().toggle('fast').toggle('fast',checkState);
300 test("Chain slideDown slideUp", function() {
301 $('#slidedown div').saveState().slideDown('fast').slideUp('fast',checkState);
303 test("Chain slideUp slideDown", function() {
304 $('#slideup div').saveState().slideUp('fast').slideDown('fast',checkState);
307 test("Chain slideToggle in", function() {
308 $('#slidetogglein div').saveState().slideToggle('fast').slideToggle('fast',checkState);
310 test("Chain slideToggle out", function() {
311 $('#slidetoggleout div').saveState().slideToggle('fast').slideToggle('fast',checkState);
314 function makeTest( text ){
315 var elem = $("<div></div>")
316 .attr("id", "test" + makeTest.id++)
321 .appendTo("#fx-tests")
323 $(this).next().toggle();