Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / docs / source / Element.fx-more.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5   <title>The source code</title>
6   <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7   <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8   <style type="text/css">
9     .highlight { display: block; background-color: #ddd; }
10   </style>
11   <script type="text/javascript">
12     function highlight() {
13       document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
14     }
15   </script>
16 </head>
17 <body onload="prettyPrint(); highlight();">
18   <pre class="prettyprint lang-js"><span id='Ext-Element'>/**
19 </span> * @class Ext.Element
20  */
21 Ext.Element.addMethods(
22     function() {
23         var VISIBILITY      = &quot;visibility&quot;,
24             DISPLAY         = &quot;display&quot;,
25             HIDDEN          = &quot;hidden&quot;,
26             NONE            = &quot;none&quot;,
27             XMASKED         = Ext.baseCSSPrefix + &quot;masked&quot;,
28             XMASKEDRELATIVE = Ext.baseCSSPrefix + &quot;masked-relative&quot;,
29             data            = Ext.Element.data;
30
31         return {
32 <span id='Ext-Element-method-isVisible'>            /**
33 </span>             * Checks whether the element is currently visible using both visibility and display properties.
34              * @param {Boolean} [deep=false] True to walk the dom and see if parent elements are hidden
35              * @return {Boolean} True if the element is currently visible, else false
36              */
37             isVisible : function(deep) {
38                 var vis = !this.isStyle(VISIBILITY, HIDDEN) &amp;&amp; !this.isStyle(DISPLAY, NONE),
39                     p   = this.dom.parentNode;
40
41                 if (deep !== true || !vis) {
42                     return vis;
43                 }
44
45                 while (p &amp;&amp; !(/^body/i.test(p.tagName))) {
46                     if (!Ext.fly(p, '_isVisible').isVisible()) {
47                         return false;
48                     }
49                     p = p.parentNode;
50                 }
51                 return true;
52             },
53
54 <span id='Ext-Element-method-isDisplayed'>            /**
55 </span>             * Returns true if display is not &quot;none&quot;
56              * @return {Boolean}
57              */
58             isDisplayed : function() {
59                 return !this.isStyle(DISPLAY, NONE);
60             },
61
62 <span id='Ext-Element-method-enableDisplayMode'>            /**
63 </span>             * Convenience method for setVisibilityMode(Element.DISPLAY)
64              * @param {String} display (optional) What to set display to when visible
65              * @return {Ext.Element} this
66              */
67             enableDisplayMode : function(display) {
68                 this.setVisibilityMode(Ext.Element.DISPLAY);
69
70                 if (!Ext.isEmpty(display)) {
71                     data(this.dom, 'originalDisplay', display);
72                 }
73
74                 return this;
75             },
76
77 <span id='Ext-Element-method-mask'>            /**
78 </span>             * Puts a mask over this element to disable user interaction. Requires core.css.
79              * This method can only be applied to elements which accept child nodes.
80              * @param {String} msg (optional) A message to display in the mask
81              * @param {String} msgCls (optional) A css class to apply to the msg element
82              * @return {Ext.Element} The mask element
83              */
84             mask : function(msg, msgCls) {
85                 var me  = this,
86                     dom = me.dom,
87                     setExpression = dom.style.setExpression,
88                     dh  = Ext.DomHelper,
89                     EXTELMASKMSG = Ext.baseCSSPrefix + &quot;mask-msg&quot;,
90                     el,
91                     mask;
92
93                 if (!(/^body/i.test(dom.tagName) &amp;&amp; me.getStyle('position') == 'static')) {
94                     me.addCls(XMASKEDRELATIVE);
95                 }
96                 el = data(dom, 'maskMsg');
97                 if (el) {
98                     el.remove();
99                 }
100                 el = data(dom, 'mask');
101                 if (el) {
102                     el.remove();
103                 }
104
105                 mask = dh.append(dom, {cls : Ext.baseCSSPrefix + &quot;mask&quot;}, true);
106                 data(dom, 'mask', mask);
107
108                 me.addCls(XMASKED);
109                 mask.setDisplayed(true);
110
111                 if (typeof msg == 'string') {
112                     var mm = dh.append(dom, {cls : EXTELMASKMSG, cn:{tag:'div'}}, true);
113                     data(dom, 'maskMsg', mm);
114                     mm.dom.className = msgCls ? EXTELMASKMSG + &quot; &quot; + msgCls : EXTELMASKMSG;
115                     mm.dom.firstChild.innerHTML = msg;
116                     mm.setDisplayed(true);
117                     mm.center(me);
118                 }
119                 // NOTE: CSS expressions are resource intensive and to be used only as a last resort
120                 // These expressions are removed as soon as they are no longer necessary - in the unmask method.
121                 // In normal use cases an element will be masked for a limited period of time.
122                 // Fix for https://sencha.jira.com/browse/EXTJSIV-19.
123                 // IE6 strict mode and IE6-9 quirks mode takes off left+right padding when calculating width!
124                 if (!Ext.supports.IncludePaddingInWidthCalculation &amp;&amp; setExpression) {
125                     mask.dom.style.setExpression('width', 'this.parentNode.offsetWidth + &quot;px&quot;');
126                 }
127
128                 // Some versions and modes of IE subtract top+bottom padding when calculating height.
129                 // Different versions from those which make the same error for width!
130                 if (!Ext.supports.IncludePaddingInHeightCalculation &amp;&amp; setExpression) {
131                     mask.dom.style.setExpression('height', 'this.parentNode.offsetHeight + &quot;px&quot;');
132                 }
133                 // ie will not expand full height automatically
134                 else if (Ext.isIE &amp;&amp; !(Ext.isIE7 &amp;&amp; Ext.isStrict) &amp;&amp; me.getStyle('height') == 'auto') {
135                     mask.setSize(undefined, me.getHeight());
136                 }
137                 return mask;
138             },
139
140 <span id='Ext-Element-method-unmask'>            /**
141 </span>             * Removes a previously applied mask.
142              */
143             unmask : function() {
144                 var me      = this,
145                     dom     = me.dom,
146                     mask    = data(dom, 'mask'),
147                     maskMsg = data(dom, 'maskMsg');
148
149                 if (mask) {
150                     // Remove resource-intensive CSS expressions as soon as they are not required.
151                     if (mask.dom.style.clearExpression) {
152                         mask.dom.style.clearExpression('width');
153                         mask.dom.style.clearExpression('height');
154                     }
155                     if (maskMsg) {
156                         maskMsg.remove();
157                         data(dom, 'maskMsg', undefined);
158                     }
159
160                     mask.remove();
161                     data(dom, 'mask', undefined);
162                     me.removeCls([XMASKED, XMASKEDRELATIVE]);
163                 }
164             },
165 <span id='Ext-Element-method-isMasked'>            /**
166 </span>             * Returns true if this element is masked. Also re-centers any displayed message within the mask.
167              * @return {Boolean}
168              */
169             isMasked : function() {
170                 var me = this,
171                     mask = data(me.dom, 'mask'),
172                     maskMsg = data(me.dom, 'maskMsg');
173
174                 if (mask &amp;&amp; mask.isVisible()) {
175                     if (maskMsg) {
176                         maskMsg.center(me);
177                     }
178                     return true;
179                 }
180                 return false;
181             },
182
183 <span id='Ext-Element-method-createShim'>            /**
184 </span>             * Creates an iframe shim for this element to keep selects and other windowed objects from
185              * showing through.
186              * @return {Ext.Element} The new shim element
187              */
188             createShim : function() {
189                 var el = document.createElement('iframe'),
190                     shim;
191
192                 el.frameBorder = '0';
193                 el.className = Ext.baseCSSPrefix + 'shim';
194                 el.src = Ext.SSL_SECURE_URL;
195                 shim = Ext.get(this.dom.parentNode.insertBefore(el, this.dom));
196                 shim.autoBoxAdjust = false;
197                 return shim;
198             }
199         };
200     }()
201 );</pre>
202 </body>
203 </html>