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("toggle()", function() {
17 ok( x.is(":visible") );
19 ok( x.is(":hidden") );
21 ok( x.is(":visible") );
25 Normal: function(elem){},
26 "CSS Hidden": function(elem){
27 $(this).addClass("hidden");
29 "JS Hidden": function(elem){
35 "CSS Auto": function(elem,prop){
36 $(elem).addClass("auto" + prop)
37 .text("This is a long string of text.");
40 "JS Auto": function(elem,prop){
41 $(elem).css(prop,"auto")
42 .text("This is a long string of text.");
45 "CSS 100": function(elem,prop){
46 $(elem).addClass("large" + prop);
49 "JS 100": function(elem,prop){
50 $(elem).css(prop,prop == "opacity" ? 1 : "100px");
51 return prop == "opacity" ? 1 : 100;
53 "CSS 50": function(elem,prop){
54 $(elem).addClass("med" + prop);
57 "JS 50": function(elem,prop){
58 $(elem).css(prop,prop == "opacity" ? 0.50 : "50px");
59 return prop == "opacity" ? 0.5 : 50;
61 "CSS 0": function(elem,prop){
62 $(elem).addClass("no" + prop);
65 "JS 0": function(elem,prop){
66 $(elem).css(prop,prop == "opacity" ? 0 : "0px");
72 "show": function(elem,prop){
73 $(elem).hide().addClass("wide"+prop);
76 "hide": function(elem,prop){
77 $(elem).addClass("wide"+prop);
80 "100": function(elem,prop){
81 $(elem).addClass("wide"+prop);
82 return prop == "opacity" ? 1 : 100;
84 "50": function(elem,prop){
85 return prop == "opacity" ? 0.50 : 50;
87 "0": function(elem,prop){
88 $(elem).addClass("noback");
93 function checkOverflowDisplay(){
94 var o = jQuery.css( this, "overflow" );
96 ok(o == "visible", "Overflow should be visible: " + o);
97 ok(jQuery.css( this, "display" ) == "inline", "Display shouldn't be tampered with.");
102 test("JS Overflow and Display", function() {
105 makeTest( "JS Overflow and Display" )
106 .addClass("widewidth")
107 .css({ overflow: "visible", display: "inline" })
108 .addClass("widewidth")
109 .text("Some sample text.")
110 .before("text before")
112 .animate({ opacity: 0.5 }, "slow", checkOverflowDisplay);
115 test("CSS Overflow and Display", function() {
118 makeTest( "CSS Overflow and Display" )
119 .addClass("overflow inline")
120 .addClass("widewidth")
121 .text("Some sample text.")
122 .before("text before")
124 .animate({ opacity: 0.5 }, "slow", checkOverflowDisplay);
127 jQuery.each( from, function(fn, f){
128 jQuery.each( to, function(tn, t){
129 test(fn + " to " + tn, function() {
130 var elem = makeTest( fn + " to " + tn );
132 var t_w = t( elem, "width" );
133 var f_w = f( elem, "width" );
134 var t_h = t( elem, "height" );
135 var f_h = f( elem, "height" );
136 var t_o = t( elem, "opacity" );
137 var f_o = f( elem, "opacity" );
141 if ( t_h == "show" ) num++;
142 if ( t_w == "show" ) num++;
143 if ( t_w == "hide"||t_w == "show" ) num++;
144 if ( t_h == "hide"||t_h == "show" ) num++;
145 if ( t_o == "hide"||t_o == "show" ) num++;
146 if ( t_w == "hide" ) num++;
147 if ( t_o.constructor == Number ) num += 2;
148 if ( t_w.constructor == Number ) num += 2;
149 if ( t_h.constructor == Number ) num +=2;
154 var anim = { width: t_w, height: t_h, opacity: t_o };
156 elem.animate(anim, 50, function(){
158 ok( this.style.display == "block", "Showing, display should block: " + this.style.display);
160 if ( t_w == "hide"||t_w == "show" )
161 ok(this.style.width.indexOf(f_w) == 0, "Width must be reset to " + f_w + ": " + this.style.width);
163 if ( t_h == "hide"||t_h == "show" )
164 ok(this.style.height.indexOf(f_h) == 0, "Height must be reset to " + f_h + ": " + this.style.height);
166 var cur_o = jQuery.attr(this.style, "opacity");
167 if ( cur_o !== "" ) cur_o = parseFloat( cur_o );
169 if ( t_o == "hide"||t_o == "show" )
170 ok(cur_o == f_o, "Opacity must be reset to " + f_o + ": " + cur_o);
173 ok(this.style.display == "none", "Hiding, display should be none: " + this.style.display);
175 if ( t_o.constructor == Number ) {
176 ok(cur_o == t_o, "Final opacity should be " + t_o + ": " + cur_o);
178 ok(jQuery.curCSS(this, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o);
181 if ( t_w.constructor == Number ) {
182 ok(this.style.width == t_w + "px", "Final width should be " + t_w + ": " + this.style.width);
184 var cur_w = jQuery.css(this,"width");
186 ok(this.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w);
189 if ( t_h.constructor == Number ) {
190 ok(this.style.height == t_h + "px", "Final height should be " + t_h + ": " + this.style.height);
192 var cur_h = jQuery.css(this,"height");
194 ok(this.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w);
197 if ( t_h == "show" ) {
198 var old_h = jQuery.curCSS(this, "height");
199 $(elem).append("<br>Some more text<br>and some more...");
200 ok(old_h != jQuery.css(this, "height" ), "Make sure height is auto.");
209 var check = ['opacity','height','width','display','overflow'];
211 jQuery.fn.saveState = function(){
212 expect(check.length);
214 return this.each(function(){
217 jQuery.each(check, function(i,c){
218 self.save[c] = jQuery.css(self,c);
223 function checkState(){
225 jQuery.each(this.save, function(c,v){
226 var cur = jQuery.css(self,c);
227 ok( v == cur, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")");
233 test("Chain fadeOut fadeIn", function() {
234 $('#fadein div').saveState().fadeOut('fast').fadeIn('fast',checkState);
236 test("Chain fadeIn fadeOut", function() {
237 $('#fadeout div').saveState().fadeIn('fast').fadeOut('fast',checkState);
240 test("Chain hide show", function() {
241 $('#show div').saveState().hide('fast').show('fast',checkState);
243 test("Chain show hide", function() {
244 $('#hide div').saveState().show('fast').hide('fast',checkState);
247 test("Chain toggle in", function() {
248 $('#togglein div').saveState().toggle('fast').toggle('fast',checkState);
250 test("Chain toggle out", function() {
251 $('#toggleout div').saveState().toggle('fast').toggle('fast',checkState);
254 test("Chain slideDown slideUp", function() {
255 $('#slidedown div').saveState().slideDown('fast').slideUp('fast',checkState);
257 test("Chain slideUp slideDown", function() {
258 $('#slideup div').saveState().slideUp('fast').slideDown('fast',checkState);
261 test("Chain slideToggle in", function() {
262 $('#slidetogglein div').saveState().slideToggle('fast').slideToggle('fast',checkState);
264 test("Chain slideToggle out", function() {
265 $('#slidetoggleout div').saveState().slideToggle('fast').slideToggle('fast',checkState);
268 function makeTest( text ){
269 var elem = $("<div></div>")
270 .attr("id", "test" + makeTest.id++)
275 .appendTo("#fx-tests")
277 $(this).next().toggle();