4 * Copyright(c) 2006-2007, Ext JS, LLC.
6 * Originally Released Under LGPL - original licence link has changed is not relivant.
9 * <script type="text/javascript">
15 * Simple class that can provide a shadow effect for any element. Note that the element MUST be absolutely positioned,
16 * and the shadow does not provide any shimming. This should be used only in simple cases -- for more advanced
17 * functionality that can also provide the same shadow effect, see the {@link Roo.Layer} class.
20 * @param {Object} config The config object
22 Roo.Shadow = function(config){
23 Roo.apply(this, config);
24 if(typeof this.mode != "string"){
25 this.mode = this.defaultMode;
27 var o = this.offset, a = {h: 0};
28 var rad = Math.floor(this.offset/2);
29 switch(this.mode.toLowerCase()){ // all this hideous nonsense calculates the various offsets for shadows
35 a.l -= this.offset + rad;
36 a.t -= this.offset + rad;
47 a.l -= (this.offset - rad);
48 a.t -= this.offset + rad;
50 a.w -= (this.offset - rad)*2;
61 a.l -= (this.offset - rad);
62 a.t -= (this.offset - rad);
64 a.w -= (this.offset + rad + 1);
65 a.h -= (this.offset + rad);
74 Roo.Shadow.prototype = {
77 * The shadow display mode. Supports the following options:<br />
78 * sides: Shadow displays on both sides and bottom only<br />
79 * frame: Shadow displays equally on all four sides<br />
80 * drop: Traditional bottom-right drop shadow (default)
84 * @cfg {String} offset
85 * The number of pixels to offset the shadow from the element (defaults to 4)
93 * Displays the shadow under the target element
94 * @param {String/HTMLElement/Element} targetEl The id or element under which the shadow should display
96 show : function(target){
97 target = Roo.get(target);
99 this.el = Roo.Shadow.Pool.pull();
100 if(this.el.dom.nextSibling != target.dom){
101 this.el.insertBefore(target);
104 this.el.setStyle("z-index", this.zIndex || parseInt(target.getStyle("z-index"), 10)-1);
106 this.el.dom.style.filter="progid:DXImageTransform.Microsoft.alpha(opacity=50) progid:DXImageTransform.Microsoft.Blur(pixelradius="+(this.offset)+")";
109 target.getLeft(true),
114 this.el.dom.style.display = "block";
118 * Returns true if the shadow is visible, else false
120 isVisible : function(){
121 return this.el ? true : false;
125 * Direct alignment when values are already available. Show must be called at least once before
126 * calling this method to ensure it is initialized.
127 * @param {Number} left The target element left position
128 * @param {Number} top The target element top position
129 * @param {Number} width The target element width
130 * @param {Number} height The target element height
132 realign : function(l, t, w, h){
136 var a = this.adjusts, d = this.el.dom, s = d.style;
138 s.left = (l+a.l)+"px";
139 s.top = (t+a.t)+"px";
140 var sw = (w+a.w), sh = (h+a.h), sws = sw +"px", shs = sh + "px";
142 if(s.width != sws || s.height != shs){
146 var cn = d.childNodes;
147 var sww = Math.max(0, (sw-12))+"px";
148 cn[0].childNodes[1].style.width = sww;
149 cn[1].childNodes[1].style.width = sww;
150 cn[2].childNodes[1].style.width = sww;
151 cn[1].style.height = Math.max(0, (sh-12))+"px";
161 this.el.dom.style.display = "none";
162 Roo.Shadow.Pool.push(this.el);
168 * Adjust the z-index of this shadow
169 * @param {Number} zindex The new z-index
171 setZIndex : function(z){
174 this.el.setStyle("z-index", z);
179 // Private utility class that manages the internal Shadow cache
180 Roo.Shadow.Pool = function(){
182 var markup = Roo.isIE ?
183 '<div class="x-ie-shadow"></div>' :
184 '<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>';
189 sh = Roo.get(Roo.DomHelper.insertHtml("beforeBegin", document.body.firstChild, markup));
190 sh.autoBoxAdjust = false;