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; }
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.Element
21 * An extended {@link Ext.Element} object that supports a shadow and shim, constrain to viewport and
22 * automatic maintaining of shadow/shim positions.
24 * @cfg {Boolean} [shim=true]
25 * False to disable the iframe shim in browsers which need one.
27 * @cfg {String/Boolean} [shadow=false]
28 * True to automatically create an {@link Ext.Shadow}, or a string indicating the
29 * shadow's display {@link Ext.Shadow#mode}. False to disable the shadow.
31 * @cfg {Object} [dh={tag: 'div', cls: 'x-layer'}]
32 * DomHelper object config to create element with.
34 * @cfg {Boolean} [constrain=true]
35 * False to disable constrain to viewport.
38 * CSS class to add to the element
40 * @cfg {Number} [zindex=11000]
43 * @cfg {Number} [shadowOffset=4]
44 * Number of pixels to offset the shadow
46 * @cfg {Boolean} [useDisplay=false]
47 * Defaults to use css offsets to hide the Layer. Specify <tt>true</tt>
48 * to use css style <tt>'display:none;'</tt> to hide the Layer.
50 * @cfg {String} visibilityCls
51 * The CSS class name to add in order to hide this Layer if this layer
52 * is configured with <code>{@link #hideMode}: 'asclass'</code>
54 * @cfg {String} hideMode
55 * A String which specifies how this Layer will be hidden.
56 * Values may be<div class="mdetail-params"><ul>
57 * <li><code>'display'</code> : The Component will be hidden using the <code>display: none</code> style.</li>
58 * <li><code>'visibility'</code> : The Component will be hidden using the <code>visibility: hidden</code> style.</li>
59 * <li><code>'offsets'</code> : The Component will be hidden by absolutely positioning it out of the visible area of the document. This
60 * is useful when a hidden Component must maintain measurable dimensions. Hiding using <code>display</code> results
61 * in a Component having zero dimensions.</li></ul></div>
63 Ext.define('Ext.Layer', {
66 // shims are shared among layer to keep from having 100 iframes
71 extend: 'Ext.Element',
73 <span id='Ext-Layer-method-constructor'> /**
74 </span> * Creates new Layer.
75 * @param {Object} config (optional) An object with config options.
76 * @param {String/HTMLElement} existingEl (optional) Uses an existing DOM element.
77 * If the element is not found it creates it.
79 constructor: function(config, existingEl) {
80 config = config || {};
84 pel = cp ? Ext.getDom(cp) : document.body,
88 me.dom = Ext.getDom(existingEl);
91 me.dom = dh.append(pel, config.dh || {
93 cls: Ext.baseCSSPrefix + 'layer'
96 me.addCls(Ext.baseCSSPrefix + 'layer');
97 if (!me.dom.parentNode) {
98 pel.appendChild(me.dom);
103 me.addCls(config.cls);
105 me.constrain = config.constrain !== false;
107 // Allow Components to pass their hide mode down to the Layer if they are floating.
108 // Otherwise, allow useDisplay to override the default hiding method which is visibility.
109 // TODO: Have ExtJS's Element implement visibilityMode by using classes as in Mobile.
111 me.setVisibilityMode(Ext.Element[hm.toUpperCase()]);
112 if (me.visibilityMode == Ext.Element.ASCLASS) {
113 me.visibilityCls = config.visibilityCls;
115 } else if (config.useDisplay) {
116 me.setVisibilityMode(Ext.Element.DISPLAY);
118 me.setVisibilityMode(Ext.Element.VISIBILITY);
122 me.id = me.dom.id = config.id;
124 me.id = Ext.id(me.dom);
126 me.position('absolute');
128 me.shadowOffset = config.shadowOffset || 4;
129 me.shadow = Ext.create('Ext.Shadow', {
130 offset: me.shadowOffset,
137 me.useShim = config.shim !== false && Ext.useShims;
138 if (config.hidden === true) {
145 getZIndex: function() {
146 return parseInt((this.getShim() || this).getStyle('z-index'), 10);
149 getShim: function() {
157 shim = me.self.shims.shift();
159 shim = me.createShim();
160 shim.enableDisplayMode('block');
163 pn = me.dom.parentNode;
164 if (shim.dom.parentNode != pn) {
165 pn.insertBefore(shim.dom, me.dom);
172 hideShim: function() {
176 me.shim.setDisplayed(false);
177 me.self.shims.push(me.shim);
182 disableShadow: function() {
185 if (me.shadow && !me.shadowDisabled) {
186 me.shadowDisabled = true;
188 me.lastShadowOffset = me.shadowOffset;
193 enableShadow: function(show) {
196 if (me.shadow && me.shadowDisabled) {
197 me.shadowDisabled = false;
198 me.shadowOffset = me.lastShadowOffset;
199 delete me.lastShadowOffset;
206 <span id='Ext-Layer-method-sync'> /**
208 * <p>Synchronize this Layer's associated elements, the shadow, and possibly the shim.</p>
209 * <p>This code can execute repeatedly in milliseconds,
210 * eg: dragging a Component configured liveDrag: true, or which has no ghost method
211 * so code size was sacrificed for efficiency (e.g. no getBox/setBox, no XY calls)</p>
212 * @param {Boolean} doShow Pass true to ensure that the shadow is shown.
214 sync: function(doShow) {
217 shadowPos, shimStyle, shadowSize;
219 if (!me.updating && me.isVisible() && (shadow || me.useShim)) {
220 var shim = me.getShim(),
221 l = me.getLeft(true),
223 w = me.dom.offsetWidth,
224 h = me.dom.offsetHeight,
227 if (shadow && !me.shadowDisabled) {
228 if (doShow && !shadow.isVisible()) {
231 shadow.realign(l, t, w, h);
234 // TODO: Determine how the shims zIndex is above the layer zIndex at this point
235 shimIndex = shim.getStyle('z-index');
236 if (shimIndex > me.zindex) {
237 me.shim.setStyle('z-index', me.zindex - 2);
240 // fit the shim behind the shadow, so it is shimmed too
241 if (shadow.isVisible()) {
242 shadowPos = shadow.el.getXY();
243 shimStyle = shim.dom.style;
244 shadowSize = shadow.el.getSize();
245 if (Ext.supports.CSS3BoxShadow) {
246 shadowSize.height += 6;
247 shadowSize.width += 4;
251 shimStyle.left = (shadowPos[0]) + 'px';
252 shimStyle.top = (shadowPos[1]) + 'px';
253 shimStyle.width = (shadowSize.width) + 'px';
254 shimStyle.height = (shadowSize.height) + 'px';
257 shim.setLeftTop(l, t);
261 // TODO: Determine how the shims zIndex is above the layer zIndex at this point
262 shimIndex = shim.getStyle('z-index');
263 if (shimIndex > me.zindex) {
264 me.shim.setStyle('z-index', me.zindex - 2);
268 shim.setLeftTop(l, t);
280 beginUpdate: function() {
281 this.updating = true;
285 endUpdate: function() {
286 this.updating = false;
291 hideUnders: function() {
299 constrainXY: function() {
300 if (this.constrain) {
301 var vw = Ext.Element.getViewWidth(),
302 vh = Ext.Element.getViewHeight(),
303 s = Ext.getDoc().getScroll(),
307 so = this.shadowOffset,
308 w = this.dom.offsetWidth + so,
309 h = this.dom.offsetHeight + so,
310 moved = false; // only move it if it needs it
311 // first validate right/bottom
312 if ((x + w) > vw + s.left) {
316 if ((y + h) > vh + s.top) {
320 // then make sure top/left isn't negative
330 Ext.Layer.superclass.setXY.call(this, [x, y]);
337 getConstrainOffset: function() {
338 return this.shadowOffset;
341 // overridden Element method
342 setVisible: function(visible, animate, duration, callback, easing) {
346 // post operation processing
356 // Hide shadow and shim if hiding
360 me.callParent([visible, animate, duration, callback, easing]);
368 beforeFx: function() {
370 return this.callParent(arguments);
374 afterFx: function() {
375 this.callParent(arguments);
376 this.sync(this.isVisible());
380 beforeAction: function() {
381 if (!this.updating && this.shadow) {
386 // overridden Element method
387 setLeft: function(left) {
388 this.callParent(arguments);
392 setTop: function(top) {
393 this.callParent(arguments);
397 setLeftTop: function(left, top) {
398 this.callParent(arguments);
402 setXY: function(xy, animate, duration, callback, easing) {
405 // Callback will restore shadow state and call the passed callback
406 callback = me.createCB(callback);
410 me.callParent([xy, animate, duration, callback, easing]);
418 createCB: function(callback) {
420 showShadow = me.shadow && me.shadow.isVisible();
431 // overridden Element method
432 setX: function(x, animate, duration, callback, easing) {
433 this.setXY([x, this.getY()], animate, duration, callback, easing);
437 // overridden Element method
438 setY: function(y, animate, duration, callback, easing) {
439 this.setXY([this.getX(), y], animate, duration, callback, easing);
443 // overridden Element method
444 setSize: function(w, h, animate, duration, callback, easing) {
447 // Callback will restore shadow state and call the passed callback
448 callback = me.createCB(callback);
451 me.callParent([w, h, animate, duration, callback, easing]);
458 // overridden Element method
459 setWidth: function(w, animate, duration, callback, easing) {
462 // Callback will restore shadow state and call the passed callback
463 callback = me.createCB(callback);
466 me.callParent([w, animate, duration, callback, easing]);
473 // overridden Element method
474 setHeight: function(h, animate, duration, callback, easing) {
477 // Callback will restore shadow state and call the passed callback
478 callback = me.createCB(callback);
481 me.callParent([h, animate, duration, callback, easing]);
488 // overridden Element method
489 setBounds: function(x, y, width, height, animate, duration, callback, easing) {
492 // Callback will restore shadow state and call the passed callback
493 callback = me.createCB(callback);
497 Ext.Layer.superclass.setXY.call(me, [x, y]);
498 Ext.Layer.superclass.setSize.call(me, width, height);
501 me.callParent([x, y, width, height, animate, duration, callback, easing]);
506 <span id='Ext-Layer-method-setZIndex'> /**
507 </span> * <p>Sets the z-index of this layer and adjusts any shadow and shim z-indexes. The layer z-index is automatically
508 * incremented depending upon the presence of a shim or a shadow in so that it always shows above those two associated elements.</p>
509 * <p>Any shim, will be assigned the passed z-index. A shadow will be assigned the next highet z-index, and the Layer's
510 * element will receive the highest z-index.
511 * @param {Number} zindex The new z-index to set
512 * @return {Ext.Layer} The Layer
514 setZIndex: function(zindex) {
519 me.shim.setStyle('z-index', zindex++);
522 me.shadow.setZIndex(zindex++);
524 return me.setStyle('z-index', zindex);
527 setOpacity: function(opacity){
529 this.shadow.setOpacity(opacity);
531 return this.callParent(arguments);