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" );
169 jQuery.checkOverflowDisplay = function(){
170 var o = jQuery.css( this, "overflow" );
172 equals(o, "visible", "Overflow should be visible: " + o);
173 equals(jQuery.css( this, "display" ), "inline", "Display shouldn't be tampered with.");
178 test("JS Overflow and Display", function() {
181 jQuery.makeTest( "JS Overflow and Display" )
182 .addClass("widewidth")
183 .css({ overflow: "visible", display: "inline" })
184 .addClass("widewidth")
185 .text("Some sample text.")
186 .before("text before")
188 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
191 test("CSS Overflow and Display", function() {
194 jQuery.makeTest( "CSS Overflow and Display" )
195 .addClass("overflow inline")
196 .addClass("widewidth")
197 .text("Some sample text.")
198 .before("text before")
200 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
204 "CSS Auto": function(elem,prop){
205 jQuery(elem).addClass("auto" + prop)
206 .text("This is a long string of text.");
209 "JS Auto": function(elem,prop){
210 jQuery(elem).css(prop,"auto")
211 .text("This is a long string of text.");
214 "CSS 100": function(elem,prop){
215 jQuery(elem).addClass("large" + prop);
218 "JS 100": function(elem,prop){
219 jQuery(elem).css(prop,prop == "opacity" ? 1 : "100px");
220 return prop == "opacity" ? 1 : 100;
222 "CSS 50": function(elem,prop){
223 jQuery(elem).addClass("med" + prop);
226 "JS 50": function(elem,prop){
227 jQuery(elem).css(prop,prop == "opacity" ? 0.50 : "50px");
228 return prop == "opacity" ? 0.5 : 50;
230 "CSS 0": function(elem,prop){
231 jQuery(elem).addClass("no" + prop);
234 "JS 0": function(elem,prop){
235 jQuery(elem).css(prop,prop == "opacity" ? 0 : "0px");
240 "show": function(elem,prop){
241 jQuery(elem).hide().addClass("wide"+prop);
244 "hide": function(elem,prop){
245 jQuery(elem).addClass("wide"+prop);
248 "100": function(elem,prop){
249 jQuery(elem).addClass("wide"+prop);
250 return prop == "opacity" ? 1 : 100;
252 "50": function(elem,prop){
253 return prop == "opacity" ? 0.50 : 50;
255 "0": function(elem,prop){
256 jQuery(elem).addClass("noback");
260 test(fn + " to " + tn, function() {
261 var elem = jQuery.makeTest( fn + " to " + tn );
263 var t_w = t( elem, "width" );
264 var f_w = f( elem, "width" );
265 var t_h = t( elem, "height" );
266 var f_h = f( elem, "height" );
267 var t_o = t( elem, "opacity" );
268 var f_o = f( elem, "opacity" );
272 if ( t_h == "show" ) num++;
273 if ( t_w == "show" ) num++;
274 if ( t_w == "hide"||t_w == "show" ) num++;
275 if ( t_h == "hide"||t_h == "show" ) num++;
276 if ( t_o == "hide"||t_o == "show" ) num++;
277 if ( t_w == "hide" ) num++;
278 if ( t_o.constructor == Number ) num += 2;
279 if ( t_w.constructor == Number ) num += 2;
280 if ( t_h.constructor == Number ) num +=2;
285 var anim = { width: t_w, height: t_h, opacity: t_o };
287 elem.animate(anim, 50, function(){
289 equals( this.style.display, "block", "Showing, display should block: " + this.style.display);
291 if ( t_w == "hide"||t_w == "show" )
292 equals(this.style.width.indexOf(f_w), 0, "Width must be reset to " + f_w + ": " + this.style.width);
294 if ( t_h == "hide"||t_h == "show" )
295 equals(this.style.height.indexOf(f_h), 0, "Height must be reset to " + f_h + ": " + this.style.height);
297 var cur_o = jQuery.attr(this.style, "opacity");
298 if ( cur_o !== "" ) cur_o = parseFloat( cur_o );
300 if ( t_o == "hide"||t_o == "show" )
301 equals(cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o);
304 equals(this.style.display, "none", "Hiding, display should be none: " + this.style.display);
306 if ( t_o.constructor == Number ) {
307 equals(cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o);
309 ok(jQuery.curCSS(this, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o);
312 if ( t_w.constructor == Number ) {
313 equals(this.style.width, t_w + "px", "Final width should be " + t_w + ": " + this.style.width);
315 var cur_w = jQuery.css(this,"width");
317 ok(this.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w);
320 if ( t_h.constructor == Number ) {
321 equals(this.style.height, t_h + "px", "Final height should be " + t_h + ": " + this.style.height);
323 var cur_h = jQuery.css(this,"height");
325 ok(this.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w);
328 if ( t_h == "show" ) {
329 var old_h = jQuery.curCSS(this, "height");
330 jQuery(elem).append("<br/>Some more text<br/>and some more...");
331 ok(old_h != jQuery.css(this, "height" ), "Make sure height is auto.");
340 jQuery.fn.saveState = function(){
341 var check = ['opacity','height','width','display','overflow'];
342 expect(check.length);
345 return this.each(function(){
348 jQuery.each(check, function(i,c){
349 self.save[c] = jQuery.css(self,c);
354 jQuery.checkState = function(){
356 jQuery.each(this.save, function(c,v){
357 var cur = jQuery.css(self,c);
358 equals( v, cur, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")");
364 test("Chain fadeOut fadeIn", function() {
365 jQuery('#fadein div').saveState().fadeOut('fast').fadeIn('fast',jQuery.checkState);
367 test("Chain fadeIn fadeOut", function() {
368 jQuery('#fadeout div').saveState().fadeIn('fast').fadeOut('fast',jQuery.checkState);
371 test("Chain hide show", function() {
372 jQuery('#show div').saveState().hide('fast').show('fast',jQuery.checkState);
374 test("Chain show hide", function() {
375 jQuery('#hide div').saveState().show('fast').hide('fast',jQuery.checkState);
378 test("Chain toggle in", function() {
379 jQuery('#togglein div').saveState().toggle('fast').toggle('fast',jQuery.checkState);
381 test("Chain toggle out", function() {
382 jQuery('#toggleout div').saveState().toggle('fast').toggle('fast',jQuery.checkState);
385 test("Chain slideDown slideUp", function() {
386 jQuery('#slidedown div').saveState().slideDown('fast').slideUp('fast',jQuery.checkState);
388 test("Chain slideUp slideDown", function() {
389 jQuery('#slideup div').saveState().slideUp('fast').slideDown('fast',jQuery.checkState);
392 test("Chain slideToggle in", function() {
393 jQuery('#slidetogglein div').saveState().slideToggle('fast').slideToggle('fast',jQuery.checkState);
395 test("Chain slideToggle out", function() {
396 jQuery('#slidetoggleout div').saveState().slideToggle('fast').slideToggle('fast',jQuery.checkState);
399 jQuery.makeTest = function( text ){
400 var elem = jQuery("<div></div>")
401 .attr("id", "test" + jQuery.makeTest.id++)
406 .appendTo("#fx-tests")
408 jQuery(this).next().toggle();
415 jQuery.makeTest.id = 1;