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;
25 rad = Math.floor(this.offset / 2);
26 switch (this.mode.toLowerCase()) {
27 // all this hideous nonsense calculates the various offsets for shadows
33 a.l -= this.offset + rad;
34 a.t -= this.offset + rad;
45 a.l -= (this.offset - rad);
46 a.t -= this.offset + rad;
48 a.w -= (this.offset - rad) * 2;
59 a.l -= (this.offset - rad);
60 a.t -= (this.offset - rad);
62 a.w -= (this.offset + rad + 1);
63 a.h -= (this.offset + rad);
72 Ext.Shadow.prototype = {
75 * The shadow display mode. Supports the following options:<div class="mdetail-params"><ul>
76 * <li><b><tt>sides</tt></b> : Shadow displays on both sides and bottom only</li>
77 * <li><b><tt>frame</tt></b> : Shadow displays equally on all four sides</li>
78 * <li><b><tt>drop</tt></b> : Traditional bottom-right drop shadow</li>
82 * @cfg {String} offset
83 * The number of pixels to offset the shadow from the element (defaults to <tt>4</tt>)
91 * Displays the shadow under the target element
92 * @param {Mixed} targetEl The id or element under which the shadow should display
94 show: function(target) {
95 target = Ext.get(target);
97 this.el = Ext.Shadow.Pool.pull();
98 if (this.el.dom.nextSibling != target.dom) {
99 this.el.insertBefore(target);
102 this.el.setStyle("z-index", this.zIndex || parseInt(target.getStyle("z-index"), 10) - 1);
104 this.el.dom.style.filter = "progid:DXImageTransform.Microsoft.alpha(opacity=50) progid:DXImageTransform.Microsoft.Blur(pixelradius=" + (this.offset) + ")";
107 target.getLeft(true),
112 this.el.dom.style.display = "block";
116 * Returns true if the shadow is visible, else false
118 isVisible: function() {
119 return this.el ? true: false;
123 * Direct alignment when values are already available. Show must be called at least once before
124 * calling this method to ensure it is initialized.
125 * @param {Number} left The target element left position
126 * @param {Number} top The target element top position
127 * @param {Number} width The target element width
128 * @param {Number} height The target element height
130 realign: function(l, t, w, h) {
134 var a = this.adjusts,
144 s.left = (l + a.l) + "px";
145 s.top = (t + a.t) + "px";
146 if (s.width != sws || s.height != shs) {
151 sww = Math.max(0, (sw - 12)) + "px";
152 cn[0].childNodes[1].style.width = sww;
153 cn[1].childNodes[1].style.width = sww;
154 cn[2].childNodes[1].style.width = sww;
155 cn[1].style.height = Math.max(0, (sh - 12)) + "px";
165 this.el.dom.style.display = "none";
166 Ext.Shadow.Pool.push(this.el);
172 * Adjust the z-index of this shadow
173 * @param {Number} zindex The new z-index
175 setZIndex: function(z) {
178 this.el.setStyle("z-index", z);
183 // Private utility class that manages the internal Shadow cache
184 Ext.Shadow.Pool = function() {
187 '<div class="x-ie-shadow"></div>':
188 '<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>';
193 sh = Ext.get(Ext.DomHelper.insertHtml("beforeBegin", document.body.firstChild, markup));
194 sh.autoBoxAdjust = false;