1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-Layer-method-constructor'><span id='Ext-Layer-cfg-hideMode'><span id='Ext-Layer-cfg-visibilityCls'><span id='Ext-Layer-cfg-useDisplay'><span id='Ext-Layer-cfg-shadowOffset'><span id='Ext-Layer-cfg-zindex'><span id='Ext-Layer-cfg-cls'><span id='Ext-Layer-cfg-constrain'><span id='Ext-Layer-cfg-dh'><span id='Ext-Layer-cfg-shadow'><span id='Ext-Layer-cfg-shim'><span id='Ext-Layer'>/**
2 </span></span></span></span></span></span></span></span></span></span></span></span> * @class Ext.Layer
3 * @extends Ext.core.Element
4 * An extended {@link Ext.core.Element} object that supports a shadow and shim, constrain to viewport and
5 * automatic maintaining of shadow/shim positions.
6 * @cfg {Boolean} shim False to disable the iframe shim in browsers which need one (defaults to true)
7 * @cfg {String/Boolean} shadow True to automatically create an {@link Ext.Shadow}, or a string indicating the
8 * shadow's display {@link Ext.Shadow#mode}. False to disable the shadow. (defaults to false)
9 * @cfg {Object} dh DomHelper object config to create element with (defaults to {tag: 'div', cls: 'x-layer'}).
10 * @cfg {Boolean} constrain False to disable constrain to viewport (defaults to true)
11 * @cfg {String} cls CSS class to add to the element
12 * @cfg {Number} zindex Starting z-index (defaults to 11000)
13 * @cfg {Number} shadowOffset Number of pixels to offset the shadow (defaults to 4)
14 * @cfg {Boolean} useDisplay
15 * Defaults to use css offsets to hide the Layer. Specify <tt>true</tt>
16 * to use css style <tt>'display:none;'</tt> to hide the Layer.
17 * @cfg {String} visibilityCls The CSS class name to add in order to hide this Layer if this layer
18 * is configured with <code>{@link #hideMode}: 'asclass'</code>
19 * @cfg {String} hideMode
20 * A String which specifies how this Layer will be hidden.
21 * Values may be<div class="mdetail-params"><ul>
22 * <li><code>'display'</code> : The Component will be hidden using the <code>display: none</code> style.</li>
23 * <li><code>'visibility'</code> : The Component will be hidden using the <code>visibility: hidden</code> style.</li>
24 * <li><code>'offsets'</code> : The Component will be hidden by absolutely positioning it out of the visible area of the document. This
25 * is useful when a hidden Component must maintain measurable dimensions. Hiding using <code>display</code> results
26 * in a Component having zero dimensions.</li></ul></div>
28 * @param {Object} config An object with config options.
29 * @param {String/HTMLElement} existingEl (optional) Uses an existing DOM element. If the element is not found it creates it.
31 Ext.define('Ext.Layer', {
34 // shims are shared among layer to keep from having 100 iframes
39 extend: 'Ext.core.Element',
41 constructor: function(config, existingEl) {
42 config = config || {};
44 dh = Ext.core.DomHelper,
46 pel = cp ? Ext.getDom(cp) : document.body,
50 me.dom = Ext.getDom(existingEl);
53 me.dom = dh.append(pel, config.dh || {
55 cls: Ext.baseCSSPrefix + 'layer'
58 me.addCls(Ext.baseCSSPrefix + 'layer');
59 if (!me.dom.parentNode) {
60 pel.appendChild(me.dom);
65 me.addCls(config.cls);
67 me.constrain = config.constrain !== false;
69 // Allow Components to pass their hide mode down to the Layer if they are floating.
70 // Otherwise, allow useDisplay to override the default hiding method which is visibility.
71 // TODO: Have ExtJS's Element implement visibilityMode by using classes as in Mobile.
73 me.setVisibilityMode(Ext.core.Element[hm.toUpperCase()]);
74 if (me.visibilityMode == Ext.core.Element.ASCLASS) {
75 me.visibilityCls = config.visibilityCls;
77 } else if (config.useDisplay) {
78 me.setVisibilityMode(Ext.core.Element.DISPLAY);
80 me.setVisibilityMode(Ext.core.Element.VISIBILITY);
84 me.id = me.dom.id = config.id;
86 me.id = Ext.id(me.dom);
88 me.position('absolute');
90 me.shadowOffset = config.shadowOffset || 4;
91 me.shadow = Ext.create('Ext.Shadow', {
92 offset: me.shadowOffset,
99 me.useShim = config.shim !== false && Ext.useShims;
100 if (config.hidden === true) {
107 getZIndex: function() {
108 return parseInt((this.getShim() || this).getStyle('z-index'), 10);
111 getShim: function() {
119 shim = me.self.shims.shift();
121 shim = me.createShim();
122 shim.enableDisplayMode('block');
125 pn = me.dom.parentNode;
126 if (shim.dom.parentNode != pn) {
127 pn.insertBefore(shim.dom, me.dom);
134 hideShim: function() {
136 this.shim.setDisplayed(false);
137 this.self.shims.push(this.shim);
142 disableShadow: function() {
144 this.shadowDisabled = true;
146 this.lastShadowOffset = this.shadowOffset;
147 this.shadowOffset = 0;
151 enableShadow: function(show) {
153 this.shadowDisabled = false;
154 this.shadowOffset = this.lastShadowOffset;
155 delete this.lastShadowOffset;
162 <span id='Ext-Layer-method-sync'> /**
164 * <p>Synchronize this Layer's associated elements, the shadow, and possibly the shim.</p>
165 * <p>This code can execute repeatedly in milliseconds,
166 * eg: dragging a Component configured liveDrag: true, or which has no ghost method
167 * so code size was sacrificed for efficiency (e.g. no getBox/setBox, no XY calls)</p>
168 * @param {Boolean} doShow Pass true to ensure that the shadow is shown.
170 sync: function(doShow) {
173 shadowPos, shimStyle, shadowSize;
175 if (!this.updating && this.isVisible() && (shadow || this.useShim)) {
176 var shim = this.getShim(),
177 l = this.getLeft(true),
178 t = this.getTop(true),
180 h = this.getHeight(),
183 if (shadow && !this.shadowDisabled) {
184 if (doShow && !shadow.isVisible()) {
187 shadow.realign(l, t, w, h);
190 // TODO: Determine how the shims zIndex is above the layer zIndex at this point
191 shimIndex = shim.getStyle('z-index');
192 if (shimIndex > me.zindex) {
193 me.shim.setStyle('z-index', me.zindex - 2);
196 // fit the shim behind the shadow, so it is shimmed too
197 if (shadow.isVisible()) {
198 shadowPos = shadow.el.getXY();
199 shimStyle = shim.dom.style;
200 shadowSize = shadow.el.getSize();
201 shimStyle.left = (shadowPos[0]) + 'px';
202 shimStyle.top = (shadowPos[1]) + 'px';
203 shimStyle.width = (shadowSize.width) + 'px';
204 shimStyle.height = (shadowSize.height) + 'px';
207 shim.setLeftTop(l, t);
211 // TODO: Determine how the shims zIndex is above the layer zIndex at this point
212 shimIndex = shim.getStyle('z-index');
213 if (shimIndex > me.zindex) {
214 me.shim.setStyle('z-index', me.zindex - 2);
218 shim.setLeftTop(l, t);
230 beginUpdate: function() {
231 this.updating = true;
235 endUpdate: function() {
236 this.updating = false;
241 hideUnders: function() {
249 constrainXY: function() {
250 if (this.constrain) {
251 var vw = Ext.core.Element.getViewWidth(),
252 vh = Ext.core.Element.getViewHeight(),
253 s = Ext.getDoc().getScroll(),
257 so = this.shadowOffset,
258 w = this.dom.offsetWidth + so,
259 h = this.dom.offsetHeight + so,
260 moved = false; // only move it if it needs it
261 // first validate right/bottom
262 if ((x + w) > vw + s.left) {
266 if ((y + h) > vh + s.top) {
270 // then make sure top/left isn't negative
280 Ext.Layer.superclass.setXY.call(this, [x, y]);
287 getConstrainOffset: function() {
288 return this.shadowOffset;
291 // overridden Element method
292 setVisible: function(visible, animate, duration, callback, easing) {
296 // post operation processing
306 // Hide shadow and shim if hiding
308 this.hideUnders(true);
310 this.callParent([visible, animate, duration, callback, easing]);
318 beforeFx: function() {
320 return this.callParent(arguments);
324 afterFx: function() {
325 this.callParent(arguments);
326 this.sync(this.isVisible());
330 beforeAction: function() {
331 if (!this.updating && this.shadow) {
336 // overridden Element method
337 setLeft: function(left) {
338 this.callParent(arguments);
342 setTop: function(top) {
343 this.callParent(arguments);
347 setLeftTop: function(left, top) {
348 this.callParent(arguments);
352 setXY: function(xy, animate, duration, callback, easing) {
354 // Callback will restore shadow state and call the passed callback
355 callback = this.createCB(callback);
359 this.callParent([xy, animate, duration, callback, easing]);
367 createCB: function(callback) {
369 showShadow = me.shadow && me.shadow.isVisible();
380 // overridden Element method
381 setX: function(x, animate, duration, callback, easing) {
382 this.setXY([x, this.getY()], animate, duration, callback, easing);
386 // overridden Element method
387 setY: function(y, animate, duration, callback, easing) {
388 this.setXY([this.getX(), y], animate, duration, callback, easing);
392 // overridden Element method
393 setSize: function(w, h, animate, duration, callback, easing) {
394 // Callback will restore shadow state and call the passed callback
395 callback = this.createCB(callback);
398 this.callParent([w, h, animate, duration, callback, easing]);
405 // overridden Element method
406 setWidth: function(w, animate, duration, callback, easing) {
407 // Callback will restore shadow state and call the passed callback
408 callback = this.createCB(callback);
411 this.callParent([w, animate, duration, callback, easing]);
418 // overridden Element method
419 setHeight: function(h, animate, duration, callback, easing) {
420 // Callback will restore shadow state and call the passed callback
421 callback = this.createCB(callback);
424 this.callParent([h, animate, duration, callback, easing]);
431 // overridden Element method
432 setBounds: function(x, y, width, height, animate, duration, callback, easing) {
433 // Callback will restore shadow state and call the passed callback
434 callback = this.createCB(callback);
438 Ext.Layer.superclass.setXY.call(this, [x, y]);
439 Ext.Layer.superclass.setSize.call(this, width, height);
442 this.callParent([x, y, width, height, animate, duration, callback, easing]);
447 <span id='Ext-Layer-method-setZIndex'> /**
448 </span> * <p>Sets the z-index of this layer and adjusts any shadow and shim z-indexes. The layer z-index is automatically
449 * incremented depending upon the presence of a shim or a shadow in so that it always shows above those two associated elements.</p>
450 * <p>Any shim, will be assigned the passed z-index. A shadow will be assigned the next highet z-index, and the Layer's
451 * element will receive the highest z-index.
452 * @param {Number} zindex The new z-index to set
453 * @return {this} The Layer
455 setZIndex: function(zindex) {
456 this.zindex = zindex;
457 if (this.getShim()) {
458 this.shim.setStyle('z-index', zindex++);
461 this.shadow.setZIndex(zindex++);
463 this.setStyle('z-index', zindex);
467 </pre></pre></body></html>