We're not adding new selector features in until a new full release. Please discuss...
[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 </style>
100 <script>
101 var visible = {
102         Normal: function(elem){},
103         "CSS Hidden": function(elem){
104                 $(this).addClass("hidden");
105         },
106         "JS Hidden": function(elem){
107                 $(this).hide();
108         }
109 };
110
111 var from = {
112         "CSS Auto": function(elem,prop){
113                 $(elem).addClass("auto" + prop)
114                         .text("This is a long string of text.");
115                 return "";
116         },
117         "JS Auto": function(elem,prop){
118                 $(elem).css(prop,"auto")
119                         .text("This is a long string of text.");
120                 return "";
121         },
122         "CSS 100": function(elem,prop){
123                 $(elem).addClass("large" + prop);
124                 return "";
125         },
126         "JS 100": function(elem,prop){
127                 $(elem).css(prop,prop == "opacity" ? 1 : "100px");
128                 return prop == "opacity" ? 1 : 100;
129         },
130         "CSS 50": function(elem,prop){
131                 $(elem).addClass("med" + prop);
132                 return "";
133         },
134         "JS 50": function(elem,prop){
135                 $(elem).css(prop,prop == "opacity" ? 0.50 : "50px");
136                 return prop == "opacity" ? 0.5 : 50;
137         },
138         "CSS 0": function(elem,prop){
139                 $(elem).addClass("no" + prop);
140                 return "";
141         },
142         "JS 0": function(elem,prop){
143                 $(elem).css(prop,prop == "opacity" ? 0 : "0px");
144                 return 0;
145         }
146 };
147
148 var to = {
149         /*"Auto": function(elem,prop){
150                 $(elem).addClass("wide"+prop);
151                 return "auto";
152         },*/
153         /*"toggle (show)": function(elem,prop){
154                 $(elem).hide().addClass("wide"+prop);
155                 return "show";
156         },*/
157         "show": function(elem,prop){
158                 $(elem).hide().addClass("wide"+prop);
159                 return "show";
160         },
161         "hide": function(elem,prop){
162                 $(elem).addClass("wide"+prop);
163                 return "hide";
164         },
165         "100": function(elem,prop){
166                 $(elem).addClass("wide"+prop);
167                 return prop == "opacity" ? 1 : 100;
168         },
169         "50": function(elem,prop){
170                 return prop == "opacity" ? 0.50 : 50;
171         },
172         "0": function(elem,prop){
173                 $(elem).addClass("noback");
174                 return 0;
175         }
176 };
177
178 /*var oldAttr = jQuery.attr;
179
180 jQuery.attr = function( elem, name, value ){
181         if ( arguments.length == 3 ) {
182                 var prev = elem.previousSibling;
183                 if ( prev && prev.nodeName == "UL" ) {
184                         $(prev).append( name + ": " + value );
185                 }
186         }
187
188         return oldAttr.apply( jQuery, arguments );
189 };*/
190
191 $(document).ready(function(){
192         makeTest( "JS Overflow and Display" )
193                 .addClass("widewidth")
194                 .css({ overflow: "visible", display: "inline" })
195                 .add( makeTest( "CSS Overflow and Display" ).addClass("overflow inline") )
196                 .addClass("widewidth")
197                 .text("Some sample text.")
198                 .before("text before")
199                 .after("text after")
200                 .animate({ opacity: 0.5 }, "slow", function(){
201                         var o = jQuery.css( this, "overflow" );
202                         if ( o != "visible" )
203                                 return msg(this, "Overflow should be visible: " + o);
204
205                         if ( jQuery.css( this, "display" ) != "inline" )
206                                 return msg(this, "Display has been tampered with.");
207
208                         pass( this );
209                 });
210
211         jQuery.each( from, function(fn, f){
212                 jQuery.each( to, function(tn, t){
213                         var elem = makeTest( fn + " to " + tn );
214
215                         var t_w = t( elem, "width" );
216                         var f_w = f( elem, "width" );
217                         var t_h = t( elem, "height" );
218                         var f_h = f( elem, "height" );
219                         var t_o = t( elem, "opacity" );
220                         var f_o = f( elem, "opacity" );
221
222                         var anim = { width: t_w, height: t_h, opacity: t_o };
223
224                         elem.animate(anim, "slow", function(){
225                                 if ( t_w == "show" && this.style.display != "block" )
226                                         return msg(this, "Showing, display not block: " + this.style.display);
227
228                                 if ( (t_w == "hide"||t_w == "show") && this.style.width.indexOf(f_w) != 0 )
229                                         return msg(this, "Width not reset to " + f_w + ": " + this.style.width);
230
231                                 if ( (t_h == "hide"||t_h == "show") && this.style.height.indexOf(f_h) != 0 )
232                                         return msg(this, "Height not reset to " + f_h + ": " + this.style.height);
233
234                                 var cur_o = jQuery.attr(this.style, "opacity");
235                                 if ( cur_o !== "" ) cur_o = parseFloat( cur_o );
236
237                                 if ( (t_o == "hide"||t_o == "show") && cur_o != f_o ) {
238                                         return msg(this, "Opacity not reset to " + f_o + ": " + cur_o);
239                                 }
240
241                                 if ( t_w == "hide" && this.style.display != "none" )
242                                         return msg(this, "Hiding, display not none: " + this.style.display);
243
244                                 if ( t_o.constructor == Number && cur_o != t_o )
245                                         return msg(this, "Final opacity is not " + t_o + ": " + cur_o);
246
247                                 if ( t_w.constructor == Number && this.style.width != t_w + "px" )
248                                         return msg(this, "Final width is not " + t_w + ": " + this.style.width);
249
250                                 if ( t_h.constructor == Number && this.style.height != t_h + "px" )
251                                         return msg(this, "Final height is not " + t_h + ": " + this.style.height);
252
253                                 var cur_w = jQuery.css(this,"width");
254                                 if ( t_w.constructor == Number && this.style.width == "" && cur_w != t_w )
255                                         return msg(this, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w);
256
257                                 var cur_h = jQuery.css(this,"height");
258                                 if ( t_h.constructor == Number && this.style.height == "" && cur_h != t_h )
259                                         return msg(this, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w);
260
261                                 if ( t_o.constructor == Number && jQuery.curCSS(this, "opacity") == "" && cur_o != t_o )
262                                         return msg(this, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o);
263
264                                 if ( t_h == "show" ) {
265                                         var old_h = jQuery.curCSS(this, "height");
266                                         $(elem).append("<br>Some more text<br>and some more...");
267                                                 if ( old_h == jQuery.css(this, "height" ) )
268                                                         return msg(this, "Height is not truly auto.");
269                                 }
270
271                                 pass( this );
272                         });
273                 });
274         });
275 });
276
277 function pass( elem ) {
278         $(elem).prev().addClass("pass");
279 }
280
281 function makeTest( text ){
282         var elem = $("<div></div>")
283                 .attr("id", "test" + makeTest.id++)
284                 .addClass("box");
285
286         $("<h4></h4>")
287                 .text( text )
288                 .appendTo("#tests")
289                 .click(function(){
290                         $(this).next().toggle();
291                 })
292                 .after( elem );
293
294         return elem;
295 }
296
297 makeTest.id = 1;
298
299 function msg(elem,txt){
300         $(elem).prev().append( "<tt> " + txt + "</tt>" );
301 }
302 </script>
303 </head>
304 <body>
305 <div id="tests"></div>
306 </body>
307 </html>