3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
17 * Simple class that can provide a shadow effect for any element. Note that the element MUST be absolutely positioned,
18 * and the shadow does not provide any shimming. This should be used only in simple cases -- for more advanced
19 * functionality that can also provide the same shadow effect, see the {@link Ext.Layer} class.
21 Ext.define('Ext.Shadow', {
22 requires: ['Ext.ShadowPool'],
26 * @param {Object} config (optional) Config object.
28 constructor: function(config) {
29 Ext.apply(this, config);
30 if (typeof this.mode != "string") {
31 this.mode = this.defaultMode;
33 var offset = this.offset,
37 rad = Math.floor(this.offset / 2);
39 switch (this.mode.toLowerCase()) {
40 // all this hideous nonsense calculates the various offsets for shadows
42 if (Ext.supports.CSS3BoxShadow) {
43 adjusts.w = adjusts.h = -offset;
44 adjusts.l = adjusts.t = offset;
47 adjusts.l = adjusts.t = offset;
50 adjusts.l -= offset + rad;
51 adjusts.t -= offset + rad;
59 if (Ext.supports.CSS3BoxShadow) {
62 adjusts.l = adjusts.w = 0;
64 adjusts.w = (offset * 2);
66 adjusts.t = offset - 1;
68 adjusts.l -= (offset - rad);
69 adjusts.t -= offset + rad;
71 adjusts.w -= (offset - rad) * 2;
78 if (Ext.supports.CSS3BoxShadow) {
79 adjusts.l = adjusts.w = adjusts.t = 0;
81 adjusts.w = adjusts.h = (offset * 2);
82 adjusts.l = adjusts.t = -offset;
86 adjusts.l -= (offset - rad);
87 adjusts.t -= (offset - rad);
89 adjusts.w -= (offset + rad + 1);
90 adjusts.h -= (offset + rad);
96 this.adjusts = adjusts;
101 * The shadow display mode. Supports the following options:<div class="mdetail-params"><ul>
102 * <li><b><tt>sides</tt></b> : Shadow displays on both sides and bottom only</li>
103 * <li><b><tt>frame</tt></b> : Shadow displays equally on all four sides</li>
104 * <li><b><tt>drop</tt></b> : Traditional bottom-right drop shadow</li>
108 * @cfg {String} offset
109 * The number of pixels to offset the shadow from the element (defaults to <tt>4</tt>)
117 * Displays the shadow under the target element
118 * @param {Mixed} targetEl The id or element under which the shadow should display
120 show: function(target) {
121 target = Ext.get(target);
123 this.el = Ext.ShadowPool.pull();
124 if (this.el.dom.nextSibling != target.dom) {
125 this.el.insertBefore(target);
128 this.el.setStyle("z-index", this.zIndex || parseInt(target.getStyle("z-index"), 10) - 1);
129 if (Ext.isIE && !Ext.supports.CSS3BoxShadow) {
130 this.el.dom.style.filter = "progid:DXImageTransform.Microsoft.alpha(opacity=50) progid:DXImageTransform.Microsoft.Blur(pixelradius=" + (this.offset) + ")";
133 target.getLeft(true),
138 this.el.dom.style.display = "block";
142 * Returns true if the shadow is visible, else false
144 isVisible: function() {
145 return this.el ? true: false;
149 * Direct alignment when values are already available. Show must be called at least once before
150 * calling this method to ensure it is initialized.
151 * @param {Number} left The target element left position
152 * @param {Number} top The target element top position
153 * @param {Number} width The target element width
154 * @param {Number} height The target element height
156 realign: function(l, t, targetWidth, targetHeight) {
160 var adjusts = this.adjusts,
162 targetStyle = d.style,
170 targetStyle.left = (l + adjusts.l) + "px";
171 targetStyle.top = (t + adjusts.t) + "px";
172 shadowWidth = Math.max(targetWidth + adjusts.w, 0);
173 shadowHeight = Math.max(targetHeight + adjusts.h, 0);
174 sws = shadowWidth + "px";
175 shs = shadowHeight + "px";
176 if (targetStyle.width != sws || targetStyle.height != shs) {
177 targetStyle.width = sws;
178 targetStyle.height = shs;
179 if (Ext.supports.CSS3BoxShadow) {
180 targetStyle.boxShadow = '0 0 ' + this.offset + 'px 0 #888';
183 // Adjust the 9 point framed element to poke out on the required sides
186 sww = Math.max(0, (shadowWidth - 12)) + "px";
187 cn[0].childNodes[1].style.width = sww;
188 cn[1].childNodes[1].style.width = sww;
189 cn[2].childNodes[1].style.width = sww;
190 cn[1].style.height = Math.max(0, (shadowHeight - 12)) + "px";
201 this.el.dom.style.display = "none";
202 Ext.ShadowPool.push(this.el);
208 * Adjust the z-index of this shadow
209 * @param {Number} zindex The new z-index
211 setZIndex: function(z) {
214 this.el.setStyle("z-index", z);