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("animate non-element", function(){
41 var obj = { test: 0 };
43 jQuery(obj).animate({test: 200}, 200, function(){
44 equals( obj.test, 200, "The custom property should be modified." );
49 test("stop()", function() {
53 var $foo = jQuery("#nothiddendiv");
55 $foo.hide().width(200).width();
57 $foo.animate({ width:'show' }, 1000);
58 setTimeout(function(){
59 var nw = $foo.width();
60 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
64 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
65 setTimeout(function(){
66 equals( nw, $foo.width(), "The animation didn't continue" );
72 test("stop() - several in queue", function() {
76 var $foo = jQuery("#nothiddendiv");
78 $foo.hide().width(200).width();
80 $foo.animate({ width:'show' }, 1000);
81 $foo.animate({ width:'hide' }, 1000);
82 $foo.animate({ width:'show' }, 1000);
83 setTimeout(function(){
84 equals( $foo.queue().length, 3, "All 3 still in the queue" );
85 var nw = $foo.width();
86 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
90 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
91 equals( $foo.queue().length, 2, "The next animation continued" );
97 test("stop(clearQueue)", function() {
101 var $foo = jQuery("#nothiddendiv");
103 $foo.hide().width(200).width();
105 $foo.animate({ width:'show' }, 1000);
106 $foo.animate({ width:'hide' }, 1000);
107 $foo.animate({ width:'show' }, 1000);
108 setTimeout(function(){
109 var nw = $foo.width();
110 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
114 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
116 equals( $foo.queue().length, 0, "The animation queue was cleared" );
117 setTimeout(function(){
118 equals( nw, $foo.width(), "The animation didn't continue" );
124 test("stop(clearQueue, gotoEnd)", function() {
128 var $foo = jQuery("#nothiddendiv");
130 $foo.hide().width(200).width();
132 $foo.animate({ width:'show' }, 1000);
133 $foo.animate({ width:'hide' }, 1000);
134 $foo.animate({ width:'show' }, 1000);
135 $foo.animate({ width:'hide' }, 1000);
136 setTimeout(function(){
137 var nw = $foo.width();
138 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
139 $foo.stop(false, true);
142 equals( nw, 200, "Stop() reset the animation" );
144 setTimeout(function(){
145 equals( $foo.queue().length, 3, "The next animation continued" );
152 test("toggle()", function() {
154 var x = jQuery("#foo");
155 ok( x.is(":visible"), "is visible" );
157 ok( x.is(":hidden"), "is hidden" );
159 ok( x.is(":visible"), "is visible again" );
162 ok( x.is(":visible"), "is visible" );
164 ok( x.is(":hidden"), "is hidden" );
166 ok( x.is(":visible"), "is visible again" );
170 Normal: function(elem){},
171 "CSS Hidden": function(elem){
172 jQuery(this).addClass("hidden");
174 "JS Hidden": function(elem){
180 "CSS Auto": function(elem,prop){
181 jQuery(elem).addClass("auto" + prop)
182 .text("This is a long string of text.");
185 "JS Auto": function(elem,prop){
186 jQuery(elem).css(prop,"auto")
187 .text("This is a long string of text.");
190 "CSS 100": function(elem,prop){
191 jQuery(elem).addClass("large" + prop);
194 "JS 100": function(elem,prop){
195 jQuery(elem).css(prop,prop == "opacity" ? 1 : "100px");
196 return prop == "opacity" ? 1 : 100;
198 "CSS 50": function(elem,prop){
199 jQuery(elem).addClass("med" + prop);
202 "JS 50": function(elem,prop){
203 jQuery(elem).css(prop,prop == "opacity" ? 0.50 : "50px");
204 return prop == "opacity" ? 0.5 : 50;
206 "CSS 0": function(elem,prop){
207 jQuery(elem).addClass("no" + prop);
210 "JS 0": function(elem,prop){
211 jQuery(elem).css(prop,prop == "opacity" ? 0 : "0px");
217 "show": function(elem,prop){
218 jQuery(elem).hide().addClass("wide"+prop);
221 "hide": function(elem,prop){
222 jQuery(elem).addClass("wide"+prop);
225 "100": function(elem,prop){
226 jQuery(elem).addClass("wide"+prop);
227 return prop == "opacity" ? 1 : 100;
229 "50": function(elem,prop){
230 return prop == "opacity" ? 0.50 : 50;
232 "0": function(elem,prop){
233 jQuery(elem).addClass("noback");
238 function checkOverflowDisplay(){
239 var o = jQuery.css( this, "overflow" );
241 equals(o, "visible", "Overflow should be visible: " + o);
242 equals(jQuery.css( this, "display" ), "inline", "Display shouldn't be tampered with.");
247 test("JS Overflow and Display", function() {
250 makeTest( "JS Overflow and Display" )
251 .addClass("widewidth")
252 .css({ overflow: "visible", display: "inline" })
253 .addClass("widewidth")
254 .text("Some sample text.")
255 .before("text before")
257 .animate({ opacity: 0.5 }, "slow", checkOverflowDisplay);
260 test("CSS Overflow and Display", function() {
263 makeTest( "CSS Overflow and Display" )
264 .addClass("overflow inline")
265 .addClass("widewidth")
266 .text("Some sample text.")
267 .before("text before")
269 .animate({ opacity: 0.5 }, "slow", checkOverflowDisplay);
272 jQuery.each( from, function(fn, f){
273 jQuery.each( to, function(tn, t){
274 test(fn + " to " + tn, function() {
275 var elem = makeTest( fn + " to " + tn );
277 var t_w = t( elem, "width" );
278 var f_w = f( elem, "width" );
279 var t_h = t( elem, "height" );
280 var f_h = f( elem, "height" );
281 var t_o = t( elem, "opacity" );
282 var f_o = f( elem, "opacity" );
286 if ( t_h == "show" ) num++;
287 if ( t_w == "show" ) num++;
288 if ( t_w == "hide"||t_w == "show" ) num++;
289 if ( t_h == "hide"||t_h == "show" ) num++;
290 if ( t_o == "hide"||t_o == "show" ) num++;
291 if ( t_w == "hide" ) num++;
292 if ( t_o.constructor == Number ) num += 2;
293 if ( t_w.constructor == Number ) num += 2;
294 if ( t_h.constructor == Number ) num +=2;
299 var anim = { width: t_w, height: t_h, opacity: t_o };
301 elem.animate(anim, 50, function(){
303 equals( this.style.display, "block", "Showing, display should block: " + this.style.display);
305 if ( t_w == "hide"||t_w == "show" )
306 equals(this.style.width.indexOf(f_w), 0, "Width must be reset to " + f_w + ": " + this.style.width);
308 if ( t_h == "hide"||t_h == "show" )
309 equals(this.style.height.indexOf(f_h), 0, "Height must be reset to " + f_h + ": " + this.style.height);
311 var cur_o = jQuery.attr(this.style, "opacity");
312 if ( cur_o !== "" ) cur_o = parseFloat( cur_o );
314 if ( t_o == "hide"||t_o == "show" )
315 equals(cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o);
318 equals(this.style.display, "none", "Hiding, display should be none: " + this.style.display);
320 if ( t_o.constructor == Number ) {
321 equals(cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o);
323 ok(jQuery.curCSS(this, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o);
326 if ( t_w.constructor == Number ) {
327 equals(this.style.width, t_w + "px", "Final width should be " + t_w + ": " + this.style.width);
329 var cur_w = jQuery.css(this,"width");
331 ok(this.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w);
334 if ( t_h.constructor == Number ) {
335 equals(this.style.height, t_h + "px", "Final height should be " + t_h + ": " + this.style.height);
337 var cur_h = jQuery.css(this,"height");
339 ok(this.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w);
342 if ( t_h == "show" ) {
343 var old_h = jQuery.curCSS(this, "height");
344 jQuery(elem).append("<br/>Some more text<br/>and some more...");
345 ok(old_h != jQuery.css(this, "height" ), "Make sure height is auto.");
354 var check = ['opacity','height','width','display','overflow'];
356 jQuery.fn.saveState = function(){
357 expect(check.length);
359 return this.each(function(){
362 jQuery.each(check, function(i,c){
363 self.save[c] = jQuery.css(self,c);
368 function checkState(){
370 jQuery.each(this.save, function(c,v){
371 var cur = jQuery.css(self,c);
372 equals( v, cur, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")");
378 test("Chain fadeOut fadeIn", function() {
379 jQuery('#fadein div').saveState().fadeOut('fast').fadeIn('fast',checkState);
381 test("Chain fadeIn fadeOut", function() {
382 jQuery('#fadeout div').saveState().fadeIn('fast').fadeOut('fast',checkState);
385 test("Chain hide show", function() {
386 jQuery('#show div').saveState().hide('fast').show('fast',checkState);
388 test("Chain show hide", function() {
389 jQuery('#hide div').saveState().show('fast').hide('fast',checkState);
392 test("Chain toggle in", function() {
393 jQuery('#togglein div').saveState().toggle('fast').toggle('fast',checkState);
395 test("Chain toggle out", function() {
396 jQuery('#toggleout div').saveState().toggle('fast').toggle('fast',checkState);
399 test("Chain slideDown slideUp", function() {
400 jQuery('#slidedown div').saveState().slideDown('fast').slideUp('fast',checkState);
402 test("Chain slideUp slideDown", function() {
403 jQuery('#slideup div').saveState().slideUp('fast').slideDown('fast',checkState);
406 test("Chain slideToggle in", function() {
407 jQuery('#slidetogglein div').saveState().slideToggle('fast').slideToggle('fast',checkState);
409 test("Chain slideToggle out", function() {
410 jQuery('#slidetoggleout div').saveState().slideToggle('fast').slideToggle('fast',checkState);
413 function makeTest( text ){
414 var elem = jQuery("<div></div>")
415 .attr("id", "test" + makeTest.id++)
420 .appendTo("#fx-tests")
422 jQuery(this).next().toggle();