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-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'>/**
19 </span></span></span></span></span></span></span></span></span></span></span> * @class Ext.Layer
20 * @extends Ext.core.Element
21 * An extended {@link Ext.core.Element} object that supports a shadow and shim, constrain to viewport and
22 * automatic maintaining of shadow/shim positions.
23 * @cfg {Boolean} shim False to disable the iframe shim in browsers which need one (defaults to true)
24 * @cfg {String/Boolean} shadow True to automatically create an {@link Ext.Shadow}, or a string indicating the
25 * shadow's display {@link Ext.Shadow#mode}. False to disable the shadow. (defaults to false)
26 * @cfg {Object} dh DomHelper object config to create element with (defaults to {tag: 'div', cls: 'x-layer'}).
27 * @cfg {Boolean} constrain False to disable constrain to viewport (defaults to true)
28 * @cfg {String} cls CSS class to add to the element
29 * @cfg {Number} zindex Starting z-index (defaults to 11000)
30 * @cfg {Number} shadowOffset Number of pixels to offset the shadow (defaults to 4)
31 * @cfg {Boolean} useDisplay
32 * Defaults to use css offsets to hide the Layer. Specify <tt>true</tt>
33 * to use css style <tt>'display:none;'</tt> to hide the Layer.
34 * @cfg {String} visibilityCls The CSS class name to add in order to hide this Layer if this layer
35 * is configured with <code>{@link #hideMode}: 'asclass'</code>
36 * @cfg {String} hideMode
37 * A String which specifies how this Layer will be hidden.
38 * Values may be<div class="mdetail-params"><ul>
39 * <li><code>'display'</code> : The Component will be hidden using the <code>display: none</code> style.</li>
40 * <li><code>'visibility'</code> : The Component will be hidden using the <code>visibility: hidden</code> style.</li>
41 * <li><code>'offsets'</code> : The Component will be hidden by absolutely positioning it out of the visible area of the document. This
42 * is useful when a hidden Component must maintain measurable dimensions. Hiding using <code>display</code> results
43 * in a Component having zero dimensions.</li></ul></div>
45 Ext.define('Ext.Layer', {
48 // shims are shared among layer to keep from having 100 iframes
53 extend: 'Ext.core.Element',
55 <span id='Ext-Layer-method-constructor'> /**
56 </span> * Creates new Layer.
57 * @param {Object} config (optional) An object with config options.
58 * @param {String/HTMLElement} existingEl (optional) Uses an existing DOM element.
59 * If the element is not found it creates it.
61 constructor: function(config, existingEl) {
62 config = config || {};
64 dh = Ext.core.DomHelper,
66 pel = cp ? Ext.getDom(cp) : document.body,
70 me.dom = Ext.getDom(existingEl);
73 me.dom = dh.append(pel, config.dh || {
75 cls: Ext.baseCSSPrefix + 'layer'
78 me.addCls(Ext.baseCSSPrefix + 'layer');
79 if (!me.dom.parentNode) {
80 pel.appendChild(me.dom);
85 me.addCls(config.cls);
87 me.constrain = config.constrain !== false;
89 // Allow Components to pass their hide mode down to the Layer if they are floating.
90 // Otherwise, allow useDisplay to override the default hiding method which is visibility.
91 // TODO: Have ExtJS's Element implement visibilityMode by using classes as in Mobile.
93 me.setVisibilityMode(Ext.core.Element[hm.toUpperCase()]);
94 if (me.visibilityMode == Ext.core.Element.ASCLASS) {
95 me.visibilityCls = config.visibilityCls;
97 } else if (config.useDisplay) {
98 me.setVisibilityMode(Ext.core.Element.DISPLAY);
100 me.setVisibilityMode(Ext.core.Element.VISIBILITY);
104 me.id = me.dom.id = config.id;
106 me.id = Ext.id(me.dom);
108 me.position('absolute');
110 me.shadowOffset = config.shadowOffset || 4;
111 me.shadow = Ext.create('Ext.Shadow', {
112 offset: me.shadowOffset,
119 me.useShim = config.shim !== false && Ext.useShims;
120 if (config.hidden === true) {
127 getZIndex: function() {
128 return parseInt((this.getShim() || this).getStyle('z-index'), 10);
131 getShim: function() {
139 shim = me.self.shims.shift();
141 shim = me.createShim();
142 shim.enableDisplayMode('block');
145 pn = me.dom.parentNode;
146 if (shim.dom.parentNode != pn) {
147 pn.insertBefore(shim.dom, me.dom);
154 hideShim: function() {
156 this.shim.setDisplayed(false);
157 this.self.shims.push(this.shim);
162 disableShadow: function() {
164 this.shadowDisabled = true;
166 this.lastShadowOffset = this.shadowOffset;
167 this.shadowOffset = 0;
171 enableShadow: function(show) {
173 this.shadowDisabled = false;
174 this.shadowOffset = this.lastShadowOffset;
175 delete this.lastShadowOffset;
182 <span id='Ext-Layer-method-sync'> /**
184 * <p>Synchronize this Layer's associated elements, the shadow, and possibly the shim.</p>
185 * <p>This code can execute repeatedly in milliseconds,
186 * eg: dragging a Component configured liveDrag: true, or which has no ghost method
187 * so code size was sacrificed for efficiency (e.g. no getBox/setBox, no XY calls)</p>
188 * @param {Boolean} doShow Pass true to ensure that the shadow is shown.
190 sync: function(doShow) {
193 shadowPos, shimStyle, shadowSize;
195 if (!this.updating && this.isVisible() && (shadow || this.useShim)) {
196 var shim = this.getShim(),
197 l = this.getLeft(true),
198 t = this.getTop(true),
200 h = this.getHeight(),
203 if (shadow && !this.shadowDisabled) {
204 if (doShow && !shadow.isVisible()) {
207 shadow.realign(l, t, w, h);
210 // TODO: Determine how the shims zIndex is above the layer zIndex at this point
211 shimIndex = shim.getStyle('z-index');
212 if (shimIndex > me.zindex) {
213 me.shim.setStyle('z-index', me.zindex - 2);
216 // fit the shim behind the shadow, so it is shimmed too
217 if (shadow.isVisible()) {
218 shadowPos = shadow.el.getXY();
219 shimStyle = shim.dom.style;
220 shadowSize = shadow.el.getSize();
221 shimStyle.left = (shadowPos[0]) + 'px';
222 shimStyle.top = (shadowPos[1]) + 'px';
223 shimStyle.width = (shadowSize.width) + 'px';
224 shimStyle.height = (shadowSize.height) + 'px';
227 shim.setLeftTop(l, t);
231 // TODO: Determine how the shims zIndex is above the layer zIndex at this point
232 shimIndex = shim.getStyle('z-index');
233 if (shimIndex > me.zindex) {
234 me.shim.setStyle('z-index', me.zindex - 2);
238 shim.setLeftTop(l, t);
250 beginUpdate: function() {
251 this.updating = true;
255 endUpdate: function() {
256 this.updating = false;
261 hideUnders: function() {
269 constrainXY: function() {
270 if (this.constrain) {
271 var vw = Ext.core.Element.getViewWidth(),
272 vh = Ext.core.Element.getViewHeight(),
273 s = Ext.getDoc().getScroll(),
277 so = this.shadowOffset,
278 w = this.dom.offsetWidth + so,
279 h = this.dom.offsetHeight + so,
280 moved = false; // only move it if it needs it
281 // first validate right/bottom
282 if ((x + w) > vw + s.left) {
286 if ((y + h) > vh + s.top) {
290 // then make sure top/left isn't negative
300 Ext.Layer.superclass.setXY.call(this, [x, y]);
307 getConstrainOffset: function() {
308 return this.shadowOffset;
311 // overridden Element method
312 setVisible: function(visible, animate, duration, callback, easing) {
316 // post operation processing
326 // Hide shadow and shim if hiding
328 this.hideUnders(true);
330 this.callParent([visible, animate, duration, callback, easing]);
338 beforeFx: function() {
340 return this.callParent(arguments);
344 afterFx: function() {
345 this.callParent(arguments);
346 this.sync(this.isVisible());
350 beforeAction: function() {
351 if (!this.updating && this.shadow) {
356 // overridden Element method
357 setLeft: function(left) {
358 this.callParent(arguments);
362 setTop: function(top) {
363 this.callParent(arguments);
367 setLeftTop: function(left, top) {
368 this.callParent(arguments);
372 setXY: function(xy, animate, duration, callback, easing) {
374 // Callback will restore shadow state and call the passed callback
375 callback = this.createCB(callback);
379 this.callParent([xy, animate, duration, callback, easing]);
387 createCB: function(callback) {
389 showShadow = me.shadow && me.shadow.isVisible();
400 // overridden Element method
401 setX: function(x, animate, duration, callback, easing) {
402 this.setXY([x, this.getY()], animate, duration, callback, easing);
406 // overridden Element method
407 setY: function(y, animate, duration, callback, easing) {
408 this.setXY([this.getX(), y], animate, duration, callback, easing);
412 // overridden Element method
413 setSize: function(w, h, animate, duration, callback, easing) {
414 // Callback will restore shadow state and call the passed callback
415 callback = this.createCB(callback);
418 this.callParent([w, h, animate, duration, callback, easing]);
425 // overridden Element method
426 setWidth: function(w, animate, duration, callback, easing) {
427 // Callback will restore shadow state and call the passed callback
428 callback = this.createCB(callback);
431 this.callParent([w, animate, duration, callback, easing]);
438 // overridden Element method
439 setHeight: function(h, animate, duration, callback, easing) {
440 // Callback will restore shadow state and call the passed callback
441 callback = this.createCB(callback);
444 this.callParent([h, animate, duration, callback, easing]);
451 // overridden Element method
452 setBounds: function(x, y, width, height, animate, duration, callback, easing) {
453 // Callback will restore shadow state and call the passed callback
454 callback = this.createCB(callback);
458 Ext.Layer.superclass.setXY.call(this, [x, y]);
459 Ext.Layer.superclass.setSize.call(this, width, height);
462 this.callParent([x, y, width, height, animate, duration, callback, easing]);
467 <span id='Ext-Layer-method-setZIndex'> /**
468 </span> * <p>Sets the z-index of this layer and adjusts any shadow and shim z-indexes. The layer z-index is automatically
469 * incremented depending upon the presence of a shim or a shadow in so that it always shows above those two associated elements.</p>
470 * <p>Any shim, will be assigned the passed z-index. A shadow will be assigned the next highet z-index, and the Layer's
471 * element will receive the highest z-index.
472 * @param {Number} zindex The new z-index to set
473 * @return {this} The Layer
475 setZIndex: function(zindex) {
476 this.zindex = zindex;
477 if (this.getShim()) {
478 this.shim.setStyle('z-index', zindex++);
481 this.shadow.setZIndex(zindex++);
483 this.setStyle('z-index', zindex);