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 duration 0", function() {
42 var $elems = jQuery([{ a:0 },{ a:0 }]),
48 equals( jQuery.timers.length, 0, "Make sure no animation was running from another test" );
50 $elems.eq(0).animate( {a:1}, 0, count );
52 // Failed until [6115]
53 equals( jQuery.timers.length, 0, "Make sure synchronic animations are not left on jQuery.timers" );
55 equals( counter, 1, "One synchronic animations" );
57 $elems.animate( { a:2 }, 0, count );
59 equals( counter, 3, "Multiple synchronic animations" );
61 $elems.eq(0).animate( {a:3}, 0, count );
62 $elems.eq(1).animate( {a:3}, 20, function(){
64 // Failed until [6115]
65 equals( counter, 5, "One synchronic and one asynchronic" );
70 test("animate non-element", function(){
74 var obj = { test: 0 };
76 jQuery(obj).animate({test: 200}, 200, function(){
77 equals( obj.test, 200, "The custom property should be modified." );
82 test("stop()", function() {
86 var $foo = jQuery("#nothiddendiv");
88 $foo.hide().width(200).width();
90 $foo.animate({ width:'show' }, 1000);
91 setTimeout(function(){
92 var nw = $foo.width();
93 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
97 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
98 setTimeout(function(){
99 equals( nw, $foo.width(), "The animation didn't continue" );
105 test("stop() - several in queue", function() {
109 var $foo = jQuery("#nothiddendiv");
111 $foo.hide().width(200).width();
113 $foo.animate({ width:'show' }, 1000);
114 $foo.animate({ width:'hide' }, 1000);
115 $foo.animate({ width:'show' }, 1000);
116 setTimeout(function(){
117 equals( $foo.queue().length, 3, "All 3 still in the queue" );
118 var nw = $foo.width();
119 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
123 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
124 equals( $foo.queue().length, 2, "The next animation continued" );
130 test("stop(clearQueue)", function() {
134 var $foo = jQuery("#nothiddendiv");
136 $foo.hide().width(200).width();
138 $foo.animate({ width:'show' }, 1000);
139 $foo.animate({ width:'hide' }, 1000);
140 $foo.animate({ width:'show' }, 1000);
141 setTimeout(function(){
142 var nw = $foo.width();
143 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
147 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
149 equals( $foo.queue().length, 0, "The animation queue was cleared" );
150 setTimeout(function(){
151 equals( nw, $foo.width(), "The animation didn't continue" );
157 test("stop(clearQueue, gotoEnd)", function() {
161 var $foo = jQuery("#nothiddendiv");
163 $foo.hide().width(200).width();
165 $foo.animate({ width:'show' }, 1000);
166 $foo.animate({ width:'hide' }, 1000);
167 $foo.animate({ width:'show' }, 1000);
168 $foo.animate({ width:'hide' }, 1000);
169 setTimeout(function(){
170 var nw = $foo.width();
171 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
172 $foo.stop(false, true);
175 equals( nw, 200, "Stop() reset the animation" );
177 setTimeout(function(){
178 equals( $foo.queue().length, 3, "The next animation continued" );
185 test("toggle()", function() {
187 var x = jQuery("#foo");
188 ok( x.is(":visible"), "is visible" );
190 ok( x.is(":hidden"), "is hidden" );
192 ok( x.is(":visible"), "is visible again" );
195 ok( x.is(":visible"), "is visible" );
197 ok( x.is(":hidden"), "is hidden" );
199 ok( x.is(":visible"), "is visible again" );
202 jQuery.checkOverflowDisplay = function(){
203 var o = jQuery.css( this, "overflow" );
205 equals(o, "visible", "Overflow should be visible: " + o);
206 equals(jQuery.css( this, "display" ), "inline", "Display shouldn't be tampered with.");
211 test("JS Overflow and Display", function() {
214 jQuery.makeTest( "JS Overflow and Display" )
215 .addClass("widewidth")
216 .css({ overflow: "visible", display: "inline" })
217 .addClass("widewidth")
218 .text("Some sample text.")
219 .before("text before")
221 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
224 test("CSS Overflow and Display", function() {
227 jQuery.makeTest( "CSS Overflow and Display" )
228 .addClass("overflow inline")
229 .addClass("widewidth")
230 .text("Some sample text.")
231 .before("text before")
233 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
237 "CSS Auto": function(elem,prop){
238 jQuery(elem).addClass("auto" + prop)
239 .text("This is a long string of text.");
242 "JS Auto": function(elem,prop){
243 jQuery(elem).css(prop,"auto")
244 .text("This is a long string of text.");
247 "CSS 100": function(elem,prop){
248 jQuery(elem).addClass("large" + prop);
251 "JS 100": function(elem,prop){
252 jQuery(elem).css(prop,prop == "opacity" ? 1 : "100px");
253 return prop == "opacity" ? 1 : 100;
255 "CSS 50": function(elem,prop){
256 jQuery(elem).addClass("med" + prop);
259 "JS 50": function(elem,prop){
260 jQuery(elem).css(prop,prop == "opacity" ? 0.50 : "50px");
261 return prop == "opacity" ? 0.5 : 50;
263 "CSS 0": function(elem,prop){
264 jQuery(elem).addClass("no" + prop);
267 "JS 0": function(elem,prop){
268 jQuery(elem).css(prop,prop == "opacity" ? 0 : "0px");
273 "show": function(elem,prop){
274 jQuery(elem).hide().addClass("wide"+prop);
277 "hide": function(elem,prop){
278 jQuery(elem).addClass("wide"+prop);
281 "100": function(elem,prop){
282 jQuery(elem).addClass("wide"+prop);
283 return prop == "opacity" ? 1 : 100;
285 "50": function(elem,prop){
286 return prop == "opacity" ? 0.50 : 50;
288 "0": function(elem,prop){
289 jQuery(elem).addClass("noback");
293 test(fn + " to " + tn, function() {
294 var elem = jQuery.makeTest( fn + " to " + tn );
296 var t_w = t( elem, "width" );
297 var f_w = f( elem, "width" );
298 var t_h = t( elem, "height" );
299 var f_h = f( elem, "height" );
300 var t_o = t( elem, "opacity" );
301 var f_o = f( elem, "opacity" );
305 if ( t_h == "show" ) num++;
306 if ( t_w == "show" ) num++;
307 if ( t_w == "hide"||t_w == "show" ) num++;
308 if ( t_h == "hide"||t_h == "show" ) num++;
309 if ( t_o == "hide"||t_o == "show" ) num++;
310 if ( t_w == "hide" ) num++;
311 if ( t_o.constructor == Number ) num += 2;
312 if ( t_w.constructor == Number ) num += 2;
313 if ( t_h.constructor == Number ) num +=2;
318 var anim = { width: t_w, height: t_h, opacity: t_o };
320 elem.animate(anim, 50, function(){
322 equals( this.style.display, "block", "Showing, display should block: " + this.style.display);
324 if ( t_w == "hide"||t_w == "show" )
325 equals(this.style.width.indexOf(f_w), 0, "Width must be reset to " + f_w + ": " + this.style.width);
327 if ( t_h == "hide"||t_h == "show" )
328 equals(this.style.height.indexOf(f_h), 0, "Height must be reset to " + f_h + ": " + this.style.height);
330 var cur_o = jQuery.attr(this.style, "opacity");
331 if ( cur_o !== "" ) cur_o = parseFloat( cur_o );
333 if ( t_o == "hide"||t_o == "show" )
334 equals(cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o);
337 equals(this.style.display, "none", "Hiding, display should be none: " + this.style.display);
339 if ( t_o.constructor == Number ) {
340 equals(cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o);
342 ok(jQuery.curCSS(this, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o);
345 if ( t_w.constructor == Number ) {
346 equals(this.style.width, t_w + "px", "Final width should be " + t_w + ": " + this.style.width);
348 var cur_w = jQuery.css(this,"width");
350 ok(this.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w);
353 if ( t_h.constructor == Number ) {
354 equals(this.style.height, t_h + "px", "Final height should be " + t_h + ": " + this.style.height);
356 var cur_h = jQuery.css(this,"height");
358 ok(this.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w);
361 if ( t_h == "show" ) {
362 var old_h = jQuery.curCSS(this, "height");
363 jQuery(elem).append("<br/>Some more text<br/>and some more...");
364 ok(old_h != jQuery.css(this, "height" ), "Make sure height is auto.");
373 jQuery.fn.saveState = function(){
374 var check = ['opacity','height','width','display','overflow'];
375 expect(check.length);
378 return this.each(function(){
381 jQuery.each(check, function(i,c){
382 self.save[c] = jQuery.css(self,c);
387 jQuery.checkState = function(){
389 jQuery.each(this.save, function(c,v){
390 var cur = jQuery.css(self,c);
391 equals( v, cur, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")");
397 test("Chain fadeOut fadeIn", function() {
398 jQuery('#fadein div').saveState().fadeOut('fast').fadeIn('fast',jQuery.checkState);
400 test("Chain fadeIn fadeOut", function() {
401 jQuery('#fadeout div').saveState().fadeIn('fast').fadeOut('fast',jQuery.checkState);
404 test("Chain hide show", function() {
405 jQuery('#show div').saveState().hide('fast').show('fast',jQuery.checkState);
407 test("Chain show hide", function() {
408 jQuery('#hide div').saveState().show('fast').hide('fast',jQuery.checkState);
411 test("Chain toggle in", function() {
412 jQuery('#togglein div').saveState().toggle('fast').toggle('fast',jQuery.checkState);
414 test("Chain toggle out", function() {
415 jQuery('#toggleout div').saveState().toggle('fast').toggle('fast',jQuery.checkState);
418 test("Chain slideDown slideUp", function() {
419 jQuery('#slidedown div').saveState().slideDown('fast').slideUp('fast',jQuery.checkState);
421 test("Chain slideUp slideDown", function() {
422 jQuery('#slideup div').saveState().slideUp('fast').slideDown('fast',jQuery.checkState);
425 test("Chain slideToggle in", function() {
426 jQuery('#slidetogglein div').saveState().slideToggle('fast').slideToggle('fast',jQuery.checkState);
428 test("Chain slideToggle out", function() {
429 jQuery('#slidetoggleout div').saveState().slideToggle('fast').slideToggle('fast',jQuery.checkState);
432 jQuery.makeTest = function( text ){
433 var elem = jQuery("<div></div>")
434 .attr("id", "test" + jQuery.makeTest.id++)
439 .appendTo("#fx-tests")
441 jQuery(this).next().toggle();
448 jQuery.makeTest.id = 1;