3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\r
4 <title>The source code</title>
\r
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
8 <body onload="prettyPrint();">
\r
9 <pre class="prettyprint lang-js"><div id="cls-Ext.Layer"></div>/**
11 * @extends Ext.Element
12 * An extended {@link Ext.Element} object that supports a shadow and shim, constrain to viewport and
13 * automatic maintaining of shadow/shim positions.
14 * @cfg {Boolean} shim False to disable the iframe shim in browsers which need one (defaults to true)
15 * @cfg {String/Boolean} shadow True to automatically create an {@link Ext.Shadow}, or a string indicating the
16 * shadow's display {@link Ext.Shadow#mode}. False to disable the shadow. (defaults to false)
17 * @cfg {Object} dh DomHelper object config to create element with (defaults to {tag: 'div', cls: 'x-layer'}).
18 * @cfg {Boolean} constrain False to disable constrain to viewport (defaults to true)
19 * @cfg {String} cls CSS class to add to the element
20 * @cfg {Number} zindex Starting z-index (defaults to 11000)
21 * @cfg {Number} shadowOffset Number of pixels to offset the shadow (defaults to 4)
22 * @cfg {Boolean} useDisplay
23 * Defaults to use css offsets to hide the Layer. Specify <tt>true</tt>
24 * to use css style <tt>'display:none;'</tt> to hide the Layer.
26 * @param {Object} config An object with config options.
27 * @param {String/HTMLElement} existingEl (optional) Uses an existing DOM element. If the element is not found it creates it.
30 Ext.Layer = function(config, existingEl){
31 config = config || {};
32 var dh = Ext.DomHelper;
33 var cp = config.parentEl, pel = cp ? Ext.getDom(cp) : document.body;
35 this.dom = Ext.getDom(existingEl);
38 var o = config.dh || {tag: 'div', cls: 'x-layer'};
39 this.dom = dh.append(pel, o);
42 this.addClass(config.cls);
44 this.constrain = config.constrain !== false;
45 this.setVisibilityMode(Ext.Element.VISIBILITY);
47 this.id = this.dom.id = config.id;
49 this.id = Ext.id(this.dom);
51 this.zindex = config.zindex || this.getZIndex();
52 this.position('absolute', this.zindex);
54 this.shadowOffset = config.shadowOffset || 4;
55 this.shadow = new Ext.Shadow({
56 offset : this.shadowOffset,
60 this.shadowOffset = 0;
62 this.useShim = config.shim !== false && Ext.useShims;
63 this.useDisplay = config.useDisplay;
67 var supr = Ext.Element.prototype;
69 // shims are shared among layer to keep from having 100 iframes
72 Ext.extend(Ext.Layer, Ext.Element, {
74 getZIndex : function(){
75 return this.zindex || parseInt((this.getShim() || this).getStyle('z-index'), 10) || 11000;
85 var shim = shims.shift();
87 shim = this.createShim();
88 shim.enableDisplayMode('block');
89 shim.dom.style.display = 'none';
90 shim.dom.style.visibility = 'visible';
92 var pn = this.dom.parentNode;
93 if(shim.dom.parentNode != pn){
94 pn.insertBefore(shim.dom, this.dom);
96 shim.setStyle('z-index', this.getZIndex()-2);
101 hideShim : function(){
103 this.shim.setDisplayed(false);
104 shims.push(this.shim);
109 disableShadow : function(){
111 this.shadowDisabled = true;
113 this.lastShadowOffset = this.shadowOffset;
114 this.shadowOffset = 0;
118 enableShadow : function(show){
120 this.shadowDisabled = false;
121 this.shadowOffset = this.lastShadowOffset;
122 delete this.lastShadowOffset;
130 // this code can execute repeatedly in milliseconds (i.e. during a drag) so
131 // code size was sacrificed for effeciency (e.g. no getBox/setBox, no XY calls)
132 sync : function(doShow){
133 var sw = this.shadow;
134 if(!this.updating && this.isVisible() && (sw || this.useShim)){
135 var sh = this.getShim();
137 var w = this.getWidth(),
138 h = this.getHeight();
140 var l = this.getLeft(true),
141 t = this.getTop(true);
143 if(sw && !this.shadowDisabled){
144 if(doShow && !sw.isVisible()){
147 sw.realign(l, t, w, h);
153 // fit the shim behind the shadow, so it is shimmed too
154 var a = sw.adjusts, s = sh.dom.style;
155 s.left = (Math.min(l, l+a.l))+'px';
156 s.top = (Math.min(t, t+a.t))+'px';
157 s.width = (w+a.w)+'px';
158 s.height = (h+a.h)+'px';
172 destroy : function(){
177 this.removeAllListeners();
178 Ext.removeNode(this.dom);
187 beginUpdate : function(){
188 this.updating = true;
192 endUpdate : function(){
193 this.updating = false;
198 hideUnders : function(negOffset){
206 constrainXY : function(){
208 var vw = Ext.lib.Dom.getViewWidth(),
209 vh = Ext.lib.Dom.getViewHeight();
210 var s = Ext.getDoc().getScroll();
212 var xy = this.getXY();
213 var x = xy[0], y = xy[1];
214 var so = this.shadowOffset;
215 var w = this.dom.offsetWidth+so, h = this.dom.offsetHeight+so;
216 // only move it if it needs it
218 // first validate right/bottom
219 if((x + w) > vw+s.left){
223 if((y + h) > vh+s.top){
227 // then make sure top/left isn't negative
238 var ay = this.avoidY;
239 if(y <= ay && (y+h) >= ay){
245 supr.setXY.call(this, xy);
252 isVisible : function(){
257 showAction : function(){
258 this.visible = true; // track visibility to prevent getStyle calls
259 if(this.useDisplay === true){
260 this.setDisplayed('');
261 }else if(this.lastXY){
262 supr.setXY.call(this, this.lastXY);
263 }else if(this.lastLT){
264 supr.setLeftTop.call(this, this.lastLT[0], this.lastLT[1]);
269 hideAction : function(){
270 this.visible = false;
271 if(this.useDisplay === true){
272 this.setDisplayed(false);
274 this.setLeftTop(-10000,-10000);
278 // overridden Element method
279 setVisible : function(v, a, d, c, e){
289 }.createDelegate(this);
290 supr.setVisible.call(this, true, true, d, cb, e);
293 this.hideUnders(true);
302 }.createDelegate(this);
304 supr.setVisible.call(this, v, a, d, cb, e);
314 storeXY : function(xy){
319 storeLeftTop : function(left, top){
321 this.lastLT = [left, top];
325 beforeFx : function(){
327 return Ext.Layer.superclass.beforeFx.apply(this, arguments);
331 afterFx : function(){
332 Ext.Layer.superclass.afterFx.apply(this, arguments);
333 this.sync(this.isVisible());
337 beforeAction : function(){
338 if(!this.updating && this.shadow){
343 // overridden Element method
344 setLeft : function(left){
345 this.storeLeftTop(left, this.getTop(true));
346 supr.setLeft.apply(this, arguments);
351 setTop : function(top){
352 this.storeLeftTop(this.getLeft(true), top);
353 supr.setTop.apply(this, arguments);
358 setLeftTop : function(left, top){
359 this.storeLeftTop(left, top);
360 supr.setLeftTop.apply(this, arguments);
365 setXY : function(xy, a, d, c, e){
369 var cb = this.createCB(c);
370 supr.setXY.call(this, xy, a, d, cb, e);
378 createCB : function(c){
389 // overridden Element method
390 setX : function(x, a, d, c, e){
391 this.setXY([x, this.getY()], a, d, c, e);
395 // overridden Element method
396 setY : function(y, a, d, c, e){
397 this.setXY([this.getX(), y], a, d, c, e);
401 // overridden Element method
402 setSize : function(w, h, a, d, c, e){
404 var cb = this.createCB(c);
405 supr.setSize.call(this, w, h, a, d, cb, e);
412 // overridden Element method
413 setWidth : function(w, a, d, c, e){
415 var cb = this.createCB(c);
416 supr.setWidth.call(this, w, a, d, cb, e);
423 // overridden Element method
424 setHeight : function(h, a, d, c, e){
426 var cb = this.createCB(c);
427 supr.setHeight.call(this, h, a, d, cb, e);
434 // overridden Element method
435 setBounds : function(x, y, w, h, a, d, c, e){
437 var cb = this.createCB(c);
439 this.storeXY([x, y]);
440 supr.setXY.call(this, [x, y]);
441 supr.setSize.call(this, w, h, a, d, cb, e);
444 supr.setBounds.call(this, x, y, w, h, a, d, cb, e);
450 * Sets the z-index of this layer and adjusts any shadow and shim z-indexes. The layer z-index is automatically
451 * incremented by two more than the value passed in so that it always shows above any shadow or shim (the shadow
452 * element, if any, will be assigned z-index + 1, and the shim element, if any, will be assigned the unmodified z-index).
453 * @param {Number} zindex The new z-index to set
454 * @return {this} The Layer
456 setZIndex : function(zindex){
457 this.zindex = zindex;
458 this.setStyle('z-index', zindex + 2);
460 this.shadow.setZIndex(zindex + 1);
463 this.shim.setStyle('z-index', zindex);