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("stop()", function() {
19 var foo = $("#foo")[0];
20 var h = foo.style.height;
22 $("#foo").slideUp(1000);
23 setTimeout(function(){
24 var nh = foo.style.height;
25 ok( nh != h, "An animation occurred " + nh + " " + h );
28 nh = foo.style.height;
29 ok( nh != h, "Stop didn't reset the animation " + nh + " " + h );
30 setTimeout(function(){
31 equals( nh, foo.style.height, "The animation didn't continue" );
37 test("toggle()", function() {
40 ok( x.is(":visible") );
42 ok( x.is(":hidden") );
44 ok( x.is(":visible") );
48 Normal: function(elem){},
49 "CSS Hidden": function(elem){
50 $(this).addClass("hidden");
52 "JS Hidden": function(elem){
58 "CSS Auto": function(elem,prop){
59 $(elem).addClass("auto" + prop)
60 .text("This is a long string of text.");
63 "JS Auto": function(elem,prop){
64 $(elem).css(prop,"auto")
65 .text("This is a long string of text.");
68 "CSS 100": function(elem,prop){
69 $(elem).addClass("large" + prop);
72 "JS 100": function(elem,prop){
73 $(elem).css(prop,prop == "opacity" ? 1 : "100px");
74 return prop == "opacity" ? 1 : 100;
76 "CSS 50": function(elem,prop){
77 $(elem).addClass("med" + prop);
80 "JS 50": function(elem,prop){
81 $(elem).css(prop,prop == "opacity" ? 0.50 : "50px");
82 return prop == "opacity" ? 0.5 : 50;
84 "CSS 0": function(elem,prop){
85 $(elem).addClass("no" + prop);
88 "JS 0": function(elem,prop){
89 $(elem).css(prop,prop == "opacity" ? 0 : "0px");
95 "show": function(elem,prop){
96 $(elem).hide().addClass("wide"+prop);
99 "hide": function(elem,prop){
100 $(elem).addClass("wide"+prop);
103 "100": function(elem,prop){
104 $(elem).addClass("wide"+prop);
105 return prop == "opacity" ? 1 : 100;
107 "50": function(elem,prop){
108 return prop == "opacity" ? 0.50 : 50;
110 "0": function(elem,prop){
111 $(elem).addClass("noback");
116 function checkOverflowDisplay(){
117 var o = jQuery.css( this, "overflow" );
119 ok(o == "visible", "Overflow should be visible: " + o);
120 ok(jQuery.css( this, "display" ) == "inline", "Display shouldn't be tampered with.");
125 test("JS Overflow and Display", function() {
128 makeTest( "JS Overflow and Display" )
129 .addClass("widewidth")
130 .css({ overflow: "visible", display: "inline" })
131 .addClass("widewidth")
132 .text("Some sample text.")
133 .before("text before")
135 .animate({ opacity: 0.5 }, "slow", checkOverflowDisplay);
138 test("CSS Overflow and Display", function() {
141 makeTest( "CSS Overflow and Display" )
142 .addClass("overflow inline")
143 .addClass("widewidth")
144 .text("Some sample text.")
145 .before("text before")
147 .animate({ opacity: 0.5 }, "slow", checkOverflowDisplay);
150 jQuery.each( from, function(fn, f){
151 jQuery.each( to, function(tn, t){
152 test(fn + " to " + tn, function() {
153 var elem = makeTest( fn + " to " + tn );
155 var t_w = t( elem, "width" );
156 var f_w = f( elem, "width" );
157 var t_h = t( elem, "height" );
158 var f_h = f( elem, "height" );
159 var t_o = t( elem, "opacity" );
160 var f_o = f( elem, "opacity" );
164 if ( t_h == "show" ) num++;
165 if ( t_w == "show" ) num++;
166 if ( t_w == "hide"||t_w == "show" ) num++;
167 if ( t_h == "hide"||t_h == "show" ) num++;
168 if ( t_o == "hide"||t_o == "show" ) num++;
169 if ( t_w == "hide" ) num++;
170 if ( t_o.constructor == Number ) num += 2;
171 if ( t_w.constructor == Number ) num += 2;
172 if ( t_h.constructor == Number ) num +=2;
177 var anim = { width: t_w, height: t_h, opacity: t_o };
179 elem.animate(anim, 50, function(){
181 ok( this.style.display == "block", "Showing, display should block: " + this.style.display);
183 if ( t_w == "hide"||t_w == "show" )
184 ok(this.style.width.indexOf(f_w) == 0, "Width must be reset to " + f_w + ": " + this.style.width);
186 if ( t_h == "hide"||t_h == "show" )
187 ok(this.style.height.indexOf(f_h) == 0, "Height must be reset to " + f_h + ": " + this.style.height);
189 var cur_o = jQuery.attr(this.style, "opacity");
190 if ( cur_o !== "" ) cur_o = parseFloat( cur_o );
192 if ( t_o == "hide"||t_o == "show" )
193 ok(cur_o == f_o, "Opacity must be reset to " + f_o + ": " + cur_o);
196 ok(this.style.display == "none", "Hiding, display should be none: " + this.style.display);
198 if ( t_o.constructor == Number ) {
199 ok(cur_o == t_o, "Final opacity should be " + t_o + ": " + cur_o);
201 ok(jQuery.curCSS(this, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o);
204 if ( t_w.constructor == Number ) {
205 ok(this.style.width == t_w + "px", "Final width should be " + t_w + ": " + this.style.width);
207 var cur_w = jQuery.css(this,"width");
209 ok(this.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w);
212 if ( t_h.constructor == Number ) {
213 ok(this.style.height == t_h + "px", "Final height should be " + t_h + ": " + this.style.height);
215 var cur_h = jQuery.css(this,"height");
217 ok(this.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w);
220 if ( t_h == "show" ) {
221 var old_h = jQuery.curCSS(this, "height");
222 $(elem).append("<br/>Some more text<br/>and some more...");
223 ok(old_h != jQuery.css(this, "height" ), "Make sure height is auto.");
232 var check = ['opacity','height','width','display','overflow'];
234 jQuery.fn.saveState = function(){
235 expect(check.length);
237 return this.each(function(){
240 jQuery.each(check, function(i,c){
241 self.save[c] = jQuery.css(self,c);
246 function checkState(){
248 jQuery.each(this.save, function(c,v){
249 var cur = jQuery.css(self,c);
250 ok( v == cur, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")");
256 test("Chain fadeOut fadeIn", function() {
257 $('#fadein div').saveState().fadeOut('fast').fadeIn('fast',checkState);
259 test("Chain fadeIn fadeOut", function() {
260 $('#fadeout div').saveState().fadeIn('fast').fadeOut('fast',checkState);
263 test("Chain hide show", function() {
264 $('#show div').saveState().hide('fast').show('fast',checkState);
266 test("Chain show hide", function() {
267 $('#hide div').saveState().show('fast').hide('fast',checkState);
270 test("Chain toggle in", function() {
271 $('#togglein div').saveState().toggle('fast').toggle('fast',checkState);
273 test("Chain toggle out", function() {
274 $('#toggleout div').saveState().toggle('fast').toggle('fast',checkState);
277 test("Chain slideDown slideUp", function() {
278 $('#slidedown div').saveState().slideDown('fast').slideUp('fast',checkState);
280 test("Chain slideUp slideDown", function() {
281 $('#slideup div').saveState().slideUp('fast').slideDown('fast',checkState);
284 test("Chain slideToggle in", function() {
285 $('#slidetogglein div').saveState().slideToggle('fast').slideToggle('fast',checkState);
287 test("Chain slideToggle out", function() {
288 $('#slidetoggleout div').saveState().slideToggle('fast').slideToggle('fast',checkState);
291 function makeTest( text ){
292 var elem = $("<div></div>")
293 .attr("id", "test" + makeTest.id++)
298 .appendTo("#fx-tests")
300 $(this).next().toggle();