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("stop()", function() {
41 var $foo = jQuery("#nothiddendiv");
43 $foo.hide().width(200).width();
45 $foo.animate({ width:'show' }, 1000);
46 setTimeout(function(){
47 var nw = $foo.width();
48 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
52 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
53 setTimeout(function(){
54 equals( nw, $foo.width(), "The animation didn't continue" );
60 test("stop() - several in queue", function() {
64 var $foo = jQuery("#nothiddendiv");
66 $foo.hide().width(200).width();
68 $foo.animate({ width:'show' }, 1000);
69 $foo.animate({ width:'hide' }, 1000);
70 $foo.animate({ width:'show' }, 1000);
71 setTimeout(function(){
72 equals( $foo.queue().length, 3, "All 3 still in the queue" );
73 var nw = $foo.width();
74 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
78 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
79 equals( $foo.queue().length, 2, "The next animation continued" );
85 test("stop(clearQueue)", function() {
89 var $foo = jQuery("#nothiddendiv");
91 $foo.hide().width(200).width();
93 $foo.animate({ width:'show' }, 1000);
94 $foo.animate({ width:'hide' }, 1000);
95 $foo.animate({ width:'show' }, 1000);
96 setTimeout(function(){
97 var nw = $foo.width();
98 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
102 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
104 equals( $foo.queue().length, 0, "The animation queue was cleared" );
105 setTimeout(function(){
106 equals( nw, $foo.width(), "The animation didn't continue" );
112 test("stop(clearQueue, gotoEnd)", function() {
116 var $foo = jQuery("#nothiddendiv");
118 $foo.hide().width(200).width();
120 $foo.animate({ width:'show' }, 1000);
121 $foo.animate({ width:'hide' }, 1000);
122 $foo.animate({ width:'show' }, 1000);
123 $foo.animate({ width:'hide' }, 1000);
124 setTimeout(function(){
125 var nw = $foo.width();
126 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
127 $foo.stop(false, true);
130 equals( nw, 200, "Stop() reset the animation" );
132 setTimeout(function(){
133 equals( $foo.queue().length, 3, "The next animation continued" );
140 test("toggle()", function() {
142 var x = jQuery("#foo");
143 ok( x.is(":visible"), "is visible" );
145 ok( x.is(":hidden"), "is hidden" );
147 ok( x.is(":visible"), "is visible again" );
150 ok( x.is(":visible"), "is visible" );
152 ok( x.is(":hidden"), "is hidden" );
154 ok( x.is(":visible"), "is visible again" );
158 Normal: function(elem){},
159 "CSS Hidden": function(elem){
160 jQuery(this).addClass("hidden");
162 "JS Hidden": function(elem){
168 "CSS Auto": function(elem,prop){
169 jQuery(elem).addClass("auto" + prop)
170 .text("This is a long string of text.");
173 "JS Auto": function(elem,prop){
174 jQuery(elem).css(prop,"auto")
175 .text("This is a long string of text.");
178 "CSS 100": function(elem,prop){
179 jQuery(elem).addClass("large" + prop);
182 "JS 100": function(elem,prop){
183 jQuery(elem).css(prop,prop == "opacity" ? 1 : "100px");
184 return prop == "opacity" ? 1 : 100;
186 "CSS 50": function(elem,prop){
187 jQuery(elem).addClass("med" + prop);
190 "JS 50": function(elem,prop){
191 jQuery(elem).css(prop,prop == "opacity" ? 0.50 : "50px");
192 return prop == "opacity" ? 0.5 : 50;
194 "CSS 0": function(elem,prop){
195 jQuery(elem).addClass("no" + prop);
198 "JS 0": function(elem,prop){
199 jQuery(elem).css(prop,prop == "opacity" ? 0 : "0px");
205 "show": function(elem,prop){
206 jQuery(elem).hide().addClass("wide"+prop);
209 "hide": function(elem,prop){
210 jQuery(elem).addClass("wide"+prop);
213 "100": function(elem,prop){
214 jQuery(elem).addClass("wide"+prop);
215 return prop == "opacity" ? 1 : 100;
217 "50": function(elem,prop){
218 return prop == "opacity" ? 0.50 : 50;
220 "0": function(elem,prop){
221 jQuery(elem).addClass("noback");
226 function checkOverflowDisplay(){
227 var o = jQuery.css( this, "overflow" );
229 equals(o, "visible", "Overflow should be visible: " + o);
230 equals(jQuery.css( this, "display" ), "inline", "Display shouldn't be tampered with.");
235 test("JS Overflow and Display", function() {
238 makeTest( "JS Overflow and Display" )
239 .addClass("widewidth")
240 .css({ overflow: "visible", display: "inline" })
241 .addClass("widewidth")
242 .text("Some sample text.")
243 .before("text before")
245 .animate({ opacity: 0.5 }, "slow", checkOverflowDisplay);
248 test("CSS Overflow and Display", function() {
251 makeTest( "CSS Overflow and Display" )
252 .addClass("overflow inline")
253 .addClass("widewidth")
254 .text("Some sample text.")
255 .before("text before")
257 .animate({ opacity: 0.5 }, "slow", checkOverflowDisplay);
260 jQuery.each( from, function(fn, f){
261 jQuery.each( to, function(tn, t){
262 test(fn + " to " + tn, function() {
263 var elem = makeTest( fn + " to " + tn );
265 var t_w = t( elem, "width" );
266 var f_w = f( elem, "width" );
267 var t_h = t( elem, "height" );
268 var f_h = f( elem, "height" );
269 var t_o = t( elem, "opacity" );
270 var f_o = f( elem, "opacity" );
274 if ( t_h == "show" ) num++;
275 if ( t_w == "show" ) num++;
276 if ( t_w == "hide"||t_w == "show" ) num++;
277 if ( t_h == "hide"||t_h == "show" ) num++;
278 if ( t_o == "hide"||t_o == "show" ) num++;
279 if ( t_w == "hide" ) num++;
280 if ( t_o.constructor == Number ) num += 2;
281 if ( t_w.constructor == Number ) num += 2;
282 if ( t_h.constructor == Number ) num +=2;
287 var anim = { width: t_w, height: t_h, opacity: t_o };
289 elem.animate(anim, 50, function(){
291 equals( this.style.display, "block", "Showing, display should block: " + this.style.display);
293 if ( t_w == "hide"||t_w == "show" )
294 equals(this.style.width.indexOf(f_w), 0, "Width must be reset to " + f_w + ": " + this.style.width);
296 if ( t_h == "hide"||t_h == "show" )
297 equals(this.style.height.indexOf(f_h), 0, "Height must be reset to " + f_h + ": " + this.style.height);
299 var cur_o = jQuery.attr(this.style, "opacity");
300 if ( cur_o !== "" ) cur_o = parseFloat( cur_o );
302 if ( t_o == "hide"||t_o == "show" )
303 equals(cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o);
306 equals(this.style.display, "none", "Hiding, display should be none: " + this.style.display);
308 if ( t_o.constructor == Number ) {
309 equals(cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o);
311 ok(jQuery.curCSS(this, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o);
314 if ( t_w.constructor == Number ) {
315 equals(this.style.width, t_w + "px", "Final width should be " + t_w + ": " + this.style.width);
317 var cur_w = jQuery.css(this,"width");
319 ok(this.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w);
322 if ( t_h.constructor == Number ) {
323 equals(this.style.height, t_h + "px", "Final height should be " + t_h + ": " + this.style.height);
325 var cur_h = jQuery.css(this,"height");
327 ok(this.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w);
330 if ( t_h == "show" ) {
331 var old_h = jQuery.curCSS(this, "height");
332 jQuery(elem).append("<br/>Some more text<br/>and some more...");
333 ok(old_h != jQuery.css(this, "height" ), "Make sure height is auto.");
342 var check = ['opacity','height','width','display','overflow'];
344 jQuery.fn.saveState = function(){
345 expect(check.length);
347 return this.each(function(){
350 jQuery.each(check, function(i,c){
351 self.save[c] = jQuery.css(self,c);
356 function checkState(){
358 jQuery.each(this.save, function(c,v){
359 var cur = jQuery.css(self,c);
360 equals( v, cur, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")");
366 test("Chain fadeOut fadeIn", function() {
367 jQuery('#fadein div').saveState().fadeOut('fast').fadeIn('fast',checkState);
369 test("Chain fadeIn fadeOut", function() {
370 jQuery('#fadeout div').saveState().fadeIn('fast').fadeOut('fast',checkState);
373 test("Chain hide show", function() {
374 jQuery('#show div').saveState().hide('fast').show('fast',checkState);
376 test("Chain show hide", function() {
377 jQuery('#hide div').saveState().show('fast').hide('fast',checkState);
380 test("Chain toggle in", function() {
381 jQuery('#togglein div').saveState().toggle('fast').toggle('fast',checkState);
383 test("Chain toggle out", function() {
384 jQuery('#toggleout div').saveState().toggle('fast').toggle('fast',checkState);
387 test("Chain slideDown slideUp", function() {
388 jQuery('#slidedown div').saveState().slideDown('fast').slideUp('fast',checkState);
390 test("Chain slideUp slideDown", function() {
391 jQuery('#slideup div').saveState().slideUp('fast').slideDown('fast',checkState);
394 test("Chain slideToggle in", function() {
395 jQuery('#slidetogglein div').saveState().slideToggle('fast').slideToggle('fast',checkState);
397 test("Chain slideToggle out", function() {
398 jQuery('#slidetoggleout div').saveState().slideToggle('fast').slideToggle('fast',checkState);
401 function makeTest( text ){
402 var elem = jQuery("<div></div>")
403 .attr("id", "test" + makeTest.id++)
408 .appendTo("#fx-tests")
410 jQuery(this).next().toggle();