Upgrade to ExtJS 3.2.2 - Released 06/02/2010
[extjs.git] / src / core / Element.fx-more.js
1 /*!
2  * Ext JS Library 3.2.2
3  * Copyright(c) 2006-2010 Ext JS, Inc.
4  * licensing@extjs.com
5  * http://www.extjs.com/license
6  */
7 /**
8  * @class Ext.Element
9  */
10 Ext.Element.addMethods(
11 function(){
12     var VISIBILITY = "visibility",
13         DISPLAY = "display",
14         HIDDEN = "hidden",
15         NONE = "none",
16             XMASKED = "x-masked",
17                 XMASKEDRELATIVE = "x-masked-relative",
18         data = Ext.Element.data;
19
20         return {
21                 /**
22              * Checks whether the element is currently visible using both visibility and display properties.
23              * @param {Boolean} deep (optional) True to walk the dom and see if parent elements are hidden (defaults to false)
24              * @return {Boolean} True if the element is currently visible, else false
25              */
26             isVisible : function(deep) {
27                 var vis = !this.isStyle(VISIBILITY,HIDDEN) && !this.isStyle(DISPLAY,NONE),
28                         p = this.dom.parentNode;
29                 if(deep !== true || !vis){
30                     return vis;
31                 }
32                 while(p && !/^body/i.test(p.tagName)){
33                     if(!Ext.fly(p, '_isVisible').isVisible()){
34                         return false;
35                     }
36                     p = p.parentNode;
37                 }
38                 return true;
39             },
40
41             /**
42              * Returns true if display is not "none"
43              * @return {Boolean}
44              */
45             isDisplayed : function() {
46                 return !this.isStyle(DISPLAY, NONE);
47             },
48
49                 /**
50              * Convenience method for setVisibilityMode(Element.DISPLAY)
51              * @param {String} display (optional) What to set display to when visible
52              * @return {Ext.Element} this
53              */
54             enableDisplayMode : function(display){
55                 this.setVisibilityMode(Ext.Element.DISPLAY);
56                 if(!Ext.isEmpty(display)){
57                 data(this.dom, 'originalDisplay', display);
58             }
59                 return this;
60             },
61
62                 /**
63              * Puts a mask over this element to disable user interaction. Requires core.css.
64              * This method can only be applied to elements which accept child nodes.
65              * @param {String} msg (optional) A message to display in the mask
66              * @param {String} msgCls (optional) A css class to apply to the msg element
67              * @return {Element} The mask element
68              */
69             mask : function(msg, msgCls){
70                     var me = this,
71                         dom = me.dom,
72                         dh = Ext.DomHelper,
73                         EXTELMASKMSG = "ext-el-mask-msg",
74                 el,
75                 mask;
76
77                 if(!/^body/i.test(dom.tagName) && me.getStyle('position') == 'static'){
78                     me.addClass(XMASKEDRELATIVE);
79                 }
80                 if((el = data(dom, 'maskMsg'))){
81                     el.remove();
82                 }
83                 if((el = data(dom, 'mask'))){
84                     el.remove();
85                 }
86
87             mask = dh.append(dom, {cls : "ext-el-mask"}, true);
88                 data(dom, 'mask', mask);
89
90                 me.addClass(XMASKED);
91                 mask.setDisplayed(true);
92                 if(typeof msg == 'string'){
93                 var mm = dh.append(dom, {cls : EXTELMASKMSG, cn:{tag:'div'}}, true);
94                 data(dom, 'maskMsg', mm);
95                     mm.dom.className = msgCls ? EXTELMASKMSG + " " + msgCls : EXTELMASKMSG;
96                     mm.dom.firstChild.innerHTML = msg;
97                     mm.setDisplayed(true);
98                     mm.center(me);
99                 }
100                 if(Ext.isIE && !(Ext.isIE7 && Ext.isStrict) && me.getStyle('height') == 'auto'){ // ie will not expand full height automatically
101                     mask.setSize(undefined, me.getHeight());
102                 }
103                 return mask;
104             },
105
106             /**
107              * Removes a previously applied mask.
108              */
109             unmask : function(){
110                     var me = this,
111                 dom = me.dom,
112                         mask = data(dom, 'mask'),
113                         maskMsg = data(dom, 'maskMsg');
114                 if(mask){
115                     if(maskMsg){
116                         maskMsg.remove();
117                     data(dom, 'maskMsg', undefined);
118                     }
119                     mask.remove();
120                 data(dom, 'mask', undefined);
121                 }
122                 if(me.isMasked()){
123                 me.removeClass([XMASKED, XMASKEDRELATIVE]);
124             }
125             },
126
127             /**
128              * Returns true if this element is masked
129              * @return {Boolean}
130              */
131             isMasked : function(){
132             var m = data(this.dom, 'mask');
133                 return m && m.isVisible();
134             },
135
136             /**
137              * Creates an iframe shim for this element to keep selects and other windowed objects from
138              * showing through.
139              * @return {Ext.Element} The new shim element
140              */
141             createShim : function(){
142                 var el = document.createElement('iframe'),
143                         shim;
144                 el.frameBorder = '0';
145                 el.className = 'ext-shim';
146                 el.src = Ext.SSL_SECURE_URL;
147                 shim = Ext.get(this.dom.parentNode.insertBefore(el, this.dom));
148                 shim.autoBoxAdjust = false;
149                 return shim;
150             }
151     };
152 }());