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.1
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 isVisible : function(){
261 showAction : function(){
262 this.visible = true; // track visibility to prevent getStyle calls
263 if(this.useDisplay === true){
264 this.setDisplayed('');
265 }else if(this.lastXY){
266 supr.setXY.call(this, this.lastXY);
267 }else if(this.lastLT){
268 supr.setLeftTop.call(this, this.lastLT[0], this.lastLT[1]);
273 hideAction : function(){
274 this.visible = false;
275 if(this.useDisplay === true){
276 this.setDisplayed(false);
278 this.setLeftTop(-10000,-10000);
282 // overridden Element method
283 setVisible : function(v, a, d, c, e){
293 }.createDelegate(this);
294 supr.setVisible.call(this, true, true, d, cb, e);
297 this.hideUnders(true);
306 }.createDelegate(this);
308 supr.setVisible.call(this, v, a, d, cb, e);
318 storeXY : function(xy){
323 storeLeftTop : function(left, top){
325 this.lastLT = [left, top];
329 beforeFx : function(){
331 return Ext.Layer.superclass.beforeFx.apply(this, arguments);
335 afterFx : function(){
336 Ext.Layer.superclass.afterFx.apply(this, arguments);
337 this.sync(this.isVisible());
341 beforeAction : function(){
342 if(!this.updating && this.shadow){
347 // overridden Element method
348 setLeft : function(left){
349 this.storeLeftTop(left, this.getTop(true));
350 supr.setLeft.apply(this, arguments);
355 setTop : function(top){
356 this.storeLeftTop(this.getLeft(true), top);
357 supr.setTop.apply(this, arguments);
362 setLeftTop : function(left, top){
363 this.storeLeftTop(left, top);
364 supr.setLeftTop.apply(this, arguments);
369 setXY : function(xy, a, d, c, e){
373 var cb = this.createCB(c);
374 supr.setXY.call(this, xy, a, d, cb, e);
382 createCB : function(c){
393 // overridden Element method
394 setX : function(x, a, d, c, e){
395 this.setXY([x, this.getY()], a, d, c, e);
399 // overridden Element method
400 setY : function(y, a, d, c, e){
401 this.setXY([this.getX(), y], a, d, c, e);
405 // overridden Element method
406 setSize : function(w, h, a, d, c, e){
408 var cb = this.createCB(c);
409 supr.setSize.call(this, w, h, a, d, cb, e);
416 // overridden Element method
417 setWidth : function(w, a, d, c, e){
419 var cb = this.createCB(c);
420 supr.setWidth.call(this, w, a, d, cb, e);
427 // overridden Element method
428 setHeight : function(h, a, d, c, e){
430 var cb = this.createCB(c);
431 supr.setHeight.call(this, h, a, d, cb, e);
438 // overridden Element method
439 setBounds : function(x, y, w, h, a, d, c, e){
441 var cb = this.createCB(c);
443 this.storeXY([x, y]);
444 supr.setXY.call(this, [x, y]);
445 supr.setSize.call(this, w, h, a, d, cb, e);
448 supr.setBounds.call(this, x, y, w, h, a, d, cb, e);
454 * Sets the z-index of this layer and adjusts any shadow and shim z-indexes. The layer z-index is automatically
455 * incremented by two more than the value passed in so that it always shows above any shadow or shim (the shadow
456 * element, if any, will be assigned z-index + 1, and the shim element, if any, will be assigned the unmodified z-index).
457 * @param {Number} zindex The new z-index to set
458 * @return {this} The Layer
460 setZIndex : function(zindex){
461 this.zindex = zindex;
462 this.setStyle('z-index', zindex + 2);
464 this.shadow.setZIndex(zindex + 1);
467 this.shim.setStyle('z-index', zindex);