]> git.proxmox.com Git - extjs.git/blame - extjs/classic/classic/src/dom/Layer.js
add extjs 6.0.1 sources
[extjs.git] / extjs / classic / classic / src / dom / Layer.js
CommitLineData
6527f429
DM
1/**\r
2 * An extended {@link Ext.dom.Element} object that supports a shadow and shim\r
3 *\r
4 * @deprecated 5.1.0 Ext.dom.Element now includes support for shadow and shim\r
5 * see {@link Ext.dom.Element#enableShadow enableShadow} and\r
6 * {@link Ext.dom.Element#enableShim enableShim}\r
7 */\r
8Ext.define('Ext.dom.Layer', {\r
9 extend: 'Ext.Element',\r
10 alternateClassName: 'Ext.Layer',\r
11\r
12 /**\r
13 * @cfg {String/Boolean} [shadow=false]\r
14 * True to automatically create an {@link Ext.Shadow}, or a string indicating the\r
15 * shadow's display {@link Ext.Shadow#mode}. False to disable the shadow.\r
16 */\r
17\r
18 /**\r
19 * @cfg {String/Boolean} [shim=false]\r
20 * True to automatically create a {@link Ext.dom.Shim}.\r
21 */\r
22\r
23 /**\r
24 * @cfg {Object} [dh={tag: 'div', cls: 'x-layer'}]\r
25 * DomHelper object config to create element with.\r
26 */\r
27\r
28 /**\r
29 * @cfg {Boolean} [constrain=true]\r
30 * False to disable constrain to viewport.\r
31 */\r
32\r
33 /**\r
34 * @cfg {String} cls\r
35 * CSS class to add to the element\r
36 */\r
37\r
38 /**\r
39 * @cfg {Number} [zindex=11000]\r
40 * Starting z-index.\r
41 */\r
42\r
43 /**\r
44 * @cfg {Number} [shadowOffset=4]\r
45 * Number of pixels to offset the shadow\r
46 */\r
47\r
48 /**\r
49 * @cfg {Boolean} [useDisplay=false]\r
50 * Defaults to use css offsets to hide the Layer. Specify <tt>true</tt>\r
51 * to use css style <tt>'display:none;'</tt> to hide the Layer.\r
52 */\r
53\r
54 /**\r
55 * @cfg {String} visibilityCls\r
56 * The CSS class name to add in order to hide this Layer if this layer\r
57 * is configured with <code>{@link #hideMode}: 'asclass'</code>\r
58 */\r
59\r
60 /**\r
61 * @cfg {String} hideMode\r
62 * A String which specifies how this Layer will be hidden.\r
63 * Values may be:\r
64 *\r
65 * - `'display'` : The Component will be hidden using the `display: none` style.\r
66 * - `'visibility'` : The Component will be hidden using the `visibility: hidden` style.\r
67 * - `'offsets'` : The Component will be hidden by absolutely positioning it out of the visible area\r
68 * of the document. This is useful when a hidden Component must maintain measurable dimensions.\r
69 * Hiding using `display` results in a Component having zero dimensions.\r
70 */\r
71\r
72 isLayer: true,\r
73\r
74 /**\r
75 * Creates new Layer.\r
76 * @param {Object} [config] An object with config options.\r
77 * @param {String/HTMLElement} [existingEl] Uses an existing DOM element.\r
78 * If the element is not found it creates it.\r
79 */\r
80 constructor: function(config, existingEl) {\r
81 config = config || {};\r
82 var me = this,\r
83 dh = Ext.DomHelper,\r
84 cp = config.parentEl,\r
85 pel = cp ? Ext.getDom(cp) : document.body,\r
86 hm = config.hideMode,\r
87 cls = Ext.baseCSSPrefix + (config.fixed ? 'fixed-layer' : 'layer'),\r
88 dom, id, element, shadowConfig;\r
89\r
90 if (existingEl) {\r
91 dom = Ext.getDom(existingEl);\r
92 if (!dom.parentNode) {\r
93 pel.appendChild(dom);\r
94 }\r
95 }\r
96\r
97 if (!dom) {\r
98 dom = dh.append(pel, config.dh || {\r
99 tag: 'div',\r
100 cls: cls // primarily to give el 'position:absolute' or, if fixed, 'position:fixed'\r
101 });\r
102 }\r
103\r
104 if (config.id) {\r
105 dom.id = config.id;\r
106 }\r
107 id = dom.id;\r
108\r
109 if (id) {\r
110 element = Ext.cache[id];\r
111 if (element) {\r
112 // if we have an existing Ext.Element in the cache for this same dom\r
113 // element, delete it, so that it can be replaced by this layer instance\r
114 // when we callParent below.\r
115 delete Ext.cache[id];\r
116 element.dom = null;\r
117 }\r
118 }\r
119 this.callParent([dom]);\r
120\r
121 if (existingEl) {\r
122 me.addCls(cls);\r
123 }\r
124\r
125 if (config.preventSync) {\r
126 me.preventSync = true;\r
127 }\r
128\r
129 if (config.cls) {\r
130 me.addCls(config.cls);\r
131 }\r
132 me.constrain = config.constrain !== false;\r
133\r
134 // Allow Components to pass their hide mode down to the Layer if they are floating.\r
135 // Otherwise, allow useDisplay to override the default hiding method which is visibility.\r
136 // TODO: Have ExtJS's Element implement visibilityMode by using classes as in Mobile.\r
137 if (hm) {\r
138 me.setVisibilityMode(Ext.Element[hm.toUpperCase()]);\r
139 } else if (config.useDisplay) {\r
140 me.setVisibilityMode(Ext.Element.DISPLAY);\r
141 } else {\r
142 me.setVisibilityMode(Ext.Element.VISIBILITY);\r
143 }\r
144\r
145 if (config.shadow) {\r
146 me.shadowOffset = config.shadowOffset || 4;\r
147 shadowConfig = {\r
148 offset: me.shadowOffset,\r
149 fixed: config.fixed\r
150 };\r
151\r
152 if (config.shadow !== true) {\r
153 shadowConfig.mode = config.shadow;\r
154 }\r
155\r
156 me.enableShadow(shadowConfig);\r
157 } else {\r
158 me.shadowOffset = 0;\r
159 }\r
160\r
161 if (config.shim) {\r
162 me.enableShim({\r
163 fixed: config.fixed\r
164 });\r
165 }\r
166\r
167 // Keep the following only for cases where Ext.Layer would be instantiated\r
168 // directly. We don't ever pass hidden in the config in the framework\r
169 // since this is handled by the Component lifecycle.\r
170 if (config.hidden === true) {\r
171 me.hide();\r
172 } else if (config.hidden === false) {\r
173 me.show();\r
174 }\r
175 }\r
176});\r