3 * Copyright(c) 2006-2010 Sencha Inc.
5 * http://www.sencha.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;
24 * Visibility mode constant for use with {@link #setVisibilityMode}. Use offsets (x and y positioning offscreen)
29 Ext.Element.OFFSETS = 3;
32 Ext.Element.ASCLASS = 4;
35 * Defaults to 'x-hide-nosize'
39 Ext.Element.visibilityCls = 'x-hide-nosize';
41 Ext.Element.addMethods(function(){
44 VISIBILITY = "visibility",
51 ORIGINALDISPLAY = 'originalDisplay',
52 VISMODE = 'visibilityMode',
53 ISVISIBLE = 'isVisible',
55 getDisplay = function(dom){
56 var d = data(dom, ORIGINALDISPLAY);
58 data(dom, ORIGINALDISPLAY, d = '');
62 getVisMode = function(dom){
63 var m = data(dom, VISMODE);
65 data(dom, VISMODE, m = 1);
72 * The element's default display mode (defaults to "")
79 * Sets the element's visibility mode. When setVisible() is called it
80 * will use this to determine whether to set the visibility or the display property.
81 * @param {Number} visMode Ext.Element.VISIBILITY or Ext.Element.DISPLAY
82 * @return {Ext.Element} this
84 setVisibilityMode : function(visMode){
85 data(this.dom, VISMODE, visMode);
90 * Perform custom animation on this element.
91 * <div><ul class="mdetail-params">
92 * <li><u>Animation Properties</u></li>
94 * <p>The Animation Control Object enables gradual transitions for any member of an
95 * element's style object that takes a numeric value including but not limited to
96 * these properties:</p><div><ul class="mdetail-params">
97 * <li><tt>bottom, top, left, right</tt></li>
98 * <li><tt>height, width</tt></li>
99 * <li><tt>margin, padding</tt></li>
100 * <li><tt>borderWidth</tt></li>
101 * <li><tt>opacity</tt></li>
102 * <li><tt>fontSize</tt></li>
103 * <li><tt>lineHeight</tt></li>
107 * <li><u>Animation Property Attributes</u></li>
109 * <p>Each Animation Property is a config object with optional properties:</p>
110 * <div><ul class="mdetail-params">
111 * <li><tt>by</tt>* : relative change - start at current value, change by this value</li>
112 * <li><tt>from</tt> : ignore current value, start from this value</li>
113 * <li><tt>to</tt>* : start at current value, go to this value</li>
114 * <li><tt>unit</tt> : any allowable unit specification</li>
115 * <p>* do not specify both <tt>to</tt> and <tt>by</tt> for an animation property</p>
118 * <li><u>Animation Types</u></li>
120 * <p>The supported animation types:</p><div><ul class="mdetail-params">
121 * <li><tt>'run'</tt> : Default
123 var el = Ext.get('complexEl');
125 // animation control object
127 borderWidth: {to: 3, from: 0},
128 opacity: {to: .3, from: 1},
129 height: {to: 50, from: el.getHeight()},
130 width: {to: 300, from: el.getWidth()},
131 top : {by: - 100, unit: 'px'},
133 0.35, // animation duration
135 'easeOut', // easing method
136 'run' // animation type ('run','color','motion','scroll')
140 * <li><tt>'color'</tt>
141 * <p>Animates transition of background, text, or border colors.</p>
144 // animation control object
146 color: { to: '#06e' },
147 backgroundColor: { to: '#e06' }
149 0.35, // animation duration
151 'easeOut', // easing method
152 'color' // animation type ('run','color','motion','scroll')
157 * <li><tt>'motion'</tt>
158 * <p>Animates the motion of an element to/from specific points using optional bezier
159 * way points during transit.</p>
162 // animation control object
164 borderWidth: {to: 3, from: 0},
165 opacity: {to: .3, from: 1},
166 height: {to: 50, from: el.getHeight()},
167 width: {to: 300, from: el.getWidth()},
168 top : {by: - 100, unit: 'px'},
170 to: [50, 100], // go to this point
171 control: [ // optional bezier way points
177 3000, // animation duration (milliseconds!)
179 'easeOut', // easing method
180 'motion' // animation type ('run','color','motion','scroll')
184 * <li><tt>'scroll'</tt>
185 * <p>Animate horizontal or vertical scrolling of an overflowing page element.</p>
188 // animation control object
190 scroll: {to: [400, 300]}
192 0.35, // animation duration
194 'easeOut', // easing method
195 'scroll' // animation type ('run','color','motion','scroll')
203 * @param {Object} args The animation control args
204 * @param {Float} duration (optional) How long the animation lasts in seconds (defaults to <tt>.35</tt>)
205 * @param {Function} onComplete (optional) Function to call when animation completes
206 * @param {String} easing (optional) {@link Ext.Fx#easing} method to use (defaults to <tt>'easeOut'</tt>)
207 * @param {String} animType (optional) <tt>'run'</tt> is the default. Can also be <tt>'color'</tt>,
208 * <tt>'motion'</tt>, or <tt>'scroll'</tt>
209 * @return {Ext.Element} this
211 animate : function(args, duration, onComplete, easing, animType){
212 this.anim(args, {duration: duration, callback: onComplete, easing: easing}, animType);
217 * @private Internal animation call
219 anim : function(args, opt, animType, defaultDur, defaultEase, cb){
220 animType = animType || 'run';
223 anim = Ext.lib.Anim[animType](
226 (opt.duration || defaultDur) || .35,
227 (opt.easing || defaultEase) || 'easeOut',
230 if(opt.callback) opt.callback.call(opt.scope || me, me, opt);
238 // private legacy anim prep
239 preanim : function(a, i){
240 return !a[i] ? false : (typeof a[i] == 'object' ? a[i]: {duration: a[i+1], callback: a[i+2], easing: a[i+3]});
244 * Checks whether the element is currently visible using both visibility and display properties.
245 * @return {Boolean} True if the element is currently visible, else false
247 isVisible : function() {
250 visible = data(dom, ISVISIBLE);
252 if(typeof visible == 'boolean'){ //return the cached value if registered
255 //Determine the current state based on display states
256 visible = !me.isStyle(VISIBILITY, HIDDEN) &&
257 !me.isStyle(DISPLAY, NONE) &&
258 !((getVisMode(dom) == El.ASCLASS) && me.hasClass(me.visibilityCls || El.visibilityCls));
260 data(dom, ISVISIBLE, visible);
265 * Sets the visibility of the element (see details). If the visibilityMode is set to Element.DISPLAY, it will use
266 * the display property to hide the element, otherwise it uses visibility. The default is to hide and show using the visibility property.
267 * @param {Boolean} visible Whether the element is visible
268 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
269 * @return {Ext.Element} this
271 setVisible : function(visible, animate){
272 var me = this, isDisplay, isVisibility, isOffsets, isNosize,
274 visMode = getVisMode(dom);
277 // hideMode string override
278 if (typeof animate == 'string'){
281 visMode = El.DISPLAY;
284 visMode = El.VISIBILITY;
287 visMode = El.OFFSETS;
291 visMode = El.ASCLASS;
294 me.setVisibilityMode(visMode);
298 if (!animate || !me.anim) {
299 if(visMode == El.ASCLASS ){
301 me[visible?'removeClass':'addClass'](me.visibilityCls || El.visibilityCls);
303 } else if (visMode == El.DISPLAY){
305 return me.setDisplayed(visible);
307 } else if (visMode == El.OFFSETS){
310 me.hideModeStyles = {
311 position: me.getStyle('position'),
312 top: me.getStyle('top'),
313 left: me.getStyle('left')
315 me.applyStyles({position: 'absolute', top: '-10000px', left: '-10000px'});
317 me.applyStyles(me.hideModeStyles || {position: '', top: '', left: ''});
318 delete me.hideModeStyles;
323 dom.style.visibility = visible ? "visible" : HIDDEN;
326 // closure for composites
331 me.anim({opacity: { to: (visible?1:0) }},
332 me.preanim(arguments, 1),
337 visible || me.setVisible(false).setOpacity(1);
340 data(dom, ISVISIBLE, visible); //set logical visibility state
347 * Determine if the Element has a relevant height and width available based
348 * upon current logical visibility state
350 hasMetrics : function(){
352 return this.isVisible() || (getVisMode(dom) == El.VISIBILITY);
356 * Toggles the element's visibility or display, depending on visibility mode.
357 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
358 * @return {Ext.Element} this
360 toggle : function(animate){
362 me.setVisible(!me.isVisible(), me.preanim(arguments, 0));
367 * Sets the CSS display property. Uses originalDisplay if the specified value is a boolean true.
368 * @param {Mixed} value Boolean value to display the element using its default display, or a string to set the display directly.
369 * @return {Ext.Element} this
371 setDisplayed : function(value) {
372 if(typeof value == "boolean"){
373 value = value ? getDisplay(this.dom) : NONE;
375 this.setStyle(DISPLAY, value);
380 fixDisplay : function(){
382 if(me.isStyle(DISPLAY, NONE)){
383 me.setStyle(VISIBILITY, HIDDEN);
384 me.setStyle(DISPLAY, getDisplay(this.dom)); // first try reverting to default
385 if(me.isStyle(DISPLAY, NONE)){ // if that fails, default to block
386 me.setStyle(DISPLAY, "block");
392 * Hide this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}.
393 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
394 * @return {Ext.Element} this
396 hide : function(animate){
398 if (typeof animate == 'string'){
399 this.setVisible(false, animate);
402 this.setVisible(false, this.preanim(arguments, 0));
407 * Show this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}.
408 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
409 * @return {Ext.Element} this
411 show : function(animate){
413 if (typeof animate == 'string'){
414 this.setVisible(true, animate);
417 this.setVisible(true, this.preanim(arguments, 0));