3 * Simple class that can provide a shadow effect for any element. Note that the element MUST be absolutely positioned,
4 * and the shadow does not provide any shimming. This should be used only in simple cases -- for more advanced
5 * functionality that can also provide the same shadow effect, see the {@link Ext.Layer} class.
8 * @param {Object} config The config object
10 Ext.define('Ext.Shadow', {
11 requires: ['Ext.ShadowPool'],
13 constructor: function(config) {
14 Ext.apply(this, config);
15 if (typeof this.mode != "string") {
16 this.mode = this.defaultMode;
18 var offset = this.offset,
22 rad = Math.floor(this.offset / 2);
24 switch (this.mode.toLowerCase()) {
25 // all this hideous nonsense calculates the various offsets for shadows
27 if (Ext.supports.CSS3BoxShadow) {
28 adjusts.w = adjusts.h = -offset;
29 adjusts.l = adjusts.t = offset;
32 adjusts.l = adjusts.t = offset;
35 adjusts.l -= offset + rad;
36 adjusts.t -= offset + rad;
44 if (Ext.supports.CSS3BoxShadow) {
47 adjusts.l = adjusts.w = 0;
49 adjusts.w = (offset * 2);
51 adjusts.t = offset - 1;
53 adjusts.l -= (offset - rad);
54 adjusts.t -= offset + rad;
56 adjusts.w -= (offset - rad) * 2;
63 if (Ext.supports.CSS3BoxShadow) {
64 adjusts.l = adjusts.w = adjusts.t = 0;
66 adjusts.w = adjusts.h = (offset * 2);
67 adjusts.l = adjusts.t = -offset;
71 adjusts.l -= (offset - rad);
72 adjusts.t -= (offset - rad);
74 adjusts.w -= (offset + rad + 1);
75 adjusts.h -= (offset + rad);
81 this.adjusts = adjusts;
86 * The shadow display mode. Supports the following options:<div class="mdetail-params"><ul>
87 * <li><b><tt>sides</tt></b> : Shadow displays on both sides and bottom only</li>
88 * <li><b><tt>frame</tt></b> : Shadow displays equally on all four sides</li>
89 * <li><b><tt>drop</tt></b> : Traditional bottom-right drop shadow</li>
93 * @cfg {String} offset
94 * The number of pixels to offset the shadow from the element (defaults to <tt>4</tt>)
102 * Displays the shadow under the target element
103 * @param {Mixed} targetEl The id or element under which the shadow should display
105 show: function(target) {
106 target = Ext.get(target);
108 this.el = Ext.ShadowPool.pull();
109 if (this.el.dom.nextSibling != target.dom) {
110 this.el.insertBefore(target);
113 this.el.setStyle("z-index", this.zIndex || parseInt(target.getStyle("z-index"), 10) - 1);
114 if (Ext.isIE && !Ext.supports.CSS3BoxShadow) {
115 this.el.dom.style.filter = "progid:DXImageTransform.Microsoft.alpha(opacity=50) progid:DXImageTransform.Microsoft.Blur(pixelradius=" + (this.offset) + ")";
118 target.getLeft(true),
123 this.el.dom.style.display = "block";
127 * Returns true if the shadow is visible, else false
129 isVisible: function() {
130 return this.el ? true: false;
134 * Direct alignment when values are already available. Show must be called at least once before
135 * calling this method to ensure it is initialized.
136 * @param {Number} left The target element left position
137 * @param {Number} top The target element top position
138 * @param {Number} width The target element width
139 * @param {Number} height The target element height
141 realign: function(l, t, targetWidth, targetHeight) {
145 var adjusts = this.adjusts,
147 targetStyle = d.style,
155 targetStyle.left = (l + adjusts.l) + "px";
156 targetStyle.top = (t + adjusts.t) + "px";
157 shadowWidth = Math.max(targetWidth + adjusts.w, 0);
158 shadowHeight = Math.max(targetHeight + adjusts.h, 0);
159 sws = shadowWidth + "px";
160 shs = shadowHeight + "px";
161 if (targetStyle.width != sws || targetStyle.height != shs) {
162 targetStyle.width = sws;
163 targetStyle.height = shs;
164 if (Ext.supports.CSS3BoxShadow) {
165 targetStyle.boxShadow = '0 0 ' + this.offset + 'px 0 #888';
168 // Adjust the 9 point framed element to poke out on the required sides
171 sww = Math.max(0, (shadowWidth - 12)) + "px";
172 cn[0].childNodes[1].style.width = sww;
173 cn[1].childNodes[1].style.width = sww;
174 cn[2].childNodes[1].style.width = sww;
175 cn[1].style.height = Math.max(0, (shadowHeight - 12)) + "px";
186 this.el.dom.style.display = "none";
187 Ext.ShadowPool.push(this.el);
193 * Adjust the z-index of this shadow
194 * @param {Number} zindex The new z-index
196 setZIndex: function(z) {
199 this.el.setStyle("z-index", z);