4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-core-Element'>/**
19 </span> * @class Ext.core.Element
21 Ext.applyIf(Ext.core.Element.prototype, {
22 // @private override base Ext.util.Animate mixin for animate for backwards compatibility
23 animate: function(config) {
28 if (Ext.fx.Manager.hasFxBlock(me.id)) {
31 Ext.fx.Manager.queueFx(Ext.create('Ext.fx.Anim', me.anim(config)));
35 // @private override base Ext.util.Animate mixin for animate for backwards compatibility
36 anim: function(config) {
37 if (!Ext.isObject(config)) {
38 return (config) ? {} : false;
42 duration = config.duration || Ext.fx.Anim.prototype.duration,
43 easing = config.easing || 'ease',
46 if (config.stopAnimation) {
50 Ext.applyIf(config, Ext.fx.Manager.getFxDefaults(me.id));
52 // Clear any 'paused' defaults.
53 Ext.fx.Manager.setFxDefaults(me.id, {
59 remove: config.remove,
60 alternate: config.alternate || false,
63 callback: config.callback,
64 listeners: config.listeners,
65 iterations: config.iterations || 1,
68 concurrent: config.concurrent,
69 delay: config.delay || 0,
71 keyframes: config.keyframes,
72 from: config.from || {},
73 to: Ext.apply({}, config)
75 Ext.apply(animConfig.to, config.to);
77 // Anim API properties - backward compat
78 delete animConfig.to.to;
79 delete animConfig.to.from;
80 delete animConfig.to.remove;
81 delete animConfig.to.alternate;
82 delete animConfig.to.keyframes;
83 delete animConfig.to.iterations;
84 delete animConfig.to.listeners;
85 delete animConfig.to.target;
86 delete animConfig.to.paused;
87 delete animConfig.to.callback;
88 delete animConfig.to.scope;
89 delete animConfig.to.duration;
90 delete animConfig.to.easing;
91 delete animConfig.to.concurrent;
92 delete animConfig.to.block;
93 delete animConfig.to.stopAnimation;
94 delete animConfig.to.delay;
98 <span id='Ext-core-Element-method-slideIn'> /**
99 </span> * Slides the element into view. An anchor point can be optionally passed to set the point of
100 * origin for the slide effect. This function automatically handles wrapping the element with
101 * a fixed-size container if needed. See the Fx class overview for valid anchor point options.
103 *<pre><code>
104 // default: slide the element in from the top
107 // custom: slide the element in from the right with a 2-second duration
108 el.slideIn('r', { duration: 2 });
110 // common config options shown with default values
115 </code></pre>
116 * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to top: 't')
117 * @param {Object} options (optional) Object literal with any of the Fx config options
118 * @return {Ext.core.Element} The Element
120 slideIn: function(anchor, obj, slideOut) {
122 elStyle = me.dom.style,
123 beforeAnim, wrapAnim;
125 anchor = anchor || "t";
128 beforeAnim = function() {
129 var animScope = this,
130 listeners = obj.listeners,
131 box, position, restoreSize, wrap, anim;
138 if ((anchor == 't' || anchor == 'b') && box.height == 0) {
139 box.height = me.dom.scrollHeight;
141 else if ((anchor == 'l' || anchor == 'r') && box.width == 0) {
142 box.width = me.dom.scrollWidth;
145 position = me.getPositioning();
146 me.setSize(box.width, box.height);
150 visibility: slideOut ? 'visible' : 'hidden'
153 wrap.setPositioning(position);
154 if (wrap.isStyle('position', 'static')) {
155 wrap.position('relative');
157 me.clearPositioning('auto');
160 // This element is temporarily positioned absolute within its wrapper.
161 // Restore to its default, CSS-inherited visibility setting.
162 // We cannot explicitly poke visibility:visible into its style because that overrides the visibility of the wrap.
168 wrap.setSize(box.width, box.height);
175 width: box.width + 'px',
179 width: box.width + 'px',
180 height: box.height + 'px'
183 elStyle.bottom = '0px';
189 height: box.height + 'px'
192 width: box.width + 'px',
193 height: box.height + 'px'
196 elStyle.right = '0px';
201 x: box.x + box.width,
203 height: box.height + 'px'
207 width: box.width + 'px',
208 height: box.height + 'px'
215 y: box.y + box.height,
216 width: box.width + 'px',
221 width: box.width + 'px',
222 height: box.height + 'px'
235 width: box.width + 'px',
236 height: box.height + 'px'
239 elStyle.bottom = '0px';
240 elStyle.right = '0px';
245 x: box.x + box.width,
251 width: box.width + 'px',
252 height: box.height + 'px'
255 elStyle.right = '0px';
260 x: box.x + box.width,
261 y: box.y + box.height,
268 width: box.width + 'px',
269 height: box.height + 'px'
276 y: box.y + box.height,
282 width: box.width + 'px',
283 height: box.height + 'px'
286 elStyle.bottom = '0px';
291 wrapAnim = Ext.apply({}, obj);
292 delete wrapAnim.listeners;
293 wrapAnim = Ext.create('Ext.fx.Anim', Ext.applyIf(wrapAnim, {
297 from: slideOut ? anim.to : anim.from,
298 to: slideOut ? anim.from : anim.to
301 // In the absence of a callback, this listener MUST be added first
302 wrapAnim.on('afteranimate', function() {
304 me.setPositioning(position);
305 if (obj.useDisplay) {
306 me.setDisplayed(false);
312 me.clearPositioning();
313 me.setPositioning(position);
316 wrap.dom.parentNode.insertBefore(me.dom, wrap.dom);
319 me.setSize(box.width, box.height);
322 // Add configured listeners after
324 wrapAnim.on(listeners);
329 duration: obj.duration ? obj.duration * 2 : 1000,
336 if (wrapAnim && wrapAnim.running) {
347 <span id='Ext-core-Element-method-slideOut'> /**
348 </span> * Slides the element out of view. An anchor point can be optionally passed to set the end point
349 * for the slide effect. When the effect is completed, the element will be hidden (visibility =
350 * 'hidden') but block elements will still take up space in the document. The element must be removed
351 * from the DOM using the 'remove' config option if desired. This function automatically handles
352 * wrapping the element with a fixed-size container if needed. See the Fx class overview for valid anchor point options.
354 *<pre><code>
355 // default: slide the element out to the top
358 // custom: slide the element out to the right with a 2-second duration
359 el.slideOut('r', { duration: 2 });
361 // common config options shown with default values
368 </code></pre>
369 * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to top: 't')
370 * @param {Object} options (optional) Object literal with any of the Fx config options
371 * @return {Ext.core.Element} The Element
373 slideOut: function(anchor, o) {
374 return this.slideIn(anchor, o, true);
377 <span id='Ext-core-Element-method-puff'> /**
378 </span> * Fades the element out while slowly expanding it in all directions. When the effect is completed, the
379 * element will be hidden (visibility = 'hidden') but block elements will still take up space in the document.
381 *<pre><code>
385 // common config options shown with default values
391 </code></pre>
392 * @param {Object} options (optional) Object literal with any of the Fx config options
393 * @return {Ext.core.Element} The Element
396 puff: function(obj) {
399 obj = Ext.applyIf(obj || {}, {
405 beforeAnim = function() {
409 var box = me.getBox(),
410 fontSize = me.getStyle('fontSize'),
411 position = me.getPositioning();
413 width: box.width * 2,
414 height: box.height * 2,
415 x: box.x - (box.width / 2),
416 y: box.y - (box.height /2),
420 this.on('afteranimate',function() {
422 if (obj.useDisplay) {
423 me.setDisplayed(false);
428 me.setPositioning(position);
429 me.setStyle({fontSize: fontSize});
435 duration: obj.duration,
446 <span id='Ext-core-Element-method-switchOff'> /**
447 </span> * Blinks the element as if it was clicked and then collapses on its center (similar to switching off a television).
448 * When the effect is completed, the element will be hidden (visibility = 'hidden') but block elements will still
449 * take up space in the document. The element must be removed from the DOM using the 'remove' config option if desired.
451 *<pre><code>
455 // all config options shown with default values
462 </code></pre>
463 * @param {Object} options (optional) Object literal with any of the Fx config options
464 * @return {Ext.core.Element} The Element
466 switchOff: function(obj) {
470 obj = Ext.applyIf(obj || {}, {
477 beforeAnim = function() {
478 var animScope = this,
484 position = me.getPositioning();
486 keyframe = Ext.create('Ext.fx.Animator', {
488 duration: obj.duration,
496 y: xy[1] + size.height / 2
500 x: xy[0] + size.width / 2
504 keyframe.on('afteranimate', function() {
505 if (obj.useDisplay) {
506 me.setDisplayed(false);
511 me.setPositioning(position);
517 duration: (obj.duration * 2),
527 <span id='Ext-core-Element-method-frame'> /**
528 </span> * Shows a ripple of exploding, attenuating borders to draw attention to an Element.
530 <pre><code>
531 // default: a single light blue ripple
534 // custom: 3 red ripples lasting 3 seconds total
535 el.frame("#ff0000", 3, { duration: 3 });
537 // common config options shown with default values
538 el.frame("#C3DAF9", 1, {
539 duration: 1 //duration of each individual ripple.
540 // Note: Easing is not configurable and will be ignored if included
542 </code></pre>
543 * @param {String} color (optional) The color of the border. Should be a 6 char hex color without the leading # (defaults to light blue: 'C3DAF9').
544 * @param {Number} count (optional) The number of ripples to display (defaults to 1)
545 * @param {Object} options (optional) Object literal with any of the Fx config options
546 * @return {Ext.core.Element} The Element
548 frame : function(color, count, obj){
552 color = color || '#C3DAF9';
556 beforeAnim = function() {
558 var animScope = this,
560 proxy = Ext.getBody().createChild({
562 position : 'absolute',
563 'pointer-events': 'none',
565 border : '0px solid ' + color
569 proxyAnim = Ext.create('Ext.fx.Anim', {
571 duration: obj.duration || 1000,
586 height: box.height + 40,
587 width: box.width + 40
590 proxyAnim.on('afteranimate', function() {
597 duration: (obj.duration * 2) || 2000,
607 <span id='Ext-core-Element-method-ghost'> /**
608 </span> * Slides the element while fading it out of view. An anchor point can be optionally passed to set the
609 * ending point of the effect.
611 *<pre><code>
612 // default: slide the element downward while fading out
615 // custom: slide the element out to the right with a 2-second duration
616 el.ghost('r', { duration: 2 });
618 // common config options shown with default values
623 </code></pre>
624 * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to bottom: 'b')
625 * @param {Object} options (optional) Object literal with any of the Fx config options
626 * @return {Ext.core.Element} The Element
628 ghost: function(anchor, obj) {
632 anchor = anchor || "b";
633 beforeAnim = function() {
634 var width = me.getWidth(),
635 height = me.getHeight(),
637 position = me.getPositioning(),
643 to.y = xy[1] - height;
646 to.x = xy[0] - width;
649 to.x = xy[0] + width;
652 to.y = xy[1] + height;
655 to.x = xy[0] - width;
656 to.y = xy[1] - height;
659 to.x = xy[0] - width;
660 to.y = xy[1] + height;
663 to.x = xy[0] + width;
664 to.y = xy[1] + height;
667 to.x = xy[0] + width;
668 to.y = xy[1] - height;
672 this.on('afteranimate', function () {
676 me.setPositioning(position);
681 me.animate(Ext.applyIf(obj || {}, {
693 <span id='Ext-core-Element-method-highlight'> /**
694 </span> * Highlights the Element by setting a color (applies to the background-color by default, but can be
695 * changed using the "attr" config option) and then fading back to the original color. If no original
696 * color is available, you should provide the "endColor" config option which will be cleared after the animation.
698 <pre><code>
699 // default: highlight background to yellow
702 // custom: highlight foreground text to blue for 2 seconds
703 el.highlight("0000ff", { attr: 'color', duration: 2 });
705 // common config options shown with default values
706 el.highlight("ffff9c", {
707 attr: "backgroundColor", //can be any valid CSS property (attribute) that supports a color value
708 endColor: (current color) or "ffffff",
712 </code></pre>
713 * @param {String} color (optional) The highlight color. Should be a 6 char hex color without the leading # (defaults to yellow: 'ffff9c')
714 * @param {Object} options (optional) Object literal with any of the Fx config options
715 * @return {Ext.core.Element} The Element
717 highlight: function(color, o) {
721 restore, to, attr, lns, event, fn;
724 lns = o.listeners || {};
725 attr = o.attr || 'backgroundColor';
726 from[attr] = color || 'ffff9c';
730 to[attr] = o.endColor || me.getColor(attr, 'ffffff', '');
736 // Don't apply directly on lns, since we reference it in our own callbacks below
737 o.listeners = Ext.apply(Ext.apply({}, lns), {
738 beforeanimate: function() {
739 restore = dom.style[attr];
743 event = lns.beforeanimate;
745 fn = event.fn || event;
746 return fn.apply(event.scope || lns.scope || window, arguments);
749 afteranimate: function() {
751 dom.style[attr] = restore;
754 event = lns.afteranimate;
756 fn = event.fn || event;
757 fn.apply(event.scope || lns.scope || window, arguments);
762 me.animate(Ext.apply({}, o, {
771 <span id='Ext-core-Element-method-pause'> /**
772 </span> * @deprecated 4.0
773 * Creates a pause before any subsequent queued effects begin. If there are
774 * no effects queued after the pause it will have no effect.
776 <pre><code>
778 </code></pre>
779 * @param {Number} seconds The length of time to pause (in seconds)
780 * @return {Ext.Element} The Element
782 pause: function(ms) {
784 Ext.fx.Manager.setFxDefaults(me.id, {
790 <span id='Ext-core-Element-method-fadeIn'> /**
791 </span> * Fade an element in (from transparent to opaque). The ending opacity can be specified
792 * using the <tt>{@link #endOpacity}</tt> config option.
794 <pre><code>
795 // default: fade in from opacity 0 to 100%
798 // custom: fade in from opacity 0 to 75% over 2 seconds
799 el.fadeIn({ endOpacity: .75, duration: 2});
801 // common config options shown with default values
803 endOpacity: 1, //can be any value between 0 and 1 (e.g. .5)
807 </code></pre>
808 * @param {Object} options (optional) Object literal with any of the Fx config options
809 * @return {Ext.Element} The Element
811 fadeIn: function(o) {
812 this.animate(Ext.apply({}, o, {
818 <span id='Ext-core-Element-method-fadeOut'> /**
819 </span> * Fade an element out (from opaque to transparent). The ending opacity can be specified
820 * using the <tt>{@link #endOpacity}</tt> config option. Note that IE may require
821 * <tt>{@link #useDisplay}:true</tt> in order to redisplay correctly.
823 <pre><code>
824 // default: fade out from the element's current opacity to 0
827 // custom: fade out from the element's current opacity to 25% over 2 seconds
828 el.fadeOut({ endOpacity: .25, duration: 2});
830 // common config options shown with default values
832 endOpacity: 0, //can be any value between 0 and 1 (e.g. .5)
838 </code></pre>
839 * @param {Object} options (optional) Object literal with any of the Fx config options
840 * @return {Ext.Element} The Element
842 fadeOut: function(o) {
843 this.animate(Ext.apply({}, o, {
849 <span id='Ext-core-Element-method-scale'> /**
850 </span> * @deprecated 4.0
851 * Animates the transition of an element's dimensions from a starting height/width
852 * to an ending height/width. This method is a convenience implementation of {@link #shift}.
854 <pre><code>
855 // change height and width to 100x100 pixels
858 // common config options shown with default values. The height and width will default to
859 // the element&#39;s existing values if passed as null.
861 [element&#39;s width],
862 [element&#39;s height], {
867 </code></pre>
868 * @param {Number} width The new width (pass undefined to keep the original width)
869 * @param {Number} height The new height (pass undefined to keep the original height)
870 * @param {Object} options (optional) Object literal with any of the Fx config options
871 * @return {Ext.Element} The Element
873 scale: function(w, h, o) {
874 this.animate(Ext.apply({}, o, {
881 <span id='Ext-core-Element-method-shift'> /**
882 </span> * @deprecated 4.0
883 * Animates the transition of any combination of an element's dimensions, xy position and/or opacity.
884 * Any of these properties not specified in the config object will not be changed. This effect
885 * requires that at least one new dimension, position or opacity setting must be passed in on
886 * the config object in order for the function to have any effect.
888 <pre><code>
889 // slide the element horizontally to x position 200 while changing the height and opacity
890 el.shift({ x: 200, height: 50, opacity: .8 });
892 // common config options shown with default values.
894 width: [element&#39;s width],
895 height: [element&#39;s height],
896 x: [element&#39;s x position],
897 y: [element&#39;s y position],
898 opacity: [element&#39;s opacity],
902 </code></pre>
903 * @param {Object} options Object literal with any of the Fx config options
904 * @return {Ext.Element} The Element
906 shift: function(config) {
907 this.animate(config);