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