2 * @class Ext.core.Element
5 * Visibility mode constant for use with {@link #setVisibilityMode}. Use visibility to hide element
9 Ext.core.Element.VISIBILITY = 1;
11 * Visibility mode constant for use with {@link #setVisibilityMode}. Use display to hide element
15 Ext.core.Element.DISPLAY = 2;
18 * Visibility mode constant for use with {@link #setVisibilityMode}. Use offsets (x and y positioning offscreen)
23 Ext.core.Element.OFFSETS = 3;
26 Ext.core.Element.ASCLASS = 4;
29 * Defaults to 'x-hide-nosize'
33 Ext.core.Element.visibilityCls = Ext.baseCSSPrefix + 'hide-nosize';
35 Ext.core.Element.addMethods(function(){
36 var El = Ext.core.Element,
38 VISIBILITY = "visibility",
45 ORIGINALDISPLAY = 'originalDisplay',
46 VISMODE = 'visibilityMode',
47 ISVISIBLE = 'isVisible',
49 getDisplay = function(dom){
50 var d = data(dom, ORIGINALDISPLAY);
52 data(dom, ORIGINALDISPLAY, d = '');
56 getVisMode = function(dom){
57 var m = data(dom, VISMODE);
59 data(dom, VISMODE, m = 1);
66 * The element's default display mode (defaults to "")
73 * Sets the element's visibility mode. When setVisible() is called it
74 * will use this to determine whether to set the visibility or the display property.
75 * @param {Number} visMode Ext.core.Element.VISIBILITY or Ext.core.Element.DISPLAY
76 * @return {Ext.core.Element} this
78 setVisibilityMode : function(visMode){
79 data(this.dom, VISMODE, visMode);
84 * Checks whether the element is currently visible using both visibility and display properties.
85 * @return {Boolean} True if the element is currently visible, else false
87 isVisible : function() {
90 visible = data(dom, ISVISIBLE);
92 if(typeof visible == 'boolean'){ //return the cached value if registered
95 //Determine the current state based on display states
96 visible = !me.isStyle(VISIBILITY, HIDDEN) &&
97 !me.isStyle(DISPLAY, NONE) &&
98 !((getVisMode(dom) == El.ASCLASS) && me.hasCls(me.visibilityCls || El.visibilityCls));
100 data(dom, ISVISIBLE, visible);
105 * Sets the visibility of the element (see details). If the visibilityMode is set to Element.DISPLAY, it will use
106 * the display property to hide the element, otherwise it uses visibility. The default is to hide and show using the visibility property.
107 * @param {Boolean} visible Whether the element is visible
108 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
109 * @return {Ext.core.Element} this
111 setVisible : function(visible, animate){
112 var me = this, isDisplay, isVisibility, isOffsets, isNosize,
114 visMode = getVisMode(dom);
117 // hideMode string override
118 if (typeof animate == 'string'){
121 visMode = El.DISPLAY;
124 visMode = El.VISIBILITY;
127 visMode = El.OFFSETS;
131 visMode = El.ASCLASS;
134 me.setVisibilityMode(visMode);
138 if (!animate || !me.anim) {
139 if(visMode == El.ASCLASS ){
141 me[visible?'removeCls':'addCls'](me.visibilityCls || El.visibilityCls);
143 } else if (visMode == El.DISPLAY){
145 return me.setDisplayed(visible);
147 } else if (visMode == El.OFFSETS){
150 // Remember position for restoring, if we are not already hidden by offsets.
151 if (!me.hideModeStyles) {
152 me.hideModeStyles = {
153 position: me.getStyle('position'),
154 top: me.getStyle('top'),
155 left: me.getStyle('left')
158 me.applyStyles({position: 'absolute', top: '-10000px', left: '-10000px'});
161 // Only "restore" as position if we have actually been hidden using offsets.
162 // Calling setVisible(true) on a positioned element should not reposition it.
163 else if (me.hideModeStyles) {
164 me.applyStyles(me.hideModeStyles || {position: '', top: '', left: ''});
165 delete me.hideModeStyles;
170 // Show by clearing visibility style. Explicitly setting to "visible" overrides parent visibility setting.
171 dom.style.visibility = visible ? '' : HIDDEN;
174 // closure for composites
179 if (!Ext.isObject(animate)) {
185 me.animate(Ext.applyIf({
186 callback: function() {
187 visible || me.setVisible(false).setOpacity(1);
190 opacity: (visible) ? 1 : 0
194 data(dom, ISVISIBLE, visible); //set logical visibility state
201 * Determine if the Element has a relevant height and width available based
202 * upon current logical visibility state
204 hasMetrics : function(){
206 return this.isVisible() || (getVisMode(dom) == El.OFFSETS) || (getVisMode(dom) == El.VISIBILITY);
210 * Toggles the element's visibility or display, depending on visibility mode.
211 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
212 * @return {Ext.core.Element} this
214 toggle : function(animate){
216 me.setVisible(!me.isVisible(), me.anim(animate));
221 * Sets the CSS display property. Uses originalDisplay if the specified value is a boolean true.
222 * @param {Mixed} value Boolean value to display the element using its default display, or a string to set the display directly.
223 * @return {Ext.core.Element} this
225 setDisplayed : function(value) {
226 if(typeof value == "boolean"){
227 value = value ? getDisplay(this.dom) : NONE;
229 this.setStyle(DISPLAY, value);
234 fixDisplay : function(){
236 if (me.isStyle(DISPLAY, NONE)) {
237 me.setStyle(VISIBILITY, HIDDEN);
238 me.setStyle(DISPLAY, getDisplay(this.dom)); // first try reverting to default
239 if (me.isStyle(DISPLAY, NONE)) { // if that fails, default to block
240 me.setStyle(DISPLAY, "block");
246 * Hide this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}.
247 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
248 * @return {Ext.core.Element} this
250 hide : function(animate){
252 if (typeof animate == 'string'){
253 this.setVisible(false, animate);
256 this.setVisible(false, this.anim(animate));
261 * Show this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}.
262 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
263 * @return {Ext.core.Element} this
265 show : function(animate){
267 if (typeof animate == 'string'){
268 this.setVisible(true, animate);
271 this.setVisible(true, this.anim(animate));