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.3.0
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 cp = config.parentEl, pel = cp ? Ext.getDom(cp) : document.body;
42 this.dom = Ext.getDom(existingEl);
45 var o = config.dh || {tag: 'div', cls: 'x-layer'};
46 this.dom = dh.append(pel, o);
49 this.addClass(config.cls);
51 this.constrain = config.constrain !== false;
52 this.setVisibilityMode(Ext.Element.VISIBILITY);
54 this.id = this.dom.id = config.id;
56 this.id = Ext.id(this.dom);
58 this.zindex = config.zindex || this.getZIndex();
59 this.position('absolute', this.zindex);
61 this.shadowOffset = config.shadowOffset || 4;
62 this.shadow = new Ext.Shadow({
63 offset : this.shadowOffset,
67 this.shadowOffset = 0;
69 this.useShim = config.shim !== false && Ext.useShims;
70 this.useDisplay = config.useDisplay;
74 var supr = Ext.Element.prototype;
76 // shims are shared among layer to keep from having 100 iframes
79 Ext.extend(Ext.Layer, Ext.Element, {
81 getZIndex : function(){
82 return this.zindex || parseInt((this.getShim() || this).getStyle('z-index'), 10) || 11000;
92 var shim = shims.shift();
94 shim = this.createShim();
95 shim.enableDisplayMode('block');
96 shim.dom.style.display = 'none';
97 shim.dom.style.visibility = 'visible';
99 var pn = this.dom.parentNode;
100 if(shim.dom.parentNode != pn){
101 pn.insertBefore(shim.dom, this.dom);
103 shim.setStyle('z-index', this.getZIndex()-2);
108 hideShim : function(){
110 this.shim.setDisplayed(false);
111 shims.push(this.shim);
116 disableShadow : function(){
118 this.shadowDisabled = true;
120 this.lastShadowOffset = this.shadowOffset;
121 this.shadowOffset = 0;
125 enableShadow : function(show){
127 this.shadowDisabled = false;
128 this.shadowOffset = this.lastShadowOffset;
129 delete this.lastShadowOffset;
137 // this code can execute repeatedly in milliseconds (i.e. during a drag) so
138 // code size was sacrificed for effeciency (e.g. no getBox/setBox, no XY calls)
139 sync : function(doShow){
140 var shadow = this.shadow;
141 if(!this.updating && this.isVisible() && (shadow || this.useShim)){
142 var shim = this.getShim(),
144 h = this.getHeight(),
145 l = this.getLeft(true),
146 t = this.getTop(true);
148 if(shadow && !this.shadowDisabled){
149 if(doShow && !shadow.isVisible()){
152 shadow.realign(l, t, w, h);
158 // fit the shim behind the shadow, so it is shimmed too
159 var shadowAdj = shadow.el.getXY(), shimStyle = shim.dom.style,
160 shadowSize = shadow.el.getSize();
161 shimStyle.left = (shadowAdj[0])+'px';
162 shimStyle.top = (shadowAdj[1])+'px';
163 shimStyle.width = (shadowSize.width)+'px';
164 shimStyle.height = (shadowSize.height)+'px';
171 shim.setLeftTop(l, t);
177 destroy : function(){
182 this.removeAllListeners();
183 Ext.removeNode(this.dom);
192 beginUpdate : function(){
193 this.updating = true;
197 endUpdate : function(){
198 this.updating = false;
203 hideUnders : function(negOffset){
211 constrainXY : function(){
213 var vw = Ext.lib.Dom.getViewWidth(),
214 vh = Ext.lib.Dom.getViewHeight();
215 var s = Ext.getDoc().getScroll();
217 var xy = this.getXY();
218 var x = xy[0], y = xy[1];
219 var so = this.shadowOffset;
220 var w = this.dom.offsetWidth+so, h = this.dom.offsetHeight+so;
221 // only move it if it needs it
223 // first validate right/bottom
224 if((x + w) > vw+s.left){
228 if((y + h) > vh+s.top){
232 // then make sure top/left isn't negative
243 var ay = this.avoidY;
244 if(y <= ay && (y+h) >= ay){
250 supr.setXY.call(this, xy);
257 getConstrainOffset : function(){
258 return this.shadowOffset;
261 isVisible : function(){
266 showAction : function(){
267 this.visible = true; // track visibility to prevent getStyle calls
268 if(this.useDisplay === true){
269 this.setDisplayed('');
270 }else if(this.lastXY){
271 supr.setXY.call(this, this.lastXY);
272 }else if(this.lastLT){
273 supr.setLeftTop.call(this, this.lastLT[0], this.lastLT[1]);
278 hideAction : function(){
279 this.visible = false;
280 if(this.useDisplay === true){
281 this.setDisplayed(false);
283 this.setLeftTop(-10000,-10000);
287 // overridden Element method
288 setVisible : function(v, a, d, c, e){
298 }.createDelegate(this);
299 supr.setVisible.call(this, true, true, d, cb, e);
302 this.hideUnders(true);
311 }.createDelegate(this);
313 supr.setVisible.call(this, v, a, d, cb, e);
323 storeXY : function(xy){
328 storeLeftTop : function(left, top){
330 this.lastLT = [left, top];
334 beforeFx : function(){
336 return Ext.Layer.superclass.beforeFx.apply(this, arguments);
340 afterFx : function(){
341 Ext.Layer.superclass.afterFx.apply(this, arguments);
342 this.sync(this.isVisible());
346 beforeAction : function(){
347 if(!this.updating && this.shadow){
352 // overridden Element method
353 setLeft : function(left){
354 this.storeLeftTop(left, this.getTop(true));
355 supr.setLeft.apply(this, arguments);
360 setTop : function(top){
361 this.storeLeftTop(this.getLeft(true), top);
362 supr.setTop.apply(this, arguments);
367 setLeftTop : function(left, top){
368 this.storeLeftTop(left, top);
369 supr.setLeftTop.apply(this, arguments);
374 setXY : function(xy, a, d, c, e){
378 var cb = this.createCB(c);
379 supr.setXY.call(this, xy, a, d, cb, e);
387 createCB : function(c){
398 // overridden Element method
399 setX : function(x, a, d, c, e){
400 this.setXY([x, this.getY()], a, d, c, e);
404 // overridden Element method
405 setY : function(y, a, d, c, e){
406 this.setXY([this.getX(), y], a, d, c, e);
410 // overridden Element method
411 setSize : function(w, h, a, d, c, e){
413 var cb = this.createCB(c);
414 supr.setSize.call(this, w, h, a, d, cb, e);
421 // overridden Element method
422 setWidth : function(w, a, d, c, e){
424 var cb = this.createCB(c);
425 supr.setWidth.call(this, w, a, d, cb, e);
432 // overridden Element method
433 setHeight : function(h, a, d, c, e){
435 var cb = this.createCB(c);
436 supr.setHeight.call(this, h, a, d, cb, e);
443 // overridden Element method
444 setBounds : function(x, y, w, h, a, d, c, e){
446 var cb = this.createCB(c);
448 this.storeXY([x, y]);
449 supr.setXY.call(this, [x, y]);
450 supr.setSize.call(this, w, h, a, d, cb, e);
453 supr.setBounds.call(this, x, y, w, h, a, d, cb, e);
459 * Sets the z-index of this layer and adjusts any shadow and shim z-indexes. The layer z-index is automatically
460 * incremented by two more than the value passed in so that it always shows above any shadow or shim (the shadow
461 * element, if any, will be assigned z-index + 1, and the shim element, if any, will be assigned the unmodified z-index).
462 * @param {Number} zindex The new z-index to set
463 * @return {this} The Layer
465 setZIndex : function(zindex){
466 this.zindex = zindex;
467 this.setStyle('z-index', zindex + 2);
469 this.shadow.setZIndex(zindex + 1);
472 this.shim.setStyle('z-index', zindex);