3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * @class Ext.core.Element
18 Ext.applyIf(Ext.core.Element.prototype, {
19 // @private override base Ext.util.Animate mixin for animate for backwards compatibility
20 animate: function(config) {
25 if (Ext.fx.Manager.hasFxBlock(me.id)) {
28 Ext.fx.Manager.queueFx(Ext.create('Ext.fx.Anim', me.anim(config)));
32 // @private override base Ext.util.Animate mixin for animate for backwards compatibility
33 anim: function(config) {
34 if (!Ext.isObject(config)) {
35 return (config) ? {} : false;
39 duration = config.duration || Ext.fx.Anim.prototype.duration,
40 easing = config.easing || 'ease',
43 if (config.stopAnimation) {
47 Ext.applyIf(config, Ext.fx.Manager.getFxDefaults(me.id));
49 // Clear any 'paused' defaults.
50 Ext.fx.Manager.setFxDefaults(me.id, {
56 remove: config.remove,
57 alternate: config.alternate || false,
60 callback: config.callback,
61 listeners: config.listeners,
62 iterations: config.iterations || 1,
65 concurrent: config.concurrent,
66 delay: config.delay || 0,
68 keyframes: config.keyframes,
69 from: config.from || {},
70 to: Ext.apply({}, config)
72 Ext.apply(animConfig.to, config.to);
74 // Anim API properties - backward compat
75 delete animConfig.to.to;
76 delete animConfig.to.from;
77 delete animConfig.to.remove;
78 delete animConfig.to.alternate;
79 delete animConfig.to.keyframes;
80 delete animConfig.to.iterations;
81 delete animConfig.to.listeners;
82 delete animConfig.to.target;
83 delete animConfig.to.paused;
84 delete animConfig.to.callback;
85 delete animConfig.to.scope;
86 delete animConfig.to.duration;
87 delete animConfig.to.easing;
88 delete animConfig.to.concurrent;
89 delete animConfig.to.block;
90 delete animConfig.to.stopAnimation;
91 delete animConfig.to.delay;
96 * Slides the element into view. An anchor point can be optionally passed to set the point of
97 * origin for the slide effect. This function automatically handles wrapping the element with
98 * a fixed-size container if needed. See the Fx class overview for valid anchor point options.
101 // default: slide the element in from the top
104 // custom: slide the element in from the right with a 2-second duration
105 el.slideIn('r', { duration: 2 });
107 // common config options shown with default values
113 * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to top: 't')
114 * @param {Object} options (optional) Object literal with any of the Fx config options
115 * @return {Ext.core.Element} The Element
117 slideIn: function(anchor, obj, slideOut) {
119 elStyle = me.dom.style,
120 beforeAnim, wrapAnim;
122 anchor = anchor || "t";
125 beforeAnim = function() {
126 var animScope = this,
127 listeners = obj.listeners,
128 box, position, restoreSize, wrap, anim;
135 if ((anchor == 't' || anchor == 'b') && box.height == 0) {
136 box.height = me.dom.scrollHeight;
138 else if ((anchor == 'l' || anchor == 'r') && box.width == 0) {
139 box.width = me.dom.scrollWidth;
142 position = me.getPositioning();
143 me.setSize(box.width, box.height);
147 visibility: slideOut ? 'visible' : 'hidden'
150 wrap.setPositioning(position);
151 if (wrap.isStyle('position', 'static')) {
152 wrap.position('relative');
154 me.clearPositioning('auto');
157 // This element is temporarily positioned absolute within its wrapper.
158 // Restore to its default, CSS-inherited visibility setting.
159 // We cannot explicitly poke visibility:visible into its style because that overrides the visibility of the wrap.
165 wrap.setSize(box.width, box.height);
172 width: box.width + 'px',
176 width: box.width + 'px',
177 height: box.height + 'px'
180 elStyle.bottom = '0px';
186 height: box.height + 'px'
189 width: box.width + 'px',
190 height: box.height + 'px'
193 elStyle.right = '0px';
198 x: box.x + box.width,
200 height: box.height + 'px'
204 width: box.width + 'px',
205 height: box.height + 'px'
212 y: box.y + box.height,
213 width: box.width + 'px',
218 width: box.width + 'px',
219 height: box.height + 'px'
232 width: box.width + 'px',
233 height: box.height + 'px'
236 elStyle.bottom = '0px';
237 elStyle.right = '0px';
242 x: box.x + box.width,
248 width: box.width + 'px',
249 height: box.height + 'px'
252 elStyle.right = '0px';
257 x: box.x + box.width,
258 y: box.y + box.height,
265 width: box.width + 'px',
266 height: box.height + 'px'
273 y: box.y + box.height,
279 width: box.width + 'px',
280 height: box.height + 'px'
283 elStyle.bottom = '0px';
288 wrapAnim = Ext.apply({}, obj);
289 delete wrapAnim.listeners;
290 wrapAnim = Ext.create('Ext.fx.Anim', Ext.applyIf(wrapAnim, {
294 from: slideOut ? anim.to : anim.from,
295 to: slideOut ? anim.from : anim.to
298 // In the absence of a callback, this listener MUST be added first
299 wrapAnim.on('afteranimate', function() {
301 me.setPositioning(position);
302 if (obj.useDisplay) {
303 me.setDisplayed(false);
309 me.clearPositioning();
310 me.setPositioning(position);
313 wrap.dom.parentNode.insertBefore(me.dom, wrap.dom);
316 me.setSize(box.width, box.height);
319 // Add configured listeners after
321 wrapAnim.on(listeners);
326 duration: obj.duration ? obj.duration * 2 : 1000,
333 if (wrapAnim && wrapAnim.running) {
345 * Slides the element out of view. An anchor point can be optionally passed to set the end point
346 * for the slide effect. When the effect is completed, the element will be hidden (visibility =
347 * 'hidden') but block elements will still take up space in the document. The element must be removed
348 * from the DOM using the 'remove' config option if desired. This function automatically handles
349 * wrapping the element with a fixed-size container if needed. See the Fx class overview for valid anchor point options.
352 // default: slide the element out to the top
355 // custom: slide the element out to the right with a 2-second duration
356 el.slideOut('r', { duration: 2 });
358 // common config options shown with default values
366 * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to top: 't')
367 * @param {Object} options (optional) Object literal with any of the Fx config options
368 * @return {Ext.core.Element} The Element
370 slideOut: function(anchor, o) {
371 return this.slideIn(anchor, o, true);
375 * Fades the element out while slowly expanding it in all directions. When the effect is completed, the
376 * element will be hidden (visibility = 'hidden') but block elements will still take up space in the document.
382 // common config options shown with default values
389 * @param {Object} options (optional) Object literal with any of the Fx config options
390 * @return {Ext.core.Element} The Element
393 puff: function(obj) {
396 obj = Ext.applyIf(obj || {}, {
402 beforeAnim = function() {
406 var box = me.getBox(),
407 fontSize = me.getStyle('fontSize'),
408 position = me.getPositioning();
410 width: box.width * 2,
411 height: box.height * 2,
412 x: box.x - (box.width / 2),
413 y: box.y - (box.height /2),
417 this.on('afteranimate',function() {
419 if (obj.useDisplay) {
420 me.setDisplayed(false);
425 me.setPositioning(position);
426 me.setStyle({fontSize: fontSize});
432 duration: obj.duration,
444 * Blinks the element as if it was clicked and then collapses on its center (similar to switching off a television).
445 * When the effect is completed, the element will be hidden (visibility = 'hidden') but block elements will still
446 * take up space in the document. The element must be removed from the DOM using the 'remove' config option if desired.
452 // all config options shown with default values
460 * @param {Object} options (optional) Object literal with any of the Fx config options
461 * @return {Ext.core.Element} The Element
463 switchOff: function(obj) {
467 obj = Ext.applyIf(obj || {}, {
474 beforeAnim = function() {
475 var animScope = this,
481 position = me.getPositioning();
483 keyframe = Ext.create('Ext.fx.Animator', {
485 duration: obj.duration,
493 y: xy[1] + size.height / 2
497 x: xy[0] + size.width / 2
501 keyframe.on('afteranimate', function() {
502 if (obj.useDisplay) {
503 me.setDisplayed(false);
508 me.setPositioning(position);
514 duration: (obj.duration * 2),
525 * Shows a ripple of exploding, attenuating borders to draw attention to an Element.
528 // default: a single light blue ripple
531 // custom: 3 red ripples lasting 3 seconds total
532 el.frame("#ff0000", 3, { duration: 3 });
534 // common config options shown with default values
535 el.frame("#C3DAF9", 1, {
536 duration: 1 //duration of each individual ripple.
537 // Note: Easing is not configurable and will be ignored if included
540 * @param {String} color (optional) The color of the border. Should be a 6 char hex color without the leading # (defaults to light blue: 'C3DAF9').
541 * @param {Number} count (optional) The number of ripples to display (defaults to 1)
542 * @param {Object} options (optional) Object literal with any of the Fx config options
543 * @return {Ext.core.Element} The Element
545 frame : function(color, count, obj){
549 color = color || '#C3DAF9';
553 beforeAnim = function() {
555 var animScope = this,
557 proxy = Ext.getBody().createChild({
559 position : 'absolute',
560 'pointer-events': 'none',
562 border : '0px solid ' + color
566 proxyAnim = Ext.create('Ext.fx.Anim', {
568 duration: obj.duration || 1000,
583 height: box.height + 40,
584 width: box.width + 40
587 proxyAnim.on('afteranimate', function() {
594 duration: (obj.duration * 2) || 2000,
605 * Slides the element while fading it out of view. An anchor point can be optionally passed to set the
606 * ending point of the effect.
609 // default: slide the element downward while fading out
612 // custom: slide the element out to the right with a 2-second duration
613 el.ghost('r', { duration: 2 });
615 // common config options shown with default values
621 * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to bottom: 'b')
622 * @param {Object} options (optional) Object literal with any of the Fx config options
623 * @return {Ext.core.Element} The Element
625 ghost: function(anchor, obj) {
629 anchor = anchor || "b";
630 beforeAnim = function() {
631 var width = me.getWidth(),
632 height = me.getHeight(),
634 position = me.getPositioning(),
640 to.y = xy[1] - height;
643 to.x = xy[0] - width;
646 to.x = xy[0] + width;
649 to.y = xy[1] + height;
652 to.x = xy[0] - width;
653 to.y = xy[1] - height;
656 to.x = xy[0] - width;
657 to.y = xy[1] + height;
660 to.x = xy[0] + width;
661 to.y = xy[1] + height;
664 to.x = xy[0] + width;
665 to.y = xy[1] - height;
669 this.on('afteranimate', function () {
673 me.setPositioning(position);
678 me.animate(Ext.applyIf(obj || {}, {
691 * Highlights the Element by setting a color (applies to the background-color by default, but can be
692 * changed using the "attr" config option) and then fading back to the original color. If no original
693 * color is available, you should provide the "endColor" config option which will be cleared after the animation.
696 // default: highlight background to yellow
699 // custom: highlight foreground text to blue for 2 seconds
700 el.highlight("0000ff", { attr: 'color', duration: 2 });
702 // common config options shown with default values
703 el.highlight("ffff9c", {
704 attr: "backgroundColor", //can be any valid CSS property (attribute) that supports a color value
705 endColor: (current color) or "ffffff",
710 * @param {String} color (optional) The highlight color. Should be a 6 char hex color without the leading # (defaults to yellow: 'ffff9c')
711 * @param {Object} options (optional) Object literal with any of the Fx config options
712 * @return {Ext.core.Element} The Element
714 highlight: function(color, o) {
718 restore, to, attr, lns, event, fn;
721 lns = o.listeners || {};
722 attr = o.attr || 'backgroundColor';
723 from[attr] = color || 'ffff9c';
727 to[attr] = o.endColor || me.getColor(attr, 'ffffff', '');
733 // Don't apply directly on lns, since we reference it in our own callbacks below
734 o.listeners = Ext.apply(Ext.apply({}, lns), {
735 beforeanimate: function() {
736 restore = dom.style[attr];
740 event = lns.beforeanimate;
742 fn = event.fn || event;
743 return fn.apply(event.scope || lns.scope || window, arguments);
746 afteranimate: function() {
748 dom.style[attr] = restore;
751 event = lns.afteranimate;
753 fn = event.fn || event;
754 fn.apply(event.scope || lns.scope || window, arguments);
759 me.animate(Ext.apply({}, o, {
770 * Creates a pause before any subsequent queued effects begin. If there are
771 * no effects queued after the pause it will have no effect.
776 * @param {Number} seconds The length of time to pause (in seconds)
777 * @return {Ext.Element} The Element
779 pause: function(ms) {
781 Ext.fx.Manager.setFxDefaults(me.id, {
788 * Fade an element in (from transparent to opaque). The ending opacity can be specified
789 * using the <tt>{@link #endOpacity}</tt> config option.
792 // default: fade in from opacity 0 to 100%
795 // custom: fade in from opacity 0 to 75% over 2 seconds
796 el.fadeIn({ endOpacity: .75, duration: 2});
798 // common config options shown with default values
800 endOpacity: 1, //can be any value between 0 and 1 (e.g. .5)
805 * @param {Object} options (optional) Object literal with any of the Fx config options
806 * @return {Ext.Element} The Element
808 fadeIn: function(o) {
809 this.animate(Ext.apply({}, o, {
816 * Fade an element out (from opaque to transparent). The ending opacity can be specified
817 * using the <tt>{@link #endOpacity}</tt> config option. Note that IE may require
818 * <tt>{@link #useDisplay}:true</tt> in order to redisplay correctly.
821 // default: fade out from the element's current opacity to 0
824 // custom: fade out from the element's current opacity to 25% over 2 seconds
825 el.fadeOut({ endOpacity: .25, duration: 2});
827 // common config options shown with default values
829 endOpacity: 0, //can be any value between 0 and 1 (e.g. .5)
836 * @param {Object} options (optional) Object literal with any of the Fx config options
837 * @return {Ext.Element} The Element
839 fadeOut: function(o) {
840 this.animate(Ext.apply({}, o, {
848 * Animates the transition of an element's dimensions from a starting height/width
849 * to an ending height/width. This method is a convenience implementation of {@link #shift}.
852 // change height and width to 100x100 pixels
855 // common config options shown with default values. The height and width will default to
856 // the element's existing values if passed as null.
858 [element's width],
859 [element's height], {
865 * @param {Number} width The new width (pass undefined to keep the original width)
866 * @param {Number} height The new height (pass undefined to keep the original height)
867 * @param {Object} options (optional) Object literal with any of the Fx config options
868 * @return {Ext.Element} The Element
870 scale: function(w, h, o) {
871 this.animate(Ext.apply({}, o, {
880 * Animates the transition of any combination of an element's dimensions, xy position and/or opacity.
881 * Any of these properties not specified in the config object will not be changed. This effect
882 * requires that at least one new dimension, position or opacity setting must be passed in on
883 * the config object in order for the function to have any effect.
886 // slide the element horizontally to x position 200 while changing the height and opacity
887 el.shift({ x: 200, height: 50, opacity: .8 });
889 // common config options shown with default values.
891 width: [element's width],
892 height: [element's height],
893 x: [element's x position],
894 y: [element's y position],
895 opacity: [element's opacity],
900 * @param {Object} options Object literal with any of the Fx config options
901 * @return {Ext.Element} The Element
903 shift: function(config) {
904 this.animate(config);