4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../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-method-constructor'><span id='Ext-Shadow'>/**
19 </span></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.
25 * @param {Object} config The config object
27 Ext.define('Ext.Shadow', {
28 requires: ['Ext.ShadowPool'],
30 constructor: function(config) {
31 Ext.apply(this, config);
32 if (typeof this.mode != "string") {
33 this.mode = this.defaultMode;
35 var offset = this.offset,
39 rad = Math.floor(this.offset / 2);
41 switch (this.mode.toLowerCase()) {
42 // all this hideous nonsense calculates the various offsets for shadows
43 case "drop":
44 if (Ext.supports.CSS3BoxShadow) {
45 adjusts.w = adjusts.h = -offset;
46 adjusts.l = adjusts.t = offset;
49 adjusts.l = adjusts.t = offset;
52 adjusts.l -= offset + rad;
53 adjusts.t -= offset + rad;
60 case "sides":
61 if (Ext.supports.CSS3BoxShadow) {
64 adjusts.l = adjusts.w = 0;
66 adjusts.w = (offset * 2);
68 adjusts.t = offset - 1;
70 adjusts.l -= (offset - rad);
71 adjusts.t -= offset + rad;
73 adjusts.w -= (offset - rad) * 2;
79 case "frame":
80 if (Ext.supports.CSS3BoxShadow) {
81 adjusts.l = adjusts.w = adjusts.t = 0;
83 adjusts.w = adjusts.h = (offset * 2);
84 adjusts.l = adjusts.t = -offset;
88 adjusts.l -= (offset - rad);
89 adjusts.t -= (offset - rad);
91 adjusts.w -= (offset + rad + 1);
92 adjusts.h -= (offset + rad);
98 this.adjusts = adjusts;
101 <span id='Ext-Shadow-cfg-mode'> /**
102 </span> * @cfg {String} mode
103 * The shadow display mode. Supports the following options:<div class="mdetail-params"><ul>
104 * <li><b><tt>sides</tt></b> : Shadow displays on both sides and bottom only</li>
105 * <li><b><tt>frame</tt></b> : Shadow displays equally on all four sides</li>
106 * <li><b><tt>drop</tt></b> : Traditional bottom-right drop shadow</li>
107 * </ul></div>
109 <span id='Ext-Shadow-cfg-offset'> /**
110 </span> * @cfg {String} offset
111 * The number of pixels to offset the shadow from the element (defaults to <tt>4</tt>)
116 defaultMode: "drop",
118 <span id='Ext-Shadow-method-show'> /**
119 </span> * Displays the shadow under the target element
120 * @param {Mixed} targetEl The id or element under which the shadow should display
122 show: function(target) {
123 target = Ext.get(target);
125 this.el = Ext.ShadowPool.pull();
126 if (this.el.dom.nextSibling != target.dom) {
127 this.el.insertBefore(target);
130 this.el.setStyle("z-index", this.zIndex || parseInt(target.getStyle("z-index"), 10) - 1);
131 if (Ext.isIE && !Ext.supports.CSS3BoxShadow) {
132 this.el.dom.style.filter = "progid:DXImageTransform.Microsoft.alpha(opacity=50) progid:DXImageTransform.Microsoft.Blur(pixelradius=" + (this.offset) + ")";
135 target.getLeft(true),
140 this.el.dom.style.display = "block";
143 <span id='Ext-Shadow-method-isVisible'> /**
144 </span> * Returns true if the shadow is visible, else false
146 isVisible: function() {
147 return this.el ? true: false;
150 <span id='Ext-Shadow-method-realign'> /**
151 </span> * Direct alignment when values are already available. Show must be called at least once before
152 * calling this method to ensure it is initialized.
153 * @param {Number} left The target element left position
154 * @param {Number} top The target element top position
155 * @param {Number} width The target element width
156 * @param {Number} height The target element height
158 realign: function(l, t, targetWidth, targetHeight) {
162 var adjusts = this.adjusts,
164 targetStyle = d.style,
172 targetStyle.left = (l + adjusts.l) + "px";
173 targetStyle.top = (t + adjusts.t) + "px";
174 shadowWidth = Math.max(targetWidth + adjusts.w, 0);
175 shadowHeight = Math.max(targetHeight + adjusts.h, 0);
176 sws = shadowWidth + "px";
177 shs = shadowHeight + "px";
178 if (targetStyle.width != sws || targetStyle.height != shs) {
179 targetStyle.width = sws;
180 targetStyle.height = shs;
181 if (Ext.supports.CSS3BoxShadow) {
182 targetStyle.boxShadow = '0 0 ' + this.offset + 'px 0 #888';
185 // Adjust the 9 point framed element to poke out on the required sides
188 sww = Math.max(0, (shadowWidth - 12)) + "px";
189 cn[0].childNodes[1].style.width = sww;
190 cn[1].childNodes[1].style.width = sww;
191 cn[2].childNodes[1].style.width = sww;
192 cn[1].style.height = Math.max(0, (shadowHeight - 12)) + "px";
198 <span id='Ext-Shadow-method-hide'> /**
199 </span> * Hides this shadow
203 this.el.dom.style.display = "none";
204 Ext.ShadowPool.push(this.el);
209 <span id='Ext-Shadow-method-setZIndex'> /**
210 </span> * Adjust the z-index of this shadow
211 * @param {Number} zindex The new z-index
213 setZIndex: function(z) {
216 this.el.setStyle("z-index", z);