3 * Copyright(c) 2006-2010 Ext JS, Inc.
5 * http://www.extjs.com/license
11 * Visibility mode constant for use with {@link #setVisibilityMode}. Use visibility to hide element
15 Ext.Element.VISIBILITY = 1;
17 * Visibility mode constant for use with {@link #setVisibilityMode}. Use display to hide element
21 Ext.Element.DISPLAY = 2;
23 Ext.Element.addMethods(function(){
24 var VISIBILITY = "visibility",
29 ORIGINALDISPLAY = 'originalDisplay',
30 VISMODE = 'visibilityMode',
31 ELDISPLAY = Ext.Element.DISPLAY,
32 data = Ext.Element.data,
33 getDisplay = function(dom){
34 var d = data(dom, ORIGINALDISPLAY);
36 data(dom, ORIGINALDISPLAY, d = '');
40 getVisMode = function(dom){
41 var m = data(dom, VISMODE);
43 data(dom, VISMODE, m = 1);
50 * The element's default display mode (defaults to "")
57 * Sets the element's visibility mode. When setVisible() is called it
58 * will use this to determine whether to set the visibility or the display property.
59 * @param {Number} visMode Ext.Element.VISIBILITY or Ext.Element.DISPLAY
60 * @return {Ext.Element} this
62 setVisibilityMode : function(visMode){
63 data(this.dom, VISMODE, visMode);
68 * Perform custom animation on this element.
69 * <div><ul class="mdetail-params">
70 * <li><u>Animation Properties</u></li>
72 * <p>The Animation Control Object enables gradual transitions for any member of an
73 * element's style object that takes a numeric value including but not limited to
74 * these properties:</p><div><ul class="mdetail-params">
75 * <li><tt>bottom, top, left, right</tt></li>
76 * <li><tt>height, width</tt></li>
77 * <li><tt>margin, padding</tt></li>
78 * <li><tt>borderWidth</tt></li>
79 * <li><tt>opacity</tt></li>
80 * <li><tt>fontSize</tt></li>
81 * <li><tt>lineHeight</tt></li>
85 * <li><u>Animation Property Attributes</u></li>
87 * <p>Each Animation Property is a config object with optional properties:</p>
88 * <div><ul class="mdetail-params">
89 * <li><tt>by</tt>* : relative change - start at current value, change by this value</li>
90 * <li><tt>from</tt> : ignore current value, start from this value</li>
91 * <li><tt>to</tt>* : start at current value, go to this value</li>
92 * <li><tt>unit</tt> : any allowable unit specification</li>
93 * <p>* do not specify both <tt>to</tt> and <tt>by</tt> for an animation property</p>
96 * <li><u>Animation Types</u></li>
98 * <p>The supported animation types:</p><div><ul class="mdetail-params">
99 * <li><tt>'run'</tt> : Default
101 var el = Ext.get('complexEl');
103 // animation control object
105 borderWidth: {to: 3, from: 0},
106 opacity: {to: .3, from: 1},
107 height: {to: 50, from: el.getHeight()},
108 width: {to: 300, from: el.getWidth()},
109 top : {by: - 100, unit: 'px'},
111 0.35, // animation duration
113 'easeOut', // easing method
114 'run' // animation type ('run','color','motion','scroll')
118 * <li><tt>'color'</tt>
119 * <p>Animates transition of background, text, or border colors.</p>
122 // animation control object
124 color: { to: '#06e' },
125 backgroundColor: { to: '#e06' }
127 0.35, // animation duration
129 'easeOut', // easing method
130 'color' // animation type ('run','color','motion','scroll')
135 * <li><tt>'motion'</tt>
136 * <p>Animates the motion of an element to/from specific points using optional bezier
137 * way points during transit.</p>
140 // animation control object
142 borderWidth: {to: 3, from: 0},
143 opacity: {to: .3, from: 1},
144 height: {to: 50, from: el.getHeight()},
145 width: {to: 300, from: el.getWidth()},
146 top : {by: - 100, unit: 'px'},
148 to: [50, 100], // go to this point
149 control: [ // optional bezier way points
155 3000, // animation duration (milliseconds!)
157 'easeOut', // easing method
158 'motion' // animation type ('run','color','motion','scroll')
162 * <li><tt>'scroll'</tt>
163 * <p>Animate horizontal or vertical scrolling of an overflowing page element.</p>
166 // animation control object
168 scroll: {to: [400, 300]}
170 0.35, // animation duration
172 'easeOut', // easing method
173 'scroll' // animation type ('run','color','motion','scroll')
181 * @param {Object} args The animation control args
182 * @param {Float} duration (optional) How long the animation lasts in seconds (defaults to <tt>.35</tt>)
183 * @param {Function} onComplete (optional) Function to call when animation completes
184 * @param {String} easing (optional) {@link Ext.Fx#easing} method to use (defaults to <tt>'easeOut'</tt>)
185 * @param {String} animType (optional) <tt>'run'</tt> is the default. Can also be <tt>'color'</tt>,
186 * <tt>'motion'</tt>, or <tt>'scroll'</tt>
187 * @return {Ext.Element} this
189 animate : function(args, duration, onComplete, easing, animType){
190 this.anim(args, {duration: duration, callback: onComplete, easing: easing}, animType);
195 * @private Internal animation call
197 anim : function(args, opt, animType, defaultDur, defaultEase, cb){
198 animType = animType || 'run';
201 anim = Ext.lib.Anim[animType](
204 (opt.duration || defaultDur) || .35,
205 (opt.easing || defaultEase) || 'easeOut',
208 if(opt.callback) opt.callback.call(opt.scope || me, me, opt);
216 // private legacy anim prep
217 preanim : function(a, i){
218 return !a[i] ? false : (Ext.isObject(a[i]) ? a[i]: {duration: a[i+1], callback: a[i+2], easing: a[i+3]});
222 * Checks whether the element is currently visible using both visibility and display properties.
223 * @return {Boolean} True if the element is currently visible, else false
225 isVisible : function() {
226 return !this.isStyle(VISIBILITY, HIDDEN) && !this.isStyle(DISPLAY, NONE);
230 * Sets the visibility of the element (see details). If the visibilityMode is set to Element.DISPLAY, it will use
231 * the display property to hide the element, otherwise it uses visibility. The default is to hide and show using the visibility property.
232 * @param {Boolean} visible Whether the element is visible
233 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
234 * @return {Ext.Element} this
236 setVisible : function(visible, animate){
237 var me = this, isDisplay, isVisible, isOffsets,
240 // hideMode string override
241 if (Ext.isString(animate)){
242 isDisplay = animate == DISPLAY;
243 isVisible = animate == VISIBILITY;
244 isOffsets = animate == OFFSETS;
247 isDisplay = getVisMode(this.dom) == ELDISPLAY;
248 isVisible = !isDisplay;
251 if (!animate || !me.anim) {
253 me.setDisplayed(visible);
254 } else if (isOffsets){
256 me.hideModeStyles = {
257 position: me.getStyle('position'),
258 top: me.getStyle('top'),
259 left: me.getStyle('left')
262 me.applyStyles({position: 'absolute', top: '-10000px', left: '-10000px'});
264 me.applyStyles(me.hideModeStyles || {position: '', top: '', left: ''});
268 dom.style.visibility = visible ? "visible" : HIDDEN;
271 // closure for composites
276 me.anim({opacity: { to: (visible?1:0) }},
277 me.preanim(arguments, 1),
283 dom.style[isDisplay ? DISPLAY : VISIBILITY] = (isDisplay) ? NONE : HIDDEN;
284 Ext.fly(dom).setOpacity(1);
292 * Toggles the element's visibility or display, depending on visibility mode.
293 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
294 * @return {Ext.Element} this
296 toggle : function(animate){
298 me.setVisible(!me.isVisible(), me.preanim(arguments, 0));
303 * Sets the CSS display property. Uses originalDisplay if the specified value is a boolean true.
304 * @param {Mixed} value Boolean value to display the element using its default display, or a string to set the display directly.
305 * @return {Ext.Element} this
307 setDisplayed : function(value) {
308 if(typeof value == "boolean"){
309 value = value ? getDisplay(this.dom) : NONE;
311 this.setStyle(DISPLAY, value);
316 fixDisplay : function(){
318 if(me.isStyle(DISPLAY, NONE)){
319 me.setStyle(VISIBILITY, HIDDEN);
320 me.setStyle(DISPLAY, getDisplay(this.dom)); // first try reverting to default
321 if(me.isStyle(DISPLAY, NONE)){ // if that fails, default to block
322 me.setStyle(DISPLAY, "block");
328 * Hide this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}.
329 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
330 * @return {Ext.Element} this
332 hide : function(animate){
334 if (Ext.isString(animate)){
335 this.setVisible(false, animate);
338 this.setVisible(false, this.preanim(arguments, 0));
343 * Show this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}.
344 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
345 * @return {Ext.Element} this
347 show : function(animate){
349 if (Ext.isString(animate)){
350 this.setVisible(true, animate);
353 this.setVisible(true, this.preanim(arguments, 0));