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 <span id='Ext-core-Element-property-VISIBILITY'>/**
22 </span> * Visibility mode constant for use with {@link #setVisibilityMode}. Use visibility to hide element
26 Ext.core.Element.VISIBILITY = 1;
27 <span id='Ext-core-Element-property-DISPLAY'>/**
28 </span> * Visibility mode constant for use with {@link #setVisibilityMode}. Use display to hide element
32 Ext.core.Element.DISPLAY = 2;
34 <span id='Ext-core-Element-property-OFFSETS'>/**
35 </span> * Visibility mode constant for use with {@link #setVisibilityMode}. Use offsets (x and y positioning offscreen)
40 Ext.core.Element.OFFSETS = 3;
43 Ext.core.Element.ASCLASS = 4;
45 <span id='Ext-core-Element-property-visibilityCls'>/**
46 </span> * Defaults to 'x-hide-nosize'
50 Ext.core.Element.visibilityCls = Ext.baseCSSPrefix + 'hide-nosize';
52 Ext.core.Element.addMethods(function(){
53 var El = Ext.core.Element,
54 OPACITY = "opacity",
55 VISIBILITY = "visibility",
56 DISPLAY = "display",
57 HIDDEN = "hidden",
58 OFFSETS = "offsets",
59 ASCLASS = "asclass",
60 NONE = "none",
62 ORIGINALDISPLAY = 'originalDisplay',
63 VISMODE = 'visibilityMode',
64 ISVISIBLE = 'isVisible',
66 getDisplay = function(dom){
67 var d = data(dom, ORIGINALDISPLAY);
69 data(dom, ORIGINALDISPLAY, d = '');
73 getVisMode = function(dom){
74 var m = data(dom, VISMODE);
76 data(dom, VISMODE, m = 1);
82 <span id='Ext-core-Element-property-originalDisplay'> /**
83 </span> * The element's default display mode (defaults to "")
86 originalDisplay : "",
89 <span id='Ext-core-Element-method-setVisibilityMode'> /**
90 </span> * Sets the element's visibility mode. When setVisible() is called it
91 * will use this to determine whether to set the visibility or the display property.
92 * @param {Number} visMode Ext.core.Element.VISIBILITY or Ext.core.Element.DISPLAY
93 * @return {Ext.core.Element} this
95 setVisibilityMode : function(visMode){
96 data(this.dom, VISMODE, visMode);
100 <span id='Ext-core-Element-method-isVisible'> /**
101 </span> * Checks whether the element is currently visible using both visibility and display properties.
102 * @return {Boolean} True if the element is currently visible, else false
104 isVisible : function() {
107 visible = data(dom, ISVISIBLE);
109 if(typeof visible == 'boolean'){ //return the cached value if registered
112 //Determine the current state based on display states
113 visible = !me.isStyle(VISIBILITY, HIDDEN) &&
114 !me.isStyle(DISPLAY, NONE) &&
115 !((getVisMode(dom) == El.ASCLASS) && me.hasCls(me.visibilityCls || El.visibilityCls));
117 data(dom, ISVISIBLE, visible);
121 <span id='Ext-core-Element-method-setVisible'> /**
122 </span> * Sets the visibility of the element (see details). If the visibilityMode is set to Element.DISPLAY, it will use
123 * the display property to hide the element, otherwise it uses visibility. The default is to hide and show using the visibility property.
124 * @param {Boolean} visible Whether the element is visible
125 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
126 * @return {Ext.core.Element} this
128 setVisible : function(visible, animate){
129 var me = this, isDisplay, isVisibility, isOffsets, isNosize,
131 visMode = getVisMode(dom);
134 // hideMode string override
135 if (typeof animate == 'string'){
138 visMode = El.DISPLAY;
141 visMode = El.VISIBILITY;
144 visMode = El.OFFSETS;
148 visMode = El.ASCLASS;
151 me.setVisibilityMode(visMode);
155 if (!animate || !me.anim) {
156 if(visMode == El.ASCLASS ){
158 me[visible?'removeCls':'addCls'](me.visibilityCls || El.visibilityCls);
160 } else if (visMode == El.DISPLAY){
162 return me.setDisplayed(visible);
164 } else if (visMode == El.OFFSETS){
167 // Remember position for restoring, if we are not already hidden by offsets.
168 if (!me.hideModeStyles) {
169 me.hideModeStyles = {
170 position: me.getStyle('position'),
171 top: me.getStyle('top'),
172 left: me.getStyle('left')
175 me.applyStyles({position: 'absolute', top: '-10000px', left: '-10000px'});
178 // Only "restore" as position if we have actually been hidden using offsets.
179 // Calling setVisible(true) on a positioned element should not reposition it.
180 else if (me.hideModeStyles) {
181 me.applyStyles(me.hideModeStyles || {position: '', top: '', left: ''});
182 delete me.hideModeStyles;
187 // Show by clearing visibility style. Explicitly setting to "visible" overrides parent visibility setting.
188 dom.style.visibility = visible ? '' : HIDDEN;
191 // closure for composites
196 if (!Ext.isObject(animate)) {
202 me.animate(Ext.applyIf({
203 callback: function() {
204 visible || me.setVisible(false).setOpacity(1);
207 opacity: (visible) ? 1 : 0
211 data(dom, ISVISIBLE, visible); //set logical visibility state
216 <span id='Ext-core-Element-method-hasMetrics'> /**
218 * Determine if the Element has a relevant height and width available based
219 * upon current logical visibility state
221 hasMetrics : function(){
223 return this.isVisible() || (getVisMode(dom) == El.OFFSETS) || (getVisMode(dom) == El.VISIBILITY);
226 <span id='Ext-core-Element-method-toggle'> /**
227 </span> * Toggles the element's visibility or display, depending on visibility mode.
228 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
229 * @return {Ext.core.Element} this
231 toggle : function(animate){
233 me.setVisible(!me.isVisible(), me.anim(animate));
237 <span id='Ext-core-Element-method-setDisplayed'> /**
238 </span> * Sets the CSS display property. Uses originalDisplay if the specified value is a boolean true.
239 * @param {Mixed} value Boolean value to display the element using its default display, or a string to set the display directly.
240 * @return {Ext.core.Element} this
242 setDisplayed : function(value) {
243 if(typeof value == "boolean"){
244 value = value ? getDisplay(this.dom) : NONE;
246 this.setStyle(DISPLAY, value);
251 fixDisplay : function(){
253 if (me.isStyle(DISPLAY, NONE)) {
254 me.setStyle(VISIBILITY, HIDDEN);
255 me.setStyle(DISPLAY, getDisplay(this.dom)); // first try reverting to default
256 if (me.isStyle(DISPLAY, NONE)) { // if that fails, default to block
257 me.setStyle(DISPLAY, "block");
262 <span id='Ext-core-Element-method-hide'> /**
263 </span> * Hide this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}.
264 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
265 * @return {Ext.core.Element} this
267 hide : function(animate){
269 if (typeof animate == 'string'){
270 this.setVisible(false, animate);
273 this.setVisible(false, this.anim(animate));
277 <span id='Ext-core-Element-method-show'> /**
278 </span> * Show this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}.
279 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
280 * @return {Ext.core.Element} this
282 show : function(animate){
284 if (typeof animate == 'string'){
285 this.setVisible(true, animate);
288 this.setVisible(true, this.anim(animate));