3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js"><div id="cls-Ext.Shadow"></div>/**
10 * Simple class that can provide a shadow effect for any element. Note that the element MUST be absolutely positioned,
11 * and the shadow does not provide any shimming. This should be used only in simple cases -- for more advanced
12 * functionality that can also provide the same shadow effect, see the {@link Ext.Layer} class.
15 * @param {Object} config The config object
17 Ext.Shadow = function(config){
18 Ext.apply(this, config);
19 if(typeof this.mode != "string"){
20 this.mode = this.defaultMode;
22 var o = this.offset, a = {h: 0};
23 var rad = Math.floor(this.offset/2);
24 switch(this.mode.toLowerCase()){ // all this hideous nonsense calculates the various offsets for shadows
30 a.l -= this.offset + rad;
31 a.t -= this.offset + rad;
42 a.l -= (this.offset - rad);
43 a.t -= this.offset + rad;
45 a.w -= (this.offset - rad)*2;
56 a.l -= (this.offset - rad);
57 a.t -= (this.offset - rad);
59 a.w -= (this.offset + rad + 1);
60 a.h -= (this.offset + rad);
69 Ext.Shadow.prototype = {
70 <div id="cfg-Ext.Shadow-mode"></div>/**
72 * The shadow display mode. Supports the following options:<div class="mdetail-params"><ul>
73 * <li><b><tt>sides</tt></b> : Shadow displays on both sides and bottom only</li>
74 * <li><b><tt>frame</tt></b> : Shadow displays equally on all four sides</li>
75 * <li><b><tt>drop</tt></b> : Traditional bottom-right drop shadow</li>
78 <div id="cfg-Ext.Shadow-offset"></div>/**
79 * @cfg {String} offset
80 * The number of pixels to offset the shadow from the element (defaults to <tt>4</tt>)
87 <div id="method-Ext.Shadow-show"></div>/**
88 * Displays the shadow under the target element
89 * @param {Mixed} targetEl The id or element under which the shadow should display
91 show : function(target){
92 target = Ext.get(target);
94 this.el = Ext.Shadow.Pool.pull();
95 if(this.el.dom.nextSibling != target.dom){
96 this.el.insertBefore(target);
99 this.el.setStyle("z-index", this.zIndex || parseInt(target.getStyle("z-index"), 10)-1);
101 this.el.dom.style.filter="progid:DXImageTransform.Microsoft.alpha(opacity=50) progid:DXImageTransform.Microsoft.Blur(pixelradius="+(this.offset)+")";
104 target.getLeft(true),
109 this.el.dom.style.display = "block";
112 <div id="method-Ext.Shadow-isVisible"></div>/**
113 * Returns true if the shadow is visible, else false
115 isVisible : function(){
116 return this.el ? true : false;
119 <div id="method-Ext.Shadow-realign"></div>/**
120 * Direct alignment when values are already available. Show must be called at least once before
121 * calling this method to ensure it is initialized.
122 * @param {Number} left The target element left position
123 * @param {Number} top The target element top position
124 * @param {Number} width The target element width
125 * @param {Number} height The target element height
127 realign : function(l, t, w, h){
131 var a = this.adjusts, d = this.el.dom, s = d.style;
133 s.left = (l+a.l)+"px";
134 s.top = (t+a.t)+"px";
135 var sw = (w+a.w), sh = (h+a.h), sws = sw +"px", shs = sh + "px";
136 if(s.width != sws || s.height != shs){
140 var cn = d.childNodes;
141 var sww = Math.max(0, (sw-12))+"px";
142 cn[0].childNodes[1].style.width = sww;
143 cn[1].childNodes[1].style.width = sww;
144 cn[2].childNodes[1].style.width = sww;
145 cn[1].style.height = Math.max(0, (sh-12))+"px";
150 <div id="method-Ext.Shadow-hide"></div>/**
155 this.el.dom.style.display = "none";
156 Ext.Shadow.Pool.push(this.el);
161 <div id="method-Ext.Shadow-setZIndex"></div>/**
162 * Adjust the z-index of this shadow
163 * @param {Number} zindex The new z-index
165 setZIndex : function(z){
168 this.el.setStyle("z-index", z);
173 // Private utility class that manages the internal Shadow cache
174 Ext.Shadow.Pool = function(){
176 var markup = Ext.isIE ?
177 '<div class="x-ie-shadow"></div>' :
178 '<div class="x-shadow"><div class="xst"><div class="xstl"></div><div class="xstc"></div><div class="xstr"></div></div><div class="xsc"><div class="xsml"></div><div class="xsmc"></div><div class="xsmr"></div></div><div class="xsb"><div class="xsbl"></div><div class="xsbc"></div><div class="xsbr"></div></div></div>';
183 sh = Ext.get(Ext.DomHelper.insertHtml("beforeBegin", document.body.firstChild, markup));
184 sh.autoBoxAdjust = false;