4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-Shadow'>/**
19 </span> * @class Ext.Shadow
20 * Simple class that can provide a shadow effect for any element. Note that the element MUST be absolutely positioned,
21 * and the shadow does not provide any shimming. This should be used only in simple cases -- for more advanced
22 * functionality that can also provide the same shadow effect, see the {@link Ext.Layer} class.
24 Ext.define('Ext.Shadow', {
25 requires: ['Ext.ShadowPool'],
27 <span id='Ext-Shadow-method-constructor'> /**
28 </span> * Creates new Shadow.
29 * @param {Object} config (optional) Config object.
31 constructor: function(config) {
39 Ext.apply(me, config);
40 if (!Ext.isString(me.mode)) {
41 me.mode = me.defaultMode;
44 rad = Math.floor(offset / 2);
46 switch (me.mode.toLowerCase()) {
47 // all this hideous nonsense calculates the various offsets for shadows
48 case "drop":
49 if (Ext.supports.CSS3BoxShadow) {
50 adjusts.w = adjusts.h = -offset;
51 adjusts.l = adjusts.t = offset;
54 adjusts.l = adjusts.t = offset;
57 adjusts.l -= offset + rad;
58 adjusts.t -= offset + rad;
65 case "sides":
66 if (Ext.supports.CSS3BoxShadow) {
69 adjusts.l = adjusts.w = 0;
71 adjusts.w = (offset * 2);
73 adjusts.t = offset - 1;
75 adjusts.l -= (offset - rad);
76 adjusts.t -= offset + rad;
78 adjusts.w -= (offset - rad) * 2;
84 case "frame":
85 if (Ext.supports.CSS3BoxShadow) {
86 adjusts.l = adjusts.w = adjusts.t = 0;
88 adjusts.w = adjusts.h = (offset * 2);
89 adjusts.l = adjusts.t = -offset;
93 adjusts.l -= (offset - rad);
94 adjusts.t -= (offset - rad);
96 adjusts.w -= (offset + rad + 1);
97 adjusts.h -= (offset + rad);
103 me.adjusts = adjusts;
106 <span id='Ext-Shadow-cfg-mode'> /**
107 </span> * @cfg {String} mode
108 * The shadow display mode. Supports the following options:<div class="mdetail-params"><ul>
109 * <li><b><tt>sides</tt></b> : Shadow displays on both sides and bottom only</li>
110 * <li><b><tt>frame</tt></b> : Shadow displays equally on all four sides</li>
111 * <li><b><tt>drop</tt></b> : Traditional bottom-right drop shadow</li>
112 * </ul></div>
114 <span id='Ext-Shadow-cfg-offset'> /**
115 </span> * @cfg {Number} offset
116 * The number of pixels to offset the shadow from the element
121 defaultMode: "drop",
123 <span id='Ext-Shadow-method-show'> /**
124 </span> * Displays the shadow under the target element
125 * @param {String/HTMLElement/Ext.Element} targetEl The id or element under which the shadow should display
127 show: function(target) {
131 target = Ext.get(target);
133 me.el = Ext.ShadowPool.pull();
134 if (me.el.dom.nextSibling != target.dom) {
135 me.el.insertBefore(target);
138 index = (parseInt(target.getStyle("z-index"), 10) - 1) || 0;
139 me.el.setStyle("z-index", me.zIndex || index);
140 if (Ext.isIE && !Ext.supports.CSS3BoxShadow) {
141 me.el.dom.style.filter = "progid:DXImageTransform.Microsoft.alpha(opacity=" + me.opacity + ") progid:DXImageTransform.Microsoft.Blur(pixelradius=" + (me.offset) + ")";
144 target.getLeft(true),
146 target.dom.offsetWidth,
147 target.dom.offsetHeight
149 me.el.dom.style.display = "block";
152 <span id='Ext-Shadow-method-isVisible'> /**
153 </span> * Returns true if the shadow is visible, else false
155 isVisible: function() {
156 return this.el ? true: false;
159 <span id='Ext-Shadow-method-realign'> /**
160 </span> * Direct alignment when values are already available. Show must be called at least once before
161 * calling this method to ensure it is initialized.
162 * @param {Number} left The target element left position
163 * @param {Number} top The target element top position
164 * @param {Number} width The target element width
165 * @param {Number} height The target element height
167 realign: function(l, t, targetWidth, targetHeight) {
171 var adjusts = this.adjusts,
173 targetStyle = d.style,
181 targetStyle.left = (l + adjusts.l) + "px";
182 targetStyle.top = (t + adjusts.t) + "px";
183 shadowWidth = Math.max(targetWidth + adjusts.w, 0);
184 shadowHeight = Math.max(targetHeight + adjusts.h, 0);
185 sws = shadowWidth + "px";
186 shs = shadowHeight + "px";
187 if (targetStyle.width != sws || targetStyle.height != shs) {
188 targetStyle.width = sws;
189 targetStyle.height = shs;
190 if (Ext.supports.CSS3BoxShadow) {
191 targetStyle.boxShadow = '0 0 ' + this.offset + 'px 0 #888';
194 // Adjust the 9 point framed element to poke out on the required sides
197 sww = Math.max(0, (shadowWidth - 12)) + "px";
198 cn[0].childNodes[1].style.width = sww;
199 cn[1].childNodes[1].style.width = sww;
200 cn[2].childNodes[1].style.width = sww;
201 cn[1].style.height = Math.max(0, (shadowHeight - 12)) + "px";
207 <span id='Ext-Shadow-method-hide'> /**
208 </span> * Hides this shadow
214 me.el.dom.style.display = "none";
215 Ext.ShadowPool.push(me.el);
220 <span id='Ext-Shadow-method-setZIndex'> /**
221 </span> * Adjust the z-index of this shadow
222 * @param {Number} zindex The new z-index
224 setZIndex: function(z) {
227 this.el.setStyle("z-index", z);
231 <span id='Ext-Shadow-method-setOpacity'> /**
232 </span> * Sets the opacity of the shadow
233 * @param {Number} opacity The opacity
235 setOpacity: function(opacity){
237 if (Ext.isIE && !Ext.supports.CSS3BoxShadow) {
238 opacity = Math.floor(opacity * 100 / 2) / 100;
240 this.opacity = opacity;
241 this.el.setOpacity(opacity);