3 * Copyright(c) 2006-2010 Ext JS, Inc.
5 * http://www.extjs.com/license
9 * Simple class that can provide a shadow effect for any element. Note that the element MUST be absolutely positioned,
10 * and the shadow does not provide any shimming. This should be used only in simple cases -- for more advanced
11 * functionality that can also provide the same shadow effect, see the {@link Ext.Layer} class.
14 * @param {Object} config The config object
16 Ext.Shadow = function(config){
17 Ext.apply(this, config);
18 if(typeof this.mode != "string"){
19 this.mode = this.defaultMode;
21 var o = this.offset, a = {h: 0};
22 var rad = Math.floor(this.offset/2);
23 switch(this.mode.toLowerCase()){ // all this hideous nonsense calculates the various offsets for shadows
29 a.l -= this.offset + rad;
30 a.t -= this.offset + rad;
41 a.l -= (this.offset - rad);
42 a.t -= this.offset + rad;
44 a.w -= (this.offset - rad)*2;
55 a.l -= (this.offset - rad);
56 a.t -= (this.offset - rad);
58 a.w -= (this.offset + rad + 1);
59 a.h -= (this.offset + rad);
68 Ext.Shadow.prototype = {
71 * The shadow display mode. Supports the following options:<div class="mdetail-params"><ul>
72 * <li><b><tt>sides</tt></b> : Shadow displays on both sides and bottom only</li>
73 * <li><b><tt>frame</tt></b> : Shadow displays equally on all four sides</li>
74 * <li><b><tt>drop</tt></b> : Traditional bottom-right drop shadow</li>
78 * @cfg {String} offset
79 * The number of pixels to offset the shadow from the element (defaults to <tt>4</tt>)
87 * Displays the shadow under the target element
88 * @param {Mixed} targetEl The id or element under which the shadow should display
90 show : function(target){
91 target = Ext.get(target);
93 this.el = Ext.Shadow.Pool.pull();
94 if(this.el.dom.nextSibling != target.dom){
95 this.el.insertBefore(target);
98 this.el.setStyle("z-index", this.zIndex || parseInt(target.getStyle("z-index"), 10)-1);
100 this.el.dom.style.filter="progid:DXImageTransform.Microsoft.alpha(opacity=50) progid:DXImageTransform.Microsoft.Blur(pixelradius="+(this.offset)+")";
103 target.getLeft(true),
108 this.el.dom.style.display = "block";
112 * Returns true if the shadow is visible, else false
114 isVisible : function(){
115 return this.el ? true : false;
119 * Direct alignment when values are already available. Show must be called at least once before
120 * calling this method to ensure it is initialized.
121 * @param {Number} left The target element left position
122 * @param {Number} top The target element top position
123 * @param {Number} width The target element width
124 * @param {Number} height The target element height
126 realign : function(l, t, w, h){
130 var a = this.adjusts, d = this.el.dom, s = d.style;
132 s.left = (l+a.l)+"px";
133 s.top = (t+a.t)+"px";
134 var sw = (w+a.w), sh = (h+a.h), sws = sw +"px", shs = sh + "px";
135 if(s.width != sws || s.height != shs){
139 var cn = d.childNodes;
140 var sww = Math.max(0, (sw-12))+"px";
141 cn[0].childNodes[1].style.width = sww;
142 cn[1].childNodes[1].style.width = sww;
143 cn[2].childNodes[1].style.width = sww;
144 cn[1].style.height = Math.max(0, (sh-12))+"px";
154 this.el.dom.style.display = "none";
155 Ext.Shadow.Pool.push(this.el);
161 * Adjust the z-index of this shadow
162 * @param {Number} zindex The new z-index
164 setZIndex : function(z){
167 this.el.setStyle("z-index", z);
172 // Private utility class that manages the internal Shadow cache
173 Ext.Shadow.Pool = function(){
175 var markup = Ext.isIE ?
176 '<div class="x-ie-shadow"></div>' :
177 '<div class="x-shadow"><div class="xst"><div class="xstl"></div><div class="xstc"></div><div class="xstr"></div></div><div class="xsc"><div class="xsml"></div><div class="xsmc"></div><div class="xsmr"></div></div><div class="xsb"><div class="xsbl"></div><div class="xsbc"></div><div class="xsbr"></div></div></div>';
182 sh = Ext.get(Ext.DomHelper.insertHtml("beforeBegin", document.body.firstChild, markup));
183 sh.autoBoxAdjust = false;