3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.2.2
11 * Copyright(c) 2006-2010 Ext JS, Inc.
13 * http://www.extjs.com/license
15 <div id="cls-Ext.Layer"></div>/**
17 * @extends Ext.Element
18 * An extended {@link Ext.Element} object that supports a shadow and shim, constrain to viewport and
19 * automatic maintaining of shadow/shim positions.
20 * @cfg {Boolean} shim False to disable the iframe shim in browsers which need one (defaults to true)
21 * @cfg {String/Boolean} shadow True to automatically create an {@link Ext.Shadow}, or a string indicating the
22 * shadow's display {@link Ext.Shadow#mode}. False to disable the shadow. (defaults to false)
23 * @cfg {Object} dh DomHelper object config to create element with (defaults to {tag: 'div', cls: 'x-layer'}).
24 * @cfg {Boolean} constrain False to disable constrain to viewport (defaults to true)
25 * @cfg {String} cls CSS class to add to the element
26 * @cfg {Number} zindex Starting z-index (defaults to 11000)
27 * @cfg {Number} shadowOffset Number of pixels to offset the shadow (defaults to 4)
28 * @cfg {Boolean} useDisplay
29 * Defaults to use css offsets to hide the Layer. Specify <tt>true</tt>
30 * to use css style <tt>'display:none;'</tt> to hide the Layer.
32 * @param {Object} config An object with config options.
33 * @param {String/HTMLElement} existingEl (optional) Uses an existing DOM element. If the element is not found it creates it.
36 Ext.Layer = function(config, existingEl){
37 config = config || {};
38 var dh = Ext.DomHelper;
39 var cp = config.parentEl, pel = cp ? Ext.getDom(cp) : document.body;
41 this.dom = Ext.getDom(existingEl);
44 var o = config.dh || {tag: 'div', cls: 'x-layer'};
45 this.dom = dh.append(pel, o);
48 this.addClass(config.cls);
50 this.constrain = config.constrain !== false;
51 this.setVisibilityMode(Ext.Element.VISIBILITY);
53 this.id = this.dom.id = config.id;
55 this.id = Ext.id(this.dom);
57 this.zindex = config.zindex || this.getZIndex();
58 this.position('absolute', this.zindex);
60 this.shadowOffset = config.shadowOffset || 4;
61 this.shadow = new Ext.Shadow({
62 offset : this.shadowOffset,
66 this.shadowOffset = 0;
68 this.useShim = config.shim !== false && Ext.useShims;
69 this.useDisplay = config.useDisplay;
73 var supr = Ext.Element.prototype;
75 // shims are shared among layer to keep from having 100 iframes
78 Ext.extend(Ext.Layer, Ext.Element, {
80 getZIndex : function(){
81 return this.zindex || parseInt((this.getShim() || this).getStyle('z-index'), 10) || 11000;
91 var shim = shims.shift();
93 shim = this.createShim();
94 shim.enableDisplayMode('block');
95 shim.dom.style.display = 'none';
96 shim.dom.style.visibility = 'visible';
98 var pn = this.dom.parentNode;
99 if(shim.dom.parentNode != pn){
100 pn.insertBefore(shim.dom, this.dom);
102 shim.setStyle('z-index', this.getZIndex()-2);
107 hideShim : function(){
109 this.shim.setDisplayed(false);
110 shims.push(this.shim);
115 disableShadow : function(){
117 this.shadowDisabled = true;
119 this.lastShadowOffset = this.shadowOffset;
120 this.shadowOffset = 0;
124 enableShadow : function(show){
126 this.shadowDisabled = false;
127 this.shadowOffset = this.lastShadowOffset;
128 delete this.lastShadowOffset;
136 // this code can execute repeatedly in milliseconds (i.e. during a drag) so
137 // code size was sacrificed for effeciency (e.g. no getBox/setBox, no XY calls)
138 sync : function(doShow){
139 var shadow = this.shadow;
140 if(!this.updating && this.isVisible() && (shadow || this.useShim)){
141 var shim = this.getShim(),
143 h = this.getHeight(),
144 l = this.getLeft(true),
145 t = this.getTop(true);
147 if(shadow && !this.shadowDisabled){
148 if(doShow && !shadow.isVisible()){
151 shadow.realign(l, t, w, h);
157 // fit the shim behind the shadow, so it is shimmed too
158 var shadowAdj = shadow.el.getXY(), shimStyle = shim.dom.style,
159 shadowSize = shadow.el.getSize();
160 shimStyle.left = (shadowAdj[0])+'px';
161 shimStyle.top = (shadowAdj[1])+'px';
162 shimStyle.width = (shadowSize.width)+'px';
163 shimStyle.height = (shadowSize.height)+'px';
170 shim.setLeftTop(l, t);
176 destroy : function(){
181 this.removeAllListeners();
182 Ext.removeNode(this.dom);
191 beginUpdate : function(){
192 this.updating = true;
196 endUpdate : function(){
197 this.updating = false;
202 hideUnders : function(negOffset){
210 constrainXY : function(){
212 var vw = Ext.lib.Dom.getViewWidth(),
213 vh = Ext.lib.Dom.getViewHeight();
214 var s = Ext.getDoc().getScroll();
216 var xy = this.getXY();
217 var x = xy[0], y = xy[1];
218 var so = this.shadowOffset;
219 var w = this.dom.offsetWidth+so, h = this.dom.offsetHeight+so;
220 // only move it if it needs it
222 // first validate right/bottom
223 if((x + w) > vw+s.left){
227 if((y + h) > vh+s.top){
231 // then make sure top/left isn't negative
242 var ay = this.avoidY;
243 if(y <= ay && (y+h) >= ay){
249 supr.setXY.call(this, xy);
256 getConstrainOffset : function(){
257 return this.shadowOffset;
260 isVisible : function(){
265 showAction : function(){
266 this.visible = true; // track visibility to prevent getStyle calls
267 if(this.useDisplay === true){
268 this.setDisplayed('');
269 }else if(this.lastXY){
270 supr.setXY.call(this, this.lastXY);
271 }else if(this.lastLT){
272 supr.setLeftTop.call(this, this.lastLT[0], this.lastLT[1]);
277 hideAction : function(){
278 this.visible = false;
279 if(this.useDisplay === true){
280 this.setDisplayed(false);
282 this.setLeftTop(-10000,-10000);
286 // overridden Element method
287 setVisible : function(v, a, d, c, e){
297 }.createDelegate(this);
298 supr.setVisible.call(this, true, true, d, cb, e);
301 this.hideUnders(true);
310 }.createDelegate(this);
312 supr.setVisible.call(this, v, a, d, cb, e);
322 storeXY : function(xy){
327 storeLeftTop : function(left, top){
329 this.lastLT = [left, top];
333 beforeFx : function(){
335 return Ext.Layer.superclass.beforeFx.apply(this, arguments);
339 afterFx : function(){
340 Ext.Layer.superclass.afterFx.apply(this, arguments);
341 this.sync(this.isVisible());
345 beforeAction : function(){
346 if(!this.updating && this.shadow){
351 // overridden Element method
352 setLeft : function(left){
353 this.storeLeftTop(left, this.getTop(true));
354 supr.setLeft.apply(this, arguments);
359 setTop : function(top){
360 this.storeLeftTop(this.getLeft(true), top);
361 supr.setTop.apply(this, arguments);
366 setLeftTop : function(left, top){
367 this.storeLeftTop(left, top);
368 supr.setLeftTop.apply(this, arguments);
373 setXY : function(xy, a, d, c, e){
377 var cb = this.createCB(c);
378 supr.setXY.call(this, xy, a, d, cb, e);
386 createCB : function(c){
397 // overridden Element method
398 setX : function(x, a, d, c, e){
399 this.setXY([x, this.getY()], a, d, c, e);
403 // overridden Element method
404 setY : function(y, a, d, c, e){
405 this.setXY([this.getX(), y], a, d, c, e);
409 // overridden Element method
410 setSize : function(w, h, a, d, c, e){
412 var cb = this.createCB(c);
413 supr.setSize.call(this, w, h, a, d, cb, e);
420 // overridden Element method
421 setWidth : function(w, a, d, c, e){
423 var cb = this.createCB(c);
424 supr.setWidth.call(this, w, a, d, cb, e);
431 // overridden Element method
432 setHeight : function(h, a, d, c, e){
434 var cb = this.createCB(c);
435 supr.setHeight.call(this, h, a, d, cb, e);
442 // overridden Element method
443 setBounds : function(x, y, w, h, a, d, c, e){
445 var cb = this.createCB(c);
447 this.storeXY([x, y]);
448 supr.setXY.call(this, [x, y]);
449 supr.setSize.call(this, w, h, a, d, cb, e);
452 supr.setBounds.call(this, x, y, w, h, a, d, cb, e);
458 * Sets the z-index of this layer and adjusts any shadow and shim z-indexes. The layer z-index is automatically
459 * incremented by two more than the value passed in so that it always shows above any shadow or shim (the shadow
460 * element, if any, will be assigned z-index + 1, and the shim element, if any, will be assigned the unmodified z-index).
461 * @param {Number} zindex The new z-index to set
462 * @return {this} The Layer
464 setZIndex : function(zindex){
465 this.zindex = zindex;
466 this.setStyle('z-index', zindex + 2);
468 this.shadow.setZIndex(zindex + 1);
471 this.shim.setStyle('z-index', zindex);