Upgrade to ExtJS 3.0.0 - Released 07/06/2009
[extjs.git] / docs / source / Fx.html
1 <html>\r
2 <head>\r
3   <title>The source code</title>\r
4     <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />\r
5     <script type="text/javascript" src="../resources/prettify/prettify.js"></script>\r
6 </head>\r
7 <body  onload="prettyPrint();">\r
8     <pre class="prettyprint lang-js">(function(){\r
9     // contants\r
10     var NULL = null,\r
11         UNDEFINED = undefined,\r
12         TRUE = true,\r
13         FALSE = false,\r
14         SETX = "setX",\r
15         SETY = "setY",\r
16         SETXY = "setXY",\r
17         LEFT = "left",\r
18         BOTTOM = "bottom",\r
19         TOP = "top",\r
20         RIGHT = "right",\r
21         HEIGHT = "height",\r
22         WIDTH = "width",\r
23         POINTS = "points",\r
24         HIDDEN = "hidden",\r
25         ABSOLUTE = "absolute",\r
26         VISIBLE = "visible",\r
27         MOTION = "motion",\r
28         POSITION = "position",\r
29         EASEOUT = "easeOut",\r
30         /*\r
31          * Use a light flyweight here since we are using so many callbacks and are always assured a DOM element\r
32          */\r
33         flyEl = new Ext.Element.Flyweight(),\r
34         queues = {},\r
35         getObject = function(o){\r
36             return o || {};\r
37         },\r
38         fly = function(dom){\r
39             flyEl.dom = dom;\r
40             flyEl.id = Ext.id(dom);\r
41             return flyEl;\r
42         },\r
43         /*\r
44          * Queueing now stored outside of the element due to closure issues\r
45          */\r
46         getQueue = function(id){\r
47             if(!queues[id]){\r
48                 queues[id] = [];\r
49             }\r
50             return queues[id];\r
51         },\r
52         setQueue = function(id, value){\r
53             queues[id] = value;\r
54         };\r
55         \r
56 //Notifies Element that fx methods are available\r
57 Ext.enableFx = TRUE;\r
58 \r
59 <div id="cls-Ext.Fx"></div>/**\r
60  * @class Ext.Fx\r
61  * <p>A class to provide basic animation and visual effects support.  <b>Note:</b> This class is automatically applied\r
62  * to the {@link Ext.Element} interface when included, so all effects calls should be performed via {@link Ext.Element}.\r
63  * Conversely, since the effects are not actually defined in {@link Ext.Element}, Ext.Fx <b>must</b> be\r
64  * {@link Ext#enableFx included} in order for the Element effects to work.</p><br/>\r
65  * \r
66  * <p><b><u>Method Chaining</u></b></p>\r
67  * <p>It is important to note that although the Fx methods and many non-Fx Element methods support "method chaining" in that\r
68  * they return the Element object itself as the method return value, it is not always possible to mix the two in a single\r
69  * method chain.  The Fx methods use an internal effects queue so that each effect can be properly timed and sequenced.\r
70  * Non-Fx methods, on the other hand, have no such internal queueing and will always execute immediately.  For this reason,\r
71  * while it may be possible to mix certain Fx and non-Fx method calls in a single chain, it may not always provide the\r
72  * expected results and should be done with care.  Also see <tt>{@link #callback}</tt>.</p><br/>\r
73  *\r
74  * <p><b><u>Anchor Options for Motion Effects</u></b></p>\r
75  * <p>Motion effects support 8-way anchoring, meaning that you can choose one of 8 different anchor points on the Element\r
76  * that will serve as either the start or end point of the animation.  Following are all of the supported anchor positions:</p>\r
77 <pre>\r
78 Value  Description\r
79 -----  -----------------------------\r
80 tl     The top left corner\r
81 t      The center of the top edge\r
82 tr     The top right corner\r
83 l      The center of the left edge\r
84 r      The center of the right edge\r
85 bl     The bottom left corner\r
86 b      The center of the bottom edge\r
87 br     The bottom right corner\r
88 </pre>\r
89  * <b>Note</b>: some Fx methods accept specific custom config parameters.  The options shown in the Config Options\r
90  * section below are common options that can be passed to any Fx method unless otherwise noted.</b>\r
91  * \r
92  * @cfg {Function} callback A function called when the effect is finished.  Note that effects are queued internally by the\r
93  * Fx class, so a callback is not required to specify another effect -- effects can simply be chained together\r
94  * and called in sequence (see note for <b><u>Method Chaining</u></b> above), for example:<pre><code>\r
95  * el.slideIn().highlight();\r
96  * </code></pre>\r
97  * The callback is intended for any additional code that should run once a particular effect has completed. The Element\r
98  * being operated upon is passed as the first parameter.\r
99  * \r
100  * @cfg {Object} scope The scope of the <tt>{@link #callback}</tt> function\r
101  * \r
102  * @cfg {String} easing A valid Ext.lib.Easing value for the effect:</p><div class="mdetail-params"><ul>\r
103  * <li><b><tt>backBoth</tt></b></li>\r
104  * <li><b><tt>backIn</tt></b></li>\r
105  * <li><b><tt>backOut</tt></b></li>\r
106  * <li><b><tt>bounceBoth</tt></b></li>\r
107  * <li><b><tt>bounceIn</tt></b></li>\r
108  * <li><b><tt>bounceOut</tt></b></li>\r
109  * <li><b><tt>easeBoth</tt></b></li>\r
110  * <li><b><tt>easeBothStrong</tt></b></li>\r
111  * <li><b><tt>easeIn</tt></b></li>\r
112  * <li><b><tt>easeInStrong</tt></b></li>\r
113  * <li><b><tt>easeNone</tt></b></li>\r
114  * <li><b><tt>easeOut</tt></b></li>\r
115  * <li><b><tt>easeOutStrong</tt></b></li>\r
116  * <li><b><tt>elasticBoth</tt></b></li>\r
117  * <li><b><tt>elasticIn</tt></b></li>\r
118  * <li><b><tt>elasticOut</tt></b></li>\r
119  * </ul></div>\r
120  *\r
121  * @cfg {String} afterCls A css class to apply after the effect\r
122  * @cfg {Number} duration The length of time (in seconds) that the effect should last\r
123  * \r
124  * @cfg {Number} endOpacity Only applicable for {@link #fadeIn} or {@link #fadeOut}, a number between\r
125  * <tt>0</tt> and <tt>1</tt> inclusive to configure the ending opacity value.\r
126  *  \r
127  * @cfg {Boolean} remove Whether the Element should be removed from the DOM and destroyed after the effect finishes\r
128  * @cfg {Boolean} useDisplay Whether to use the <i>display</i> CSS property instead of <i>visibility</i> when hiding Elements (only applies to \r
129  * effects that end with the element being visually hidden, ignored otherwise)\r
130  * @cfg {String/Object/Function} afterStyle A style specification string, e.g. <tt>"width:100px"</tt>, or an object\r
131  * in the form <tt>{width:"100px"}</tt>, or a function which returns such a specification that will be applied to the\r
132  * Element after the effect finishes.\r
133  * @cfg {Boolean} block Whether the effect should block other effects from queueing while it runs\r
134  * @cfg {Boolean} concurrent Whether to allow subsequently-queued effects to run at the same time as the current effect, or to ensure that they run in sequence\r
135  * @cfg {Boolean} stopFx Whether preceding effects should be stopped and removed before running current effect (only applies to non blocking effects)\r
136  */\r
137 Ext.Fx = {\r
138     \r
139     // private - calls the function taking arguments from the argHash based on the key.  Returns the return value of the function.\r
140     //           this is useful for replacing switch statements (for example).\r
141     switchStatements : function(key, fn, argHash){\r
142         return fn.apply(this, argHash[key]);\r
143     },\r
144     \r
145     /**\r
146      * Slides the element into view.  An anchor point can be optionally passed to set the point of\r
147      * origin for the slide effect.  This function automatically handles wrapping the element with\r
148      * a fixed-size container if needed.  See the Fx class overview for valid anchor point options.\r
149      * Usage:\r
150      *<pre><code>\r
151 // default: slide the element in from the top\r
152 el.slideIn();\r
153 \r
154 // custom: slide the element in from the right with a 2-second duration\r
155 el.slideIn('r', { duration: 2 });\r
156 \r
157 // common config options shown with default values\r
158 el.slideIn('t', {\r
159     easing: 'easeOut',\r
160     duration: .5\r
161 });\r
162 </code></pre>\r
163      * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to top: 't')\r
164      * @param {Object} options (optional) Object literal with any of the Fx config options\r
165      * @return {Ext.Element} The Element\r
166      */\r
167     slideIn : function(anchor, o){ \r
168         o = getObject(o);\r
169         var me = this,\r
170             dom = me.dom,\r
171             st = dom.style,\r
172             xy,\r
173             r,\r
174             b,              \r
175             wrap,               \r
176             after,\r
177             st,\r
178             args, \r
179             pt,\r
180             bw,\r
181             bh;\r
182             \r
183         anchor = anchor || "t";\r
184 \r
185         me.queueFx(o, function(){            \r
186             xy = fly(dom).getXY();\r
187             // fix display to visibility\r
188             fly(dom).fixDisplay();            \r
189             \r
190             // restore values after effect\r
191             r = fly(dom).getFxRestore();      \r
192             b = {x: xy[0], y: xy[1], 0: xy[0], 1: xy[1], width: dom.offsetWidth, height: dom.offsetHeight};\r
193             b.right = b.x + b.width;\r
194             b.bottom = b.y + b.height;\r
195             \r
196             // fixed size for slide\r
197             fly(dom).setWidth(b.width).setHeight(b.height);            \r
198             \r
199             // wrap if needed\r
200             wrap = fly(dom).fxWrap(r.pos, o, HIDDEN);\r
201             \r
202             st.visibility = VISIBLE;\r
203             st.position = ABSOLUTE;\r
204             \r
205             // clear out temp styles after slide and unwrap\r
206             function after(){\r
207                  fly(dom).fxUnwrap(wrap, r.pos, o);\r
208                  st.width = r.width;\r
209                  st.height = r.height;\r
210                  fly(dom).afterFx(o);\r
211             }\r
212             \r
213             // time to calculate the positions        \r
214             pt = {to: [b.x, b.y]}; \r
215             bw = {to: b.width};\r
216             bh = {to: b.height};\r
217                 \r
218             function argCalc(wrap, style, ww, wh, sXY, sXYval, s1, s2, w, h, p){                    \r
219                 var ret = {};\r
220                 fly(wrap).setWidth(ww).setHeight(wh);\r
221                 if(fly(wrap)[sXY]){\r
222                     fly(wrap)[sXY](sXYval);                  \r
223                 }\r
224                 style[s1] = style[s2] = "0";                    \r
225                 if(w){\r
226                     ret.width = w\r
227                 };\r
228                 if(h){\r
229                     ret.height = h;\r
230                 }\r
231                 if(p){\r
232                     ret.points = p;\r
233                 }\r
234                 return ret;\r
235             };\r
236 \r
237             args = fly(dom).switchStatements(anchor.toLowerCase(), argCalc, {\r
238                     t  : [wrap, st, b.width, 0, NULL, NULL, LEFT, BOTTOM, NULL, bh, NULL],\r
239                     l  : [wrap, st, 0, b.height, NULL, NULL, RIGHT, TOP, bw, NULL, NULL],\r
240                     r  : [wrap, st, b.width, b.height, SETX, b.right, LEFT, TOP, NULL, NULL, pt],\r
241                     b  : [wrap, st, b.width, b.height, SETY, b.bottom, LEFT, TOP, NULL, bh, pt],\r
242                     tl : [wrap, st, 0, 0, NULL, NULL, RIGHT, BOTTOM, bw, bh, pt],\r
243                     bl : [wrap, st, 0, 0, SETY, b.y + b.height, RIGHT, TOP, bw, bh, pt],\r
244                     br : [wrap, st, 0, 0, SETXY, [b.right, b.bottom], LEFT, TOP, bw, bh, pt],\r
245                     tr : [wrap, st, 0, 0, SETX, b.x + b.width, LEFT, BOTTOM, bw, bh, pt]\r
246                 });\r
247             \r
248             st.visibility = VISIBLE;\r
249             fly(wrap).show();\r
250 \r
251             arguments.callee.anim = fly(wrap).fxanim(args,\r
252                 o,\r
253                 MOTION,\r
254                 .5,\r
255                 EASEOUT, \r
256                 after);\r
257         });\r
258         return me;\r
259     },\r
260     \r
261     /**\r
262      * Slides the element out of view.  An anchor point can be optionally passed to set the end point\r
263      * for the slide effect.  When the effect is completed, the element will be hidden (visibility = \r
264      * 'hidden') but block elements will still take up space in the document.  The element must be removed\r
265      * from the DOM using the 'remove' config option if desired.  This function automatically handles \r
266      * wrapping the element with a fixed-size container if needed.  See the Fx class overview for valid anchor point options.\r
267      * Usage:\r
268      *<pre><code>\r
269 // default: slide the element out to the top\r
270 el.slideOut();\r
271 \r
272 // custom: slide the element out to the right with a 2-second duration\r
273 el.slideOut('r', { duration: 2 });\r
274 \r
275 // common config options shown with default values\r
276 el.slideOut('t', {\r
277     easing: 'easeOut',\r
278     duration: .5,\r
279     remove: false,\r
280     useDisplay: false\r
281 });\r
282 </code></pre>\r
283      * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to top: 't')\r
284      * @param {Object} options (optional) Object literal with any of the Fx config options\r
285      * @return {Ext.Element} The Element\r
286      */\r
287     slideOut : function(anchor, o){\r
288         o = getObject(o);\r
289         var me = this,\r
290             dom = me.dom,\r
291             st = dom.style,\r
292             xy = me.getXY(),\r
293             wrap,\r
294             r,\r
295             b,\r
296             a,\r
297             zero = {to: 0}; \r
298                     \r
299         anchor = anchor || "t";\r
300 \r
301         me.queueFx(o, function(){\r
302             \r
303             // restore values after effect\r
304             r = fly(dom).getFxRestore(); \r
305             b = {x: xy[0], y: xy[1], 0: xy[0], 1: xy[1], width: dom.offsetWidth, height: dom.offsetHeight};\r
306             b.right = b.x + b.width;\r
307             b.bottom = b.y + b.height;\r
308                 \r
309             // fixed size for slide   \r
310             fly(dom).setWidth(b.width).setHeight(b.height);\r
311 \r
312             // wrap if needed\r
313             wrap = fly(dom).fxWrap(r.pos, o, VISIBLE);\r
314                 \r
315             st.visibility = VISIBLE;\r
316             st.position = ABSOLUTE;\r
317             fly(wrap).setWidth(b.width).setHeight(b.height);            \r
318 \r
319             function after(){\r
320                 o.useDisplay ? fly(dom).setDisplayed(FALSE) : fly(dom).hide();                \r
321                 fly(dom).fxUnwrap(wrap, r.pos, o);\r
322                 st.width = r.width;\r
323                 st.height = r.height;\r
324                 fly(dom).afterFx(o);\r
325             }            \r
326             \r
327             function argCalc(style, s1, s2, p1, v1, p2, v2, p3, v3){                    \r
328                 var ret = {};\r
329                 \r
330                 style[s1] = style[s2] = "0";\r
331                 ret[p1] = v1;               \r
332                 if(p2){\r
333                     ret[p2] = v2;               \r
334                 }\r
335                 if(p3){\r
336                     ret[p3] = v3;\r
337                 }\r
338                 \r
339                 return ret;\r
340             };\r
341             \r
342             a = fly(dom).switchStatements(anchor.toLowerCase(), argCalc, {\r
343                 t  : [st, LEFT, BOTTOM, HEIGHT, zero],\r
344                 l  : [st, RIGHT, TOP, WIDTH, zero],\r
345                 r  : [st, LEFT, TOP, WIDTH, zero, POINTS, {to : [b.right, b.y]}],\r
346                 b  : [st, LEFT, TOP, HEIGHT, zero, POINTS, {to : [b.x, b.bottom]}],\r
347                 tl : [st, RIGHT, BOTTOM, WIDTH, zero, HEIGHT, zero],\r
348                 bl : [st, RIGHT, TOP, WIDTH, zero, HEIGHT, zero, POINTS, {to : [b.x, b.bottom]}],\r
349                 br : [st, LEFT, TOP, WIDTH, zero, HEIGHT, zero, POINTS, {to : [b.x + b.width, b.bottom]}],\r
350                 tr : [st, LEFT, BOTTOM, WIDTH, zero, HEIGHT, zero, POINTS, {to : [b.right, b.y]}]\r
351             });\r
352             \r
353             arguments.callee.anim = fly(wrap).fxanim(a,\r
354                 o,\r
355                 MOTION,\r
356                 .5,\r
357                 EASEOUT, \r
358                 after);\r
359         });\r
360         return me;\r
361     },\r
362 \r
363     /**\r
364      * Fades the element out while slowly expanding it in all directions.  When the effect is completed, the \r
365      * element will be hidden (visibility = 'hidden') but block elements will still take up space in the document. \r
366      * The element must be removed from the DOM using the 'remove' config option if desired.\r
367      * Usage:\r
368      *<pre><code>\r
369 // default\r
370 el.puff();\r
371 \r
372 // common config options shown with default values\r
373 el.puff({\r
374     easing: 'easeOut',\r
375     duration: .5,\r
376     remove: false,\r
377     useDisplay: false\r
378 });\r
379 </code></pre>\r
380      * @param {Object} options (optional) Object literal with any of the Fx config options\r
381      * @return {Ext.Element} The Element\r
382      */\r
383     puff : function(o){\r
384         o = getObject(o);\r
385         var me = this,\r
386             dom = me.dom,\r
387             st = dom.style,\r
388             width,\r
389             height,\r
390             r;\r
391 \r
392         me.queueFx(o, function(){\r
393             width = fly(dom).getWidth();\r
394             height = fly(dom).getHeight();\r
395             fly(dom).clearOpacity();\r
396             fly(dom).show();\r
397 \r
398             // restore values after effect\r
399             r = fly(dom).getFxRestore();                   \r
400             \r
401             function after(){\r
402                 o.useDisplay ? fly(dom).setDisplayed(FALSE) : fly(dom).hide();                  \r
403                 fly(dom).clearOpacity();  \r
404                 fly(dom).setPositioning(r.pos);\r
405                 st.width = r.width;\r
406                 st.height = r.height;\r
407                 st.fontSize = '';\r
408                 fly(dom).afterFx(o);\r
409             }   \r
410 \r
411             arguments.callee.anim = fly(dom).fxanim({\r
412                     width : {to : fly(dom).adjustWidth(width * 2)},\r
413                     height : {to : fly(dom).adjustHeight(height * 2)},\r
414                     points : {by : [-width * .5, -height * .5]},\r
415                     opacity : {to : 0},\r
416                     fontSize: {to : 200, unit: "%"}\r
417                 },\r
418                 o,\r
419                 MOTION,\r
420                 .5,\r
421                 EASEOUT,\r
422                  after);\r
423         });\r
424         return me;\r
425     },\r
426 \r
427     /**\r
428      * Blinks the element as if it was clicked and then collapses on its center (similar to switching off a television).\r
429      * When the effect is completed, the element will be hidden (visibility = 'hidden') but block elements will still \r
430      * take up space in the document. The element must be removed from the DOM using the 'remove' config option if desired.\r
431      * Usage:\r
432      *<pre><code>\r
433 // default\r
434 el.switchOff();\r
435 \r
436 // all config options shown with default values\r
437 el.switchOff({\r
438     easing: 'easeIn',\r
439     duration: .3,\r
440     remove: false,\r
441     useDisplay: false\r
442 });\r
443 </code></pre>\r
444      * @param {Object} options (optional) Object literal with any of the Fx config options\r
445      * @return {Ext.Element} The Element\r
446      */\r
447     switchOff : function(o){\r
448         o = getObject(o);\r
449         var me = this,\r
450             dom = me.dom,\r
451             st = dom.style,\r
452             r;\r
453 \r
454         me.queueFx(o, function(){\r
455             fly(dom).clearOpacity();\r
456             fly(dom).clip();\r
457 \r
458             // restore values after effect\r
459             r = fly(dom).getFxRestore();\r
460                 \r
461             function after(){\r
462                 o.useDisplay ? fly(dom).setDisplayed(FALSE) : fly(dom).hide();  \r
463                 fly(dom).clearOpacity();\r
464                 fly(dom).setPositioning(r.pos);\r
465                 st.width = r.width;\r
466                 st.height = r.height;   \r
467                 fly(dom).afterFx(o);\r
468             };\r
469 \r
470             fly(dom).fxanim({opacity : {to : 0.3}}, \r
471                 NULL, \r
472                 NULL, \r
473                 .1, \r
474                 NULL, \r
475                 function(){                                 \r
476                     fly(dom).clearOpacity();\r
477                         (function(){                            \r
478                             fly(dom).fxanim({\r
479                                 height : {to : 1},\r
480                                 points : {by : [0, fly(dom).getHeight() * .5]}\r
481                             }, \r
482                             o, \r
483                             MOTION, \r
484                             0.3, \r
485                             'easeIn', \r
486                             after);\r
487                         }).defer(100);\r
488                 });\r
489         });\r
490         return me;\r
491     },\r
492 \r
493     /**\r
494      * Highlights the Element by setting a color (applies to the background-color by default, but can be\r
495      * changed using the "attr" config option) and then fading back to the original color. If no original\r
496      * color is available, you should provide the "endColor" config option which will be cleared after the animation.\r
497      * Usage:\r
498 <pre><code>\r
499 // default: highlight background to yellow\r
500 el.highlight();\r
501 \r
502 // custom: highlight foreground text to blue for 2 seconds\r
503 el.highlight("0000ff", { attr: 'color', duration: 2 });\r
504 \r
505 // common config options shown with default values\r
506 el.highlight("ffff9c", {\r
507     attr: "background-color", //can be any valid CSS property (attribute) that supports a color value\r
508     endColor: (current color) or "ffffff",\r
509     easing: 'easeIn',\r
510     duration: 1\r
511 });\r
512 </code></pre>\r
513      * @param {String} color (optional) The highlight color. Should be a 6 char hex color without the leading # (defaults to yellow: 'ffff9c')\r
514      * @param {Object} options (optional) Object literal with any of the Fx config options\r
515      * @return {Ext.Element} The Element\r
516      */ \r
517     highlight : function(color, o){\r
518         o = getObject(o);\r
519         var me = this,\r
520             dom = me.dom,\r
521             attr = o.attr || "backgroundColor",\r
522             a = {},\r
523             restore;\r
524 \r
525         me.queueFx(o, function(){\r
526             fly(dom).clearOpacity();\r
527             fly(dom).show();\r
528 \r
529             function after(){\r
530                 dom.style[attr] = restore;\r
531                 fly(dom).afterFx(o);\r
532             }            \r
533             restore = dom.style[attr];\r
534             a[attr] = {from: color || "ffff9c", to: o.endColor || fly(dom).getColor(attr) || "ffffff"};\r
535             arguments.callee.anim = fly(dom).fxanim(a,\r
536                 o,\r
537                 'color',\r
538                 1,\r
539                 'easeIn', \r
540                 after);\r
541         });\r
542         return me;\r
543     },\r
544 \r
545    /**\r
546     * Shows a ripple of exploding, attenuating borders to draw attention to an Element.\r
547     * Usage:\r
548 <pre><code>\r
549 // default: a single light blue ripple\r
550 el.frame();\r
551 \r
552 // custom: 3 red ripples lasting 3 seconds total\r
553 el.frame("ff0000", 3, { duration: 3 });\r
554 \r
555 // common config options shown with default values\r
556 el.frame("C3DAF9", 1, {\r
557     duration: 1 //duration of each individual ripple.\r
558     // Note: Easing is not configurable and will be ignored if included\r
559 });\r
560 </code></pre>\r
561     * @param {String} color (optional) The color of the border.  Should be a 6 char hex color without the leading # (defaults to light blue: 'C3DAF9').\r
562     * @param {Number} count (optional) The number of ripples to display (defaults to 1)\r
563     * @param {Object} options (optional) Object literal with any of the Fx config options\r
564     * @return {Ext.Element} The Element\r
565     */\r
566     frame : function(color, count, o){\r
567         o = getObject(o);\r
568         var me = this,\r
569             dom = me.dom,\r
570             proxy,\r
571             active;\r
572 \r
573         me.queueFx(o, function(){\r
574             color = color || "#C3DAF9"\r
575             if(color.length == 6){\r
576                 color = "#" + color;\r
577             }            \r
578             count = count || 1;\r
579             fly(dom).show();\r
580 \r
581             var xy = fly(dom).getXY(),\r
582                 b = {x: xy[0], y: xy[1], 0: xy[0], 1: xy[1], width: dom.offsetWidth, height: dom.offsetHeight},\r
583                 queue = function(){\r
584                     proxy = fly(document.body || document.documentElement).createChild({\r
585                         style:{\r
586                             visbility: HIDDEN,\r
587                             position : ABSOLUTE,\r
588                             "z-index": 35000, // yee haw\r
589                             border : "0px solid " + color\r
590                         }\r
591                     });\r
592                     return proxy.queueFx({}, animFn);\r
593                 };\r
594             \r
595             \r
596             arguments.callee.anim = {\r
597                 isAnimated: true,\r
598                 stop: function() {\r
599                     count = 0;\r
600                     proxy.stopFx();\r
601                 }\r
602             };\r
603             \r
604             function animFn(){\r
605                 var scale = Ext.isBorderBox ? 2 : 1;\r
606                 active = proxy.anim({\r
607                     top : {from : b.y, to : b.y - 20},\r
608                     left : {from : b.x, to : b.x - 20},\r
609                     borderWidth : {from : 0, to : 10},\r
610                     opacity : {from : 1, to : 0},\r
611                     height : {from : b.height, to : b.height + 20 * scale},\r
612                     width : {from : b.width, to : b.width + 20 * scale}\r
613                 },{\r
614                     duration: o.duration || 1,\r
615                     callback: function() {\r
616                         proxy.remove();\r
617                         --count > 0 ? queue() : fly(dom).afterFx(o);\r
618                     }\r
619                 });\r
620                 arguments.callee.anim = {\r
621                     isAnimated: true,\r
622                     stop: function(){\r
623                         active.stop();\r
624                     }\r
625                 };\r
626             };\r
627             queue();\r
628         });\r
629         return me;\r
630     },\r
631 \r
632    /**\r
633     * Creates a pause before any subsequent queued effects begin.  If there are\r
634     * no effects queued after the pause it will have no effect.\r
635     * Usage:\r
636 <pre><code>\r
637 el.pause(1);\r
638 </code></pre>\r
639     * @param {Number} seconds The length of time to pause (in seconds)\r
640     * @return {Ext.Element} The Element\r
641     */\r
642     pause : function(seconds){        \r
643         var dom = this.dom,\r
644             t;\r
645 \r
646         this.queueFx({}, function(){\r
647             t = setTimeout(function(){\r
648                 fly(dom).afterFx({});\r
649             }, seconds * 1000);\r
650             arguments.callee.anim = {\r
651                 isAnimated: true,\r
652                 stop: function(){\r
653                     clearTimeout(t);\r
654                     fly(dom).afterFx({});\r
655                 }\r
656             };\r
657         });\r
658         return this;\r
659     },\r
660 \r
661    /**\r
662     * Fade an element in (from transparent to opaque).  The ending opacity can be specified\r
663     * using the <tt>{@link #endOpacity}</tt> config option.\r
664     * Usage:\r
665 <pre><code>\r
666 // default: fade in from opacity 0 to 100%\r
667 el.fadeIn();\r
668 \r
669 // custom: fade in from opacity 0 to 75% over 2 seconds\r
670 el.fadeIn({ endOpacity: .75, duration: 2});\r
671 \r
672 // common config options shown with default values\r
673 el.fadeIn({\r
674     endOpacity: 1, //can be any value between 0 and 1 (e.g. .5)\r
675     easing: 'easeOut',\r
676     duration: .5\r
677 });\r
678 </code></pre>\r
679     * @param {Object} options (optional) Object literal with any of the Fx config options\r
680     * @return {Ext.Element} The Element\r
681     */\r
682     fadeIn : function(o){\r
683         o = getObject(o);\r
684         var me = this,\r
685             dom = me.dom,\r
686             to = o.endOpacity || 1;\r
687         \r
688         me.queueFx(o, function(){\r
689             fly(dom).setOpacity(0);\r
690             fly(dom).fixDisplay();\r
691             dom.style.visibility = VISIBLE;\r
692             arguments.callee.anim = fly(dom).fxanim({opacity:{to:to}},\r
693                 o, NULL, .5, EASEOUT, function(){\r
694                 if(to == 1){\r
695                     fly(dom).clearOpacity();\r
696                 }\r
697                 fly(dom).afterFx(o);\r
698             });\r
699         });\r
700         return me;\r
701     },\r
702 \r
703    /**\r
704     * Fade an element out (from opaque to transparent).  The ending opacity can be specified\r
705     * using the <tt>{@link #endOpacity}</tt> config option.  Note that IE may require\r
706     * <tt>{@link #useDisplay}:true</tt> in order to redisplay correctly.\r
707     * Usage:\r
708 <pre><code>\r
709 // default: fade out from the element's current opacity to 0\r
710 el.fadeOut();\r
711 \r
712 // custom: fade out from the element's current opacity to 25% over 2 seconds\r
713 el.fadeOut({ endOpacity: .25, duration: 2});\r
714 \r
715 // common config options shown with default values\r
716 el.fadeOut({\r
717     endOpacity: 0, //can be any value between 0 and 1 (e.g. .5)\r
718     easing: 'easeOut',\r
719     duration: .5,\r
720     remove: false,\r
721     useDisplay: false\r
722 });\r
723 </code></pre>\r
724     * @param {Object} options (optional) Object literal with any of the Fx config options\r
725     * @return {Ext.Element} The Element\r
726     */\r
727     fadeOut : function(o){\r
728         o = getObject(o);\r
729         var me = this,\r
730             dom = me.dom,\r
731             style = dom.style,\r
732             to = o.endOpacity || 0;         \r
733         \r
734         me.queueFx(o, function(){  \r
735             arguments.callee.anim = fly(dom).fxanim({ \r
736                 opacity : {to : to}},\r
737                 o, \r
738                 NULL, \r
739                 .5, \r
740                 EASEOUT, \r
741                 function(){\r
742                     if(to == 0){\r
743                         Ext.Element.data(dom, 'visibilityMode') == Ext.Element.DISPLAY || o.useDisplay ? \r
744                             style.display = "none" :\r
745                             style.visibility = HIDDEN;\r
746                             \r
747                         fly(dom).clearOpacity();\r
748                     }\r
749                     fly(dom).afterFx(o);\r
750             });\r
751         });\r
752         return me;\r
753     },\r
754 \r
755    /**\r
756     * Animates the transition of an element's dimensions from a starting height/width\r
757     * to an ending height/width.  This method is a convenience implementation of {@link shift}.\r
758     * Usage:\r
759 <pre><code>\r
760 // change height and width to 100x100 pixels\r
761 el.scale(100, 100);\r
762 \r
763 // common config options shown with default values.  The height and width will default to\r
764 // the element&#39;s existing values if passed as null.\r
765 el.scale(\r
766     [element&#39;s width],\r
767     [element&#39;s height], {\r
768         easing: 'easeOut',\r
769         duration: .35\r
770     }\r
771 );\r
772 </code></pre>\r
773     * @param {Number} width  The new width (pass undefined to keep the original width)\r
774     * @param {Number} height  The new height (pass undefined to keep the original height)\r
775     * @param {Object} options (optional) Object literal with any of the Fx config options\r
776     * @return {Ext.Element} The Element\r
777     */\r
778     scale : function(w, h, o){\r
779         this.shift(Ext.apply({}, o, {\r
780             width: w,\r
781             height: h\r
782         }));\r
783         return this;\r
784     },\r
785 \r
786    /**\r
787     * Animates the transition of any combination of an element's dimensions, xy position and/or opacity.\r
788     * Any of these properties not specified in the config object will not be changed.  This effect \r
789     * requires that at least one new dimension, position or opacity setting must be passed in on\r
790     * the config object in order for the function to have any effect.\r
791     * Usage:\r
792 <pre><code>\r
793 // slide the element horizontally to x position 200 while changing the height and opacity\r
794 el.shift({ x: 200, height: 50, opacity: .8 });\r
795 \r
796 // common config options shown with default values.\r
797 el.shift({\r
798     width: [element&#39;s width],\r
799     height: [element&#39;s height],\r
800     x: [element&#39;s x position],\r
801     y: [element&#39;s y position],\r
802     opacity: [element&#39;s opacity],\r
803     easing: 'easeOut',\r
804     duration: .35\r
805 });\r
806 </code></pre>\r
807     * @param {Object} options  Object literal with any of the Fx config options\r
808     * @return {Ext.Element} The Element\r
809     */\r
810     shift : function(o){\r
811         o = getObject(o);\r
812         var dom = this.dom,\r
813             a = {};\r
814                 \r
815         this.queueFx(o, function(){\r
816             for (var prop in o) {\r
817                 if (o[prop] != UNDEFINED) {                                                 \r
818                     a[prop] = {to : o[prop]};                   \r
819                 }\r
820             } \r
821             \r
822             a.width ? a.width.to = fly(dom).adjustWidth(o.width) : a;\r
823             a.height ? a.height.to = fly(dom).adjustWidth(o.height) : a;   \r
824             \r
825             if (a.x || a.y || a.xy) {\r
826                 a.points = a.xy || \r
827                            {to : [ a.x ? a.x.to : fly(dom).getX(),\r
828                                    a.y ? a.y.to : fly(dom).getY()]};                  \r
829             }\r
830 \r
831             arguments.callee.anim = fly(dom).fxanim(a,\r
832                 o, \r
833                 MOTION, \r
834                 .35, \r
835                 EASEOUT, \r
836                 function(){\r
837                     fly(dom).afterFx(o);\r
838                 });\r
839         });\r
840         return this;\r
841     },\r
842 \r
843     /**\r
844      * Slides the element while fading it out of view.  An anchor point can be optionally passed to set the \r
845      * ending point of the effect.\r
846      * Usage:\r
847      *<pre><code>\r
848 // default: slide the element downward while fading out\r
849 el.ghost();\r
850 \r
851 // custom: slide the element out to the right with a 2-second duration\r
852 el.ghost('r', { duration: 2 });\r
853 \r
854 // common config options shown with default values\r
855 el.ghost('b', {\r
856     easing: 'easeOut',\r
857     duration: .5,\r
858     remove: false,\r
859     useDisplay: false\r
860 });\r
861 </code></pre>\r
862      * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to bottom: 'b')\r
863      * @param {Object} options (optional) Object literal with any of the Fx config options\r
864      * @return {Ext.Element} The Element\r
865      */\r
866     ghost : function(anchor, o){\r
867         o = getObject(o);\r
868         var me = this,\r
869             dom = me.dom,\r
870             st = dom.style,\r
871             a = {opacity: {to: 0}, points: {}},\r
872             pt = a.points,\r
873             r,\r
874             w,\r
875             h;\r
876             \r
877         anchor = anchor || "b";\r
878 \r
879         me.queueFx(o, function(){\r
880             // restore values after effect\r
881             r = fly(dom).getFxRestore();\r
882             w = fly(dom).getWidth();\r
883             h = fly(dom).getHeight();\r
884             \r
885             function after(){\r
886                 o.useDisplay ? fly(dom).setDisplayed(FALSE) : fly(dom).hide();   \r
887                 fly(dom).clearOpacity();\r
888                 fly(dom).setPositioning(r.pos);\r
889                 st.width = r.width;\r
890                 st.height = r.height;\r
891                 fly(dom).afterFx(o);\r
892             }\r
893                 \r
894             pt.by = fly(dom).switchStatements(anchor.toLowerCase(), function(v1,v2){ return [v1, v2];}, {\r
895                t  : [0, -h],\r
896                l  : [-w, 0],\r
897                r  : [w, 0],\r
898                b  : [0, h],\r
899                tl : [-w, -h],\r
900                bl : [-w, h],\r
901                br : [w, h],\r
902                tr : [w, -h] \r
903             });\r
904                 \r
905             arguments.callee.anim = fly(dom).fxanim(a,\r
906                 o,\r
907                 MOTION,\r
908                 .5,\r
909                 EASEOUT, after);\r
910         });\r
911         return me;\r
912     },\r
913 \r
914     /**\r
915      * Ensures that all effects queued after syncFx is called on the element are\r
916      * run concurrently.  This is the opposite of {@link #sequenceFx}.\r
917      * @return {Ext.Element} The Element\r
918      */\r
919     syncFx : function(){\r
920         var me = this;\r
921         me.fxDefaults = Ext.apply(me.fxDefaults || {}, {\r
922             block : FALSE,\r
923             concurrent : TRUE,\r
924             stopFx : FALSE\r
925         });\r
926         return me;\r
927     },\r
928 \r
929     /**\r
930      * Ensures that all effects queued after sequenceFx is called on the element are\r
931      * run in sequence.  This is the opposite of {@link #syncFx}.\r
932      * @return {Ext.Element} The Element\r
933      */\r
934     sequenceFx : function(){\r
935         var me = this;\r
936         me.fxDefaults = Ext.apply(me.fxDefaults || {}, {\r
937             block : FALSE,\r
938             concurrent : FALSE,\r
939             stopFx : FALSE\r
940         });\r
941         return me;\r
942     },\r
943 \r
944     /* @private */\r
945     nextFx : function(){        \r
946         var ef = getQueue(this.dom.id)[0];\r
947         if(ef){\r
948             ef.call(this);\r
949         }\r
950     },\r
951 \r
952     /**\r
953      * Returns true if the element has any effects actively running or queued, else returns false.\r
954      * @return {Boolean} True if element has active effects, else false\r
955      */\r
956     hasActiveFx : function(){\r
957         return getQueue(this.dom.id)[0];\r
958     },\r
959 \r
960     /**\r
961      * Stops any running effects and clears the element's internal effects queue if it contains\r
962      * any additional effects that haven't started yet.\r
963      * @return {Ext.Element} The Element\r
964      */\r
965     stopFx : function(finish){\r
966         var me = this,\r
967             id = me.dom.id;\r
968         if(me.hasActiveFx()){\r
969             var cur = getQueue(id)[0];\r
970             if(cur && cur.anim){\r
971                 if(cur.anim.isAnimated){\r
972                     setQueue(id, [cur]); //clear\r
973                     cur.anim.stop(finish !== undefined ? finish : TRUE);\r
974                 }else{\r
975                     setQueue(id, []);\r
976                 }\r
977             }\r
978         }\r
979         return me;\r
980     },\r
981 \r
982     /* @private */\r
983     beforeFx : function(o){\r
984         if(this.hasActiveFx() && !o.concurrent){\r
985            if(o.stopFx){\r
986                this.stopFx();\r
987                return TRUE;\r
988            }\r
989            return FALSE;\r
990         }\r
991         return TRUE;\r
992     },\r
993 \r
994     /**\r
995      * Returns true if the element is currently blocking so that no other effect can be queued\r
996      * until this effect is finished, else returns false if blocking is not set.  This is commonly\r
997      * used to ensure that an effect initiated by a user action runs to completion prior to the\r
998      * same effect being restarted (e.g., firing only one effect even if the user clicks several times).\r
999      * @return {Boolean} True if blocking, else false\r
1000      */\r
1001     hasFxBlock : function(){\r
1002         var q = getQueue(this.dom.id);\r
1003         return q && q[0] && q[0].block;\r
1004     },\r
1005 \r
1006     /* @private */\r
1007     queueFx : function(o, fn){\r
1008         var me = this;\r
1009         if(!me.hasFxBlock()){\r
1010             Ext.applyIf(o, me.fxDefaults);\r
1011             if(!o.concurrent){\r
1012                 var run = me.beforeFx(o);\r
1013                 fn.block = o.block;\r
1014                 getQueue(me.dom.id).push(fn);\r
1015                 if(run){\r
1016                     me.nextFx();\r
1017                 }\r
1018             }else{\r
1019                 fn.call(me);\r
1020             }\r
1021         }\r
1022         return me;\r
1023     },\r
1024 \r
1025     /* @private */\r
1026     fxWrap : function(pos, o, vis){ \r
1027         var dom = this.dom,\r
1028             wrap,\r
1029             wrapXY;\r
1030         if(!o.wrap || !(wrap = Ext.getDom(o.wrap))){            \r
1031             if(o.fixPosition){\r
1032                 wrapXY = fly(dom).getXY();\r
1033             }\r
1034             var div = document.createElement("div");\r
1035             div.style.visibility = vis;\r
1036             wrap = dom.parentNode.insertBefore(div, dom);\r
1037             fly(wrap).setPositioning(pos);\r
1038             if(fly(wrap).isStyle(POSITION, "static")){\r
1039                 fly(wrap).position("relative");\r
1040             }\r
1041             fly(dom).clearPositioning('auto');\r
1042             fly(wrap).clip();\r
1043             wrap.appendChild(dom);\r
1044             if(wrapXY){\r
1045                 fly(wrap).setXY(wrapXY);\r
1046             }\r
1047         }\r
1048         return wrap;\r
1049     },\r
1050 \r
1051     /* @private */\r
1052     fxUnwrap : function(wrap, pos, o){      \r
1053         var dom = this.dom;\r
1054         fly(dom).clearPositioning();\r
1055         fly(dom).setPositioning(pos);\r
1056         if(!o.wrap){\r
1057             wrap.parentNode.insertBefore(dom, wrap);\r
1058             fly(wrap).remove();\r
1059         }\r
1060     },\r
1061 \r
1062     /* @private */\r
1063     getFxRestore : function(){\r
1064         var st = this.dom.style;\r
1065         return {pos: this.getPositioning(), width: st.width, height : st.height};\r
1066     },\r
1067 \r
1068     /* @private */\r
1069     afterFx : function(o){\r
1070         var dom = this.dom,\r
1071             id = dom.id,\r
1072             notConcurrent = !o.concurrent;\r
1073         if(o.afterStyle){\r
1074             fly(dom).setStyle(o.afterStyle);            \r
1075         }\r
1076         if(o.afterCls){\r
1077             fly(dom).addClass(o.afterCls);\r
1078         }\r
1079         if(o.remove == TRUE){\r
1080             fly(dom).remove();\r
1081         }\r
1082         if(notConcurrent){\r
1083             getQueue(id).shift();\r
1084         }\r
1085         if(o.callback){\r
1086             o.callback.call(o.scope, fly(dom));\r
1087         }\r
1088         if(notConcurrent){\r
1089             fly(dom).nextFx();\r
1090         }\r
1091     },\r
1092 \r
1093     /* @private */\r
1094     fxanim : function(args, opt, animType, defaultDur, defaultEase, cb){\r
1095         animType = animType || 'run';\r
1096         opt = opt || {};\r
1097         var anim = Ext.lib.Anim[animType](\r
1098                 this.dom, \r
1099                 args,\r
1100                 (opt.duration || defaultDur) || .35,\r
1101                 (opt.easing || defaultEase) || EASEOUT,\r
1102                 cb,            \r
1103                 this\r
1104             );\r
1105         opt.anim = anim;\r
1106         return anim;\r
1107     }\r
1108 };\r
1109 \r
1110 // backwards compat\r
1111 Ext.Fx.resize = Ext.Fx.scale;\r
1112 \r
1113 //When included, Ext.Fx is automatically applied to Element so that all basic\r
1114 //effects are available directly via the Element API\r
1115 Ext.Element.addMethods(Ext.Fx);\r
1116 })();</pre>    \r
1117 </body>\r
1118 </html>