2 * @class Ext.core.Element
4 Ext.applyIf(Ext.core.Element.prototype, {
5 // @private override base Ext.util.Animate mixin for animate for backwards compatibility
6 animate: function(config) {
11 if (Ext.fx.Manager.hasFxBlock(me.id)) {
14 Ext.fx.Manager.queueFx(Ext.create('Ext.fx.Anim', me.anim(config)));
18 // @private override base Ext.util.Animate mixin for animate for backwards compatibility
19 anim: function(config) {
20 if (!Ext.isObject(config)) {
21 return (config) ? {} : false;
25 duration = config.duration || Ext.fx.Anim.prototype.duration,
26 easing = config.easing || 'ease',
29 if (config.stopAnimation) {
33 Ext.applyIf(config, Ext.fx.Manager.getFxDefaults(me.id));
35 // Clear any 'paused' defaults.
36 Ext.fx.Manager.setFxDefaults(me.id, {
42 remove: config.remove,
43 alternate: config.alternate || false,
46 callback: config.callback,
47 listeners: config.listeners,
48 iterations: config.iterations || 1,
51 concurrent: config.concurrent,
52 delay: config.delay || 0,
54 keyframes: config.keyframes,
55 from: config.from || {},
56 to: Ext.apply({}, config)
58 Ext.apply(animConfig.to, config.to);
60 // Anim API properties - backward compat
61 delete animConfig.to.to;
62 delete animConfig.to.from;
63 delete animConfig.to.remove;
64 delete animConfig.to.alternate;
65 delete animConfig.to.keyframes;
66 delete animConfig.to.iterations;
67 delete animConfig.to.listeners;
68 delete animConfig.to.target;
69 delete animConfig.to.paused;
70 delete animConfig.to.callback;
71 delete animConfig.to.scope;
72 delete animConfig.to.duration;
73 delete animConfig.to.easing;
74 delete animConfig.to.concurrent;
75 delete animConfig.to.block;
76 delete animConfig.to.stopAnimation;
77 delete animConfig.to.delay;
82 * Slides the element into view. An anchor point can be optionally passed to set the point of
83 * origin for the slide effect. This function automatically handles wrapping the element with
84 * a fixed-size container if needed. See the Fx class overview for valid anchor point options.
87 // default: slide the element in from the top
90 // custom: slide the element in from the right with a 2-second duration
91 el.slideIn('r', { duration: 2 });
93 // common config options shown with default values
99 * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to top: 't')
100 * @param {Object} options (optional) Object literal with any of the Fx config options
101 * @return {Ext.core.Element} The Element
103 slideIn: function(anchor, obj, slideOut) {
105 elStyle = me.dom.style,
106 beforeAnim, wrapAnim;
108 anchor = anchor || "t";
111 beforeAnim = function() {
112 var animScope = this,
113 listeners = obj.listeners,
114 box, position, restoreSize, wrap, anim;
121 if ((anchor == 't' || anchor == 'b') && box.height == 0) {
122 box.height = me.dom.scrollHeight;
124 else if ((anchor == 'l' || anchor == 'r') && box.width == 0) {
125 box.width = me.dom.scrollWidth;
128 position = me.getPositioning();
129 me.setSize(box.width, box.height);
133 visibility: slideOut ? 'visible' : 'hidden'
136 wrap.setPositioning(position);
137 if (wrap.isStyle('position', 'static')) {
138 wrap.position('relative');
140 me.clearPositioning('auto');
143 // This element is temporarily positioned absolute within its wrapper.
144 // Restore to its default, CSS-inherited visibility setting.
145 // We cannot explicitly poke visibility:visible into its style because that overrides the visibility of the wrap.
151 wrap.setSize(box.width, box.height);
158 width: box.width + 'px',
162 width: box.width + 'px',
163 height: box.height + 'px'
166 elStyle.bottom = '0px';
172 height: box.height + 'px'
175 width: box.width + 'px',
176 height: box.height + 'px'
179 elStyle.right = '0px';
184 x: box.x + box.width,
186 height: box.height + 'px'
190 width: box.width + 'px',
191 height: box.height + 'px'
198 y: box.y + box.height,
199 width: box.width + 'px',
204 width: box.width + 'px',
205 height: box.height + 'px'
218 width: box.width + 'px',
219 height: box.height + 'px'
222 elStyle.bottom = '0px';
223 elStyle.right = '0px';
228 x: box.x + box.width,
234 width: box.width + 'px',
235 height: box.height + 'px'
238 elStyle.right = '0px';
243 x: box.x + box.width,
244 y: box.y + box.height,
251 width: box.width + 'px',
252 height: box.height + 'px'
259 y: box.y + box.height,
265 width: box.width + 'px',
266 height: box.height + 'px'
269 elStyle.bottom = '0px';
274 wrapAnim = Ext.apply({}, obj);
275 delete wrapAnim.listeners;
276 wrapAnim = Ext.create('Ext.fx.Anim', Ext.applyIf(wrapAnim, {
280 from: slideOut ? anim.to : anim.from,
281 to: slideOut ? anim.from : anim.to
284 // In the absence of a callback, this listener MUST be added first
285 wrapAnim.on('afteranimate', function() {
287 me.setPositioning(position);
288 if (obj.useDisplay) {
289 me.setDisplayed(false);
295 me.clearPositioning();
296 me.setPositioning(position);
299 wrap.dom.parentNode.insertBefore(me.dom, wrap.dom);
302 me.setSize(box.width, box.height);
305 // Add configured listeners after
307 wrapAnim.on(listeners);
312 duration: obj.duration ? obj.duration * 2 : 1000,
319 if (wrapAnim && wrapAnim.running) {
331 * Slides the element out of view. An anchor point can be optionally passed to set the end point
332 * for the slide effect. When the effect is completed, the element will be hidden (visibility =
333 * 'hidden') but block elements will still take up space in the document. The element must be removed
334 * from the DOM using the 'remove' config option if desired. This function automatically handles
335 * wrapping the element with a fixed-size container if needed. See the Fx class overview for valid anchor point options.
338 // default: slide the element out to the top
341 // custom: slide the element out to the right with a 2-second duration
342 el.slideOut('r', { duration: 2 });
344 // common config options shown with default values
352 * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to top: 't')
353 * @param {Object} options (optional) Object literal with any of the Fx config options
354 * @return {Ext.core.Element} The Element
356 slideOut: function(anchor, o) {
357 return this.slideIn(anchor, o, true);
361 * Fades the element out while slowly expanding it in all directions. When the effect is completed, the
362 * element will be hidden (visibility = 'hidden') but block elements will still take up space in the document.
368 // common config options shown with default values
375 * @param {Object} options (optional) Object literal with any of the Fx config options
376 * @return {Ext.core.Element} The Element
379 puff: function(obj) {
382 obj = Ext.applyIf(obj || {}, {
388 beforeAnim = function() {
392 var box = me.getBox(),
393 fontSize = me.getStyle('fontSize'),
394 position = me.getPositioning();
396 width: box.width * 2,
397 height: box.height * 2,
398 x: box.x - (box.width / 2),
399 y: box.y - (box.height /2),
403 this.on('afteranimate',function() {
405 if (obj.useDisplay) {
406 me.setDisplayed(false);
411 me.setPositioning(position);
412 me.setStyle({fontSize: fontSize});
418 duration: obj.duration,
430 * Blinks the element as if it was clicked and then collapses on its center (similar to switching off a television).
431 * When the effect is completed, the element will be hidden (visibility = 'hidden') but block elements will still
432 * take up space in the document. The element must be removed from the DOM using the 'remove' config option if desired.
438 // all config options shown with default values
446 * @param {Object} options (optional) Object literal with any of the Fx config options
447 * @return {Ext.core.Element} The Element
449 switchOff: function(obj) {
453 obj = Ext.applyIf(obj || {}, {
460 beforeAnim = function() {
461 var animScope = this,
467 position = me.getPositioning();
469 keyframe = Ext.create('Ext.fx.Animator', {
471 duration: obj.duration,
479 y: xy[1] + size.height / 2
483 x: xy[0] + size.width / 2
487 keyframe.on('afteranimate', function() {
488 if (obj.useDisplay) {
489 me.setDisplayed(false);
494 me.setPositioning(position);
500 duration: (obj.duration * 2),
511 * Shows a ripple of exploding, attenuating borders to draw attention to an Element.
514 // default: a single light blue ripple
517 // custom: 3 red ripples lasting 3 seconds total
518 el.frame("#ff0000", 3, { duration: 3 });
520 // common config options shown with default values
521 el.frame("#C3DAF9", 1, {
522 duration: 1 //duration of each individual ripple.
523 // Note: Easing is not configurable and will be ignored if included
526 * @param {String} color (optional) The color of the border. Should be a 6 char hex color without the leading # (defaults to light blue: 'C3DAF9').
527 * @param {Number} count (optional) The number of ripples to display (defaults to 1)
528 * @param {Object} options (optional) Object literal with any of the Fx config options
529 * @return {Ext.core.Element} The Element
531 frame : function(color, count, obj){
535 color = color || '#C3DAF9';
539 beforeAnim = function() {
541 var animScope = this,
543 proxy = Ext.getBody().createChild({
545 position : 'absolute',
546 'pointer-events': 'none',
548 border : '0px solid ' + color
552 proxyAnim = Ext.create('Ext.fx.Anim', {
554 duration: obj.duration || 1000,
569 height: box.height + 40,
570 width: box.width + 40
573 proxyAnim.on('afteranimate', function() {
580 duration: (obj.duration * 2) || 2000,
591 * Slides the element while fading it out of view. An anchor point can be optionally passed to set the
592 * ending point of the effect.
595 // default: slide the element downward while fading out
598 // custom: slide the element out to the right with a 2-second duration
599 el.ghost('r', { duration: 2 });
601 // common config options shown with default values
607 * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to bottom: 'b')
608 * @param {Object} options (optional) Object literal with any of the Fx config options
609 * @return {Ext.core.Element} The Element
611 ghost: function(anchor, obj) {
615 anchor = anchor || "b";
616 beforeAnim = function() {
617 var width = me.getWidth(),
618 height = me.getHeight(),
620 position = me.getPositioning(),
626 to.y = xy[1] - height;
629 to.x = xy[0] - width;
632 to.x = xy[0] + width;
635 to.y = xy[1] + height;
638 to.x = xy[0] - width;
639 to.y = xy[1] - height;
642 to.x = xy[0] - width;
643 to.y = xy[1] + height;
646 to.x = xy[0] + width;
647 to.y = xy[1] + height;
650 to.x = xy[0] + width;
651 to.y = xy[1] - height;
655 this.on('afteranimate', function () {
659 me.setPositioning(position);
664 me.animate(Ext.applyIf(obj || {}, {
677 * Highlights the Element by setting a color (applies to the background-color by default, but can be
678 * changed using the "attr" config option) and then fading back to the original color. If no original
679 * color is available, you should provide the "endColor" config option which will be cleared after the animation.
682 // default: highlight background to yellow
685 // custom: highlight foreground text to blue for 2 seconds
686 el.highlight("0000ff", { attr: 'color', duration: 2 });
688 // common config options shown with default values
689 el.highlight("ffff9c", {
690 attr: "backgroundColor", //can be any valid CSS property (attribute) that supports a color value
691 endColor: (current color) or "ffffff",
696 * @param {String} color (optional) The highlight color. Should be a 6 char hex color without the leading # (defaults to yellow: 'ffff9c')
697 * @param {Object} options (optional) Object literal with any of the Fx config options
698 * @return {Ext.core.Element} The Element
700 highlight: function(color, o) {
704 restore, to, attr, lns, event, fn;
707 lns = o.listeners || {};
708 attr = o.attr || 'backgroundColor';
709 from[attr] = color || 'ffff9c';
713 to[attr] = o.endColor || me.getColor(attr, 'ffffff', '');
719 // Don't apply directly on lns, since we reference it in our own callbacks below
720 o.listeners = Ext.apply(Ext.apply({}, lns), {
721 beforeanimate: function() {
722 restore = dom.style[attr];
726 event = lns.beforeanimate;
728 fn = event.fn || event;
729 return fn.apply(event.scope || lns.scope || window, arguments);
732 afteranimate: function() {
734 dom.style[attr] = restore;
737 event = lns.afteranimate;
739 fn = event.fn || event;
740 fn.apply(event.scope || lns.scope || window, arguments);
745 me.animate(Ext.apply({}, o, {
756 * Creates a pause before any subsequent queued effects begin. If there are
757 * no effects queued after the pause it will have no effect.
762 * @param {Number} seconds The length of time to pause (in seconds)
763 * @return {Ext.Element} The Element
765 pause: function(ms) {
767 Ext.fx.Manager.setFxDefaults(me.id, {
774 * Fade an element in (from transparent to opaque). The ending opacity can be specified
775 * using the <tt>{@link #endOpacity}</tt> config option.
778 // default: fade in from opacity 0 to 100%
781 // custom: fade in from opacity 0 to 75% over 2 seconds
782 el.fadeIn({ endOpacity: .75, duration: 2});
784 // common config options shown with default values
786 endOpacity: 1, //can be any value between 0 and 1 (e.g. .5)
791 * @param {Object} options (optional) Object literal with any of the Fx config options
792 * @return {Ext.Element} The Element
794 fadeIn: function(o) {
795 this.animate(Ext.apply({}, o, {
802 * Fade an element out (from opaque to transparent). The ending opacity can be specified
803 * using the <tt>{@link #endOpacity}</tt> config option. Note that IE may require
804 * <tt>{@link #useDisplay}:true</tt> in order to redisplay correctly.
807 // default: fade out from the element's current opacity to 0
810 // custom: fade out from the element's current opacity to 25% over 2 seconds
811 el.fadeOut({ endOpacity: .25, duration: 2});
813 // common config options shown with default values
815 endOpacity: 0, //can be any value between 0 and 1 (e.g. .5)
822 * @param {Object} options (optional) Object literal with any of the Fx config options
823 * @return {Ext.Element} The Element
825 fadeOut: function(o) {
826 this.animate(Ext.apply({}, o, {
834 * Animates the transition of an element's dimensions from a starting height/width
835 * to an ending height/width. This method is a convenience implementation of {@link shift}.
838 // change height and width to 100x100 pixels
841 // common config options shown with default values. The height and width will default to
842 // the element's existing values if passed as null.
844 [element's width],
845 [element's height], {
851 * @param {Number} width The new width (pass undefined to keep the original width)
852 * @param {Number} height The new height (pass undefined to keep the original height)
853 * @param {Object} options (optional) Object literal with any of the Fx config options
854 * @return {Ext.Element} The Element
856 scale: function(w, h, o) {
857 this.animate(Ext.apply({}, o, {
866 * Animates the transition of any combination of an element's dimensions, xy position and/or opacity.
867 * Any of these properties not specified in the config object will not be changed. This effect
868 * requires that at least one new dimension, position or opacity setting must be passed in on
869 * the config object in order for the function to have any effect.
872 // slide the element horizontally to x position 200 while changing the height and opacity
873 el.shift({ x: 200, height: 50, opacity: .8 });
875 // common config options shown with default values.
877 width: [element's width],
878 height: [element's height],
879 x: [element's x position],
880 y: [element's y position],
881 opacity: [element's opacity],
886 * @param {Object} options Object literal with any of the Fx config options
887 * @return {Ext.Element} The Element
889 shift: function(config) {
890 this.animate(config);