Added an initial version of the new animation test suite. (You should never see red...
[jquery.git] / build / test / fx.html
1 <html>
2 <head>
3 <title>Animation Test Suite</title>
4 <script src="../dist/jquery.js"></script>
5 <style>
6 div#tests h4 {
7         background: red;
8 }
9
10 div#tests h4.pass {
11         background: green;
12 }
13
14 div#tests div.box {
15         background: red url(cow.jpg) no-repeat;
16         overflow: hidden;
17         border: 2px solid #000;
18 }
19
20 div#tests div.overflow {
21         overflow: visible;
22 }
23
24 div.inline {
25         display: inline;
26 }
27
28 div.autoheight {
29         height: auto;
30 }
31
32 div.autowidth {
33         width: auto;
34 }
35
36 div.autoopacity {
37         opacity: auto;
38 }
39
40 div.largewidth {
41         width: 100px;
42 }
43
44 div.largeheight {
45         height: 100px;
46 }
47
48 div.largeopacity {
49         filter: progid:DXImageTransform.Microsoft.Alpha(opacity=100);
50 }
51
52 div.medwidth {
53         width: 50px;
54 }
55
56 div.medheight {
57         height: 50px;
58 }
59
60 div.medopacity {
61         opacity: 0.5;
62         filter: progid:DXImageTransform.Microsoft.Alpha(opacity=50);
63 }
64
65 div.nowidth {
66         width: 0px;
67 }
68
69 div.noheight {
70         height: 0px;
71 }
72
73 div.noopacity {
74         opacity: 0;
75         filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0);
76 }
77
78 div.hidden {
79         display: none;
80 }
81
82 div#tests div.widewidth {
83         background-repeat: repeat-x;
84 }
85
86 div#tests div.wideheight {
87         background-repeat: repeat-y;
88 }
89
90 div#tests div.widewidth.wideheight {
91         background-repeat: repeat;
92 }
93
94 div#tests div.noback {
95         background-image: none;
96 }
97 </style>
98 <script>
99 var visible = {
100         Normal: function(elem){},
101         "CSS Hidden": function(elem){
102                 $(this).addClass("hidden");
103         },
104         "JS Hidden": function(elem){
105                 $(this).hide();
106         }
107 };
108
109 var from = {
110         "CSS Auto": function(elem,prop){
111                 $(elem).addClass("auto" + prop)
112                         .text("This is a long string of text.");
113                 return "";
114         },
115         "JS Auto": function(elem,prop){
116                 $(elem).css(prop,"auto")
117                         .text("This is a long string of text.");
118                 return "";
119         },
120         "CSS 100": function(elem,prop){
121                 $(elem).addClass("large" + prop);
122                 return "";
123         },
124         "JS 100": function(elem,prop){
125                 $(elem).css(prop,prop == "opacity" ? 1 : "100px");
126                 return prop == "opacity" ? 1 : 100;
127         },
128         "CSS 50": function(elem,prop){
129                 $(elem).addClass("med" + prop);
130                 return "";
131         },
132         "JS 50": function(elem,prop){
133                 $(elem).css(prop,prop == "opacity" ? 0.50 : "50px");
134                 return prop == "opacity" ? 0.5 : 50;
135         },
136         "CSS 0": function(elem,prop){
137                 $(elem).addClass("no" + prop);
138                 return "";
139         },
140         "JS 0": function(elem,prop){
141                 $(elem).css(prop,prop == "opacity" ? 0 : "0px");
142                 return 0;
143         }
144 };
145
146 var to = {
147         /*"Auto": function(elem,prop){
148                 $(elem).addClass("wide"+prop);
149                 return "auto";
150         },*/
151         /*"toggle (show)": function(elem,prop){
152                 $(elem).hide().addClass("wide"+prop);
153                 return "show";
154         },*/
155         "show": function(elem,prop){
156                 $(elem).hide().addClass("wide"+prop);
157                 return "show";
158         },
159         "hide": function(elem,prop){
160                 $(elem).addClass("wide"+prop);
161                 return "hide";
162         },
163         "100": function(elem,prop){
164                 $(elem).addClass("wide"+prop);
165                 return prop == "opacity" ? 1 : 100;
166         },
167         "50": function(elem,prop){
168                 return prop == "opacity" ? 0.50 : 50;
169         },
170         "0": function(elem,prop){
171                 $(elem).addClass("noback");
172                 return 0;
173         }
174 };
175
176 /*var oldAttr = jQuery.attr;
177
178 jQuery.attr = function( elem, name, value ){
179         if ( arguments.length == 3 ) {
180                 var prev = elem.previousSibling;
181                 if ( prev && prev.nodeName == "UL" ) {
182                         $(prev).append( name + ": " + value );
183                 }
184         }
185
186         return oldAttr.apply( jQuery, arguments );
187 };*/
188
189 $(document).ready(function(){
190         makeTest( "JS Overflow and Display" )
191                 .addClass("widewidth")
192                 .css({ overflow: "visible", display: "inline" })
193                 .add( makeTest( "CSS Overflow and Display" ).addClass("overflow inline") )
194                 .addClass("widewidth")
195                 .text("Some sample text.")
196                 .before("text before")
197                 .after("text after")
198                 .animate({ opacity: 0.5 }, "slow", function(){
199                         var o = jQuery.css( this, "overflow" );
200                         if ( o != "visible" )
201                                 return msg(this, "Overflow should be visible: " + o);
202
203                         if ( jQuery.css( this, "display" ) != "inline" )
204                                 return msg(this, "Display has been tampered with.");
205
206                         pass( this );
207                 });
208
209         jQuery.each( from, function(fn, f){
210                 jQuery.each( to, function(tn, t){
211                         var elem = makeTest( fn + " to " + tn );
212
213                         var t_w = t( elem, "width" );
214                         var f_w = f( elem, "width" );
215                         var t_h = t( elem, "height" );
216                         var f_h = f( elem, "height" );
217                         var t_o = t( elem, "opacity" );
218                         var f_o = f( elem, "opacity" );
219
220                         var anim = { width: t_w, height: t_h, opacity: t_o };
221
222                         elem.animate(anim, "slow", function(){
223                                 if ( t_w == "show" && this.style.display != "block" )
224                                         return msg(this, "Showing, display not block: " + this.style.display);
225
226                                 if ( (t_w == "hide"||t_w == "show") && this.style.width.indexOf(f_w) != 0 )
227                                         return msg(this, "Width not reset to " + f_w + ": " + this.style.width);
228
229                                 if ( (t_h == "hide"||t_h == "show") && this.style.height.indexOf(f_h) != 0 )
230                                         return msg(this, "Height not reset to " + f_h + ": " + this.style.height);
231
232                                 var cur_o = jQuery.attr(this.style, "opacity");
233                                 if ( cur_o !== "" ) cur_o = parseFloat( cur_o );
234
235                                 if ( (t_o == "hide"||t_o == "show") && cur_o != f_o )
236                                         return msg(this, "Opacity not reset to " + f_o + ": " + cur_o);
237
238                                 if ( t_w == "hide" && this.style.display != "none" )
239                                         return msg(this, "Hiding, display not none: " + this.style.display);
240
241                                 if ( t_o.constructor == Number && cur_o != t_o )
242                                         return msg(this, "Final opacity is not " + t_o + ": " + cur_o);
243
244                                 if ( t_w.constructor == Number && this.style.width != t_w + "px" )
245                                         return msg(this, "Final width is not " + t_w + ": " + this.style.width);
246
247                                 if ( t_h.constructor == Number && this.style.height != t_h + "px" )
248                                         return msg(this, "Final height is not " + t_h + ": " + this.style.height);
249
250                                 var cur_w = jQuery.css(this,"width");
251                                 if ( t_w.constructor == Number && this.style.width == "" && cur_w != t_w )
252                                         return msg(this, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w);
253
254                                 var cur_h = jQuery.css(this,"height");
255                                 if ( t_h.constructor == Number && this.style.height == "" && cur_h != t_h )
256                                         return msg(this, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w);
257
258                                 if ( t_o.constructor == Number && jQuery.curCSS(this, "opacity") == "" && cur_o != t_o )
259                                         return msg(this, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o);
260
261                                 if ( t_h == "show" ) {
262                                         var old_h = jQuery.curCSS(this, "height");
263                                         $(elem).append("<br>Some more text<br>and some more...");
264                                                 if ( old_h == jQuery.css(this, "height" ) )
265                                                         return msg(this, "Height is not truly auto.");
266                                 }
267
268                                 pass( this );
269                         });
270                 });
271         });
272 });
273
274 function pass( elem ) {
275         $(elem).prev().addClass("pass");
276 }
277
278 function makeTest( text ){
279         var elem = $("<div></div>")
280                 .attr("id", "test" + makeTest.id++)
281                 .addClass("box");
282
283         $("<h4></h4>")
284                 .text( text )
285                 .appendTo("#tests")
286                 .click(function(){
287                         $(this).next().toggle();
288                 })
289                 .after( elem );
290
291         return elem;
292 }
293
294 makeTest.id = 1;
295
296 function msg(elem,txt){
297         $(elem).prev().append( "<tt> " + txt + "</tt>" );
298 }
299 </script>
300 </head>
301 <body>
302 <div id="tests"></div>
303 </body>
304 </html>