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'>/**
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) {
32 Ext.apply(this, config);
33 if (typeof this.mode != "string") {
34 this.mode = this.defaultMode;
36 var offset = this.offset,
40 rad = Math.floor(this.offset / 2);
42 switch (this.mode.toLowerCase()) {
43 // all this hideous nonsense calculates the various offsets for shadows
44 case "drop":
45 if (Ext.supports.CSS3BoxShadow) {
46 adjusts.w = adjusts.h = -offset;
47 adjusts.l = adjusts.t = offset;
50 adjusts.l = adjusts.t = offset;
53 adjusts.l -= offset + rad;
54 adjusts.t -= offset + rad;
61 case "sides":
62 if (Ext.supports.CSS3BoxShadow) {
65 adjusts.l = adjusts.w = 0;
67 adjusts.w = (offset * 2);
69 adjusts.t = offset - 1;
71 adjusts.l -= (offset - rad);
72 adjusts.t -= offset + rad;
74 adjusts.w -= (offset - rad) * 2;
80 case "frame":
81 if (Ext.supports.CSS3BoxShadow) {
82 adjusts.l = adjusts.w = adjusts.t = 0;
84 adjusts.w = adjusts.h = (offset * 2);
85 adjusts.l = adjusts.t = -offset;
89 adjusts.l -= (offset - rad);
90 adjusts.t -= (offset - rad);
92 adjusts.w -= (offset + rad + 1);
93 adjusts.h -= (offset + rad);
99 this.adjusts = adjusts;
102 <span id='Ext-Shadow-cfg-mode'> /**
103 </span> * @cfg {String} mode
104 * The shadow display mode. Supports the following options:<div class="mdetail-params"><ul>
105 * <li><b><tt>sides</tt></b> : Shadow displays on both sides and bottom only</li>
106 * <li><b><tt>frame</tt></b> : Shadow displays equally on all four sides</li>
107 * <li><b><tt>drop</tt></b> : Traditional bottom-right drop shadow</li>
108 * </ul></div>
110 <span id='Ext-Shadow-cfg-offset'> /**
111 </span> * @cfg {String} offset
112 * The number of pixels to offset the shadow from the element (defaults to <tt>4</tt>)
117 defaultMode: "drop",
119 <span id='Ext-Shadow-method-show'> /**
120 </span> * Displays the shadow under the target element
121 * @param {Mixed} targetEl The id or element under which the shadow should display
123 show: function(target) {
124 target = Ext.get(target);
126 this.el = Ext.ShadowPool.pull();
127 if (this.el.dom.nextSibling != target.dom) {
128 this.el.insertBefore(target);
131 this.el.setStyle("z-index", this.zIndex || parseInt(target.getStyle("z-index"), 10) - 1);
132 if (Ext.isIE && !Ext.supports.CSS3BoxShadow) {
133 this.el.dom.style.filter = "progid:DXImageTransform.Microsoft.alpha(opacity=50) progid:DXImageTransform.Microsoft.Blur(pixelradius=" + (this.offset) + ")";
136 target.getLeft(true),
141 this.el.dom.style.display = "block";
144 <span id='Ext-Shadow-method-isVisible'> /**
145 </span> * Returns true if the shadow is visible, else false
147 isVisible: function() {
148 return this.el ? true: false;
151 <span id='Ext-Shadow-method-realign'> /**
152 </span> * Direct alignment when values are already available. Show must be called at least once before
153 * calling this method to ensure it is initialized.
154 * @param {Number} left The target element left position
155 * @param {Number} top The target element top position
156 * @param {Number} width The target element width
157 * @param {Number} height The target element height
159 realign: function(l, t, targetWidth, targetHeight) {
163 var adjusts = this.adjusts,
165 targetStyle = d.style,
173 targetStyle.left = (l + adjusts.l) + "px";
174 targetStyle.top = (t + adjusts.t) + "px";
175 shadowWidth = Math.max(targetWidth + adjusts.w, 0);
176 shadowHeight = Math.max(targetHeight + adjusts.h, 0);
177 sws = shadowWidth + "px";
178 shs = shadowHeight + "px";
179 if (targetStyle.width != sws || targetStyle.height != shs) {
180 targetStyle.width = sws;
181 targetStyle.height = shs;
182 if (Ext.supports.CSS3BoxShadow) {
183 targetStyle.boxShadow = '0 0 ' + this.offset + 'px 0 #888';
186 // Adjust the 9 point framed element to poke out on the required sides
189 sww = Math.max(0, (shadowWidth - 12)) + "px";
190 cn[0].childNodes[1].style.width = sww;
191 cn[1].childNodes[1].style.width = sww;
192 cn[2].childNodes[1].style.width = sww;
193 cn[1].style.height = Math.max(0, (shadowHeight - 12)) + "px";
199 <span id='Ext-Shadow-method-hide'> /**
200 </span> * Hides this shadow
204 this.el.dom.style.display = "none";
205 Ext.ShadowPool.push(this.el);
210 <span id='Ext-Shadow-method-setZIndex'> /**
211 </span> * Adjust the z-index of this shadow
212 * @param {Number} zindex The new z-index
214 setZIndex: function(z) {
217 this.el.setStyle("z-index", z);