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