3 <title>The source code</title>
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 <body onload="prettyPrint();">
8 <pre class="prettyprint lang-js">/*!
10 * Copyright(c) 2006-2009 Ext JS, LLC
12 * http://www.extjs.com/license
14 <div id="cls-Ext.Shadow"></div>/**
16 * Simple class that can provide a shadow effect for any element. Note that the element MUST be absolutely positioned,
17 * and the shadow does not provide any shimming. This should be used only in simple cases -- for more advanced
18 * functionality that can also provide the same shadow effect, see the {@link Ext.Layer} class.
21 * @param {Object} config The config object
23 Ext.Shadow = function(config){
24 Ext.apply(this, config);
25 if(typeof this.mode != "string"){
26 this.mode = this.defaultMode;
28 var o = this.offset, a = {h: 0};
29 var rad = Math.floor(this.offset/2);
30 switch(this.mode.toLowerCase()){ // all this hideous nonsense calculates the various offsets for shadows
36 a.l -= this.offset + rad;
37 a.t -= this.offset + rad;
48 a.l -= (this.offset - rad);
49 a.t -= this.offset + rad;
51 a.w -= (this.offset - rad)*2;
62 a.l -= (this.offset - rad);
63 a.t -= (this.offset - rad);
65 a.w -= (this.offset + rad + 1);
66 a.h -= (this.offset + rad);
75 Ext.Shadow.prototype = {
76 <div id="cfg-Ext.Shadow-mode"></div>/**
78 * The shadow display mode. Supports the following options:<div class="mdetail-params"><ul>
79 * <li><b><tt>sides</tt></b> : Shadow displays on both sides and bottom only</li>
80 * <li><b><tt>frame</tt></b> : Shadow displays equally on all four sides</li>
81 * <li><b><tt>drop</tt></b> : Traditional bottom-right drop shadow</li>
84 <div id="cfg-Ext.Shadow-offset"></div>/**
85 * @cfg {String} offset
86 * The number of pixels to offset the shadow from the element (defaults to <tt>4</tt>)
93 <div id="method-Ext.Shadow-show"></div>/**
94 * Displays the shadow under the target element
95 * @param {Mixed} targetEl The id or element under which the shadow should display
97 show : function(target){
98 target = Ext.get(target);
100 this.el = Ext.Shadow.Pool.pull();
101 if(this.el.dom.nextSibling != target.dom){
102 this.el.insertBefore(target);
105 this.el.setStyle("z-index", this.zIndex || parseInt(target.getStyle("z-index"), 10)-1);
107 this.el.dom.style.filter="progid:DXImageTransform.Microsoft.alpha(opacity=50) progid:DXImageTransform.Microsoft.Blur(pixelradius="+(this.offset)+")";
110 target.getLeft(true),
115 this.el.dom.style.display = "block";
118 <div id="method-Ext.Shadow-isVisible"></div>/**
119 * Returns true if the shadow is visible, else false
121 isVisible : function(){
122 return this.el ? true : false;
125 <div id="method-Ext.Shadow-realign"></div>/**
126 * Direct alignment when values are already available. Show must be called at least once before
127 * calling this method to ensure it is initialized.
128 * @param {Number} left The target element left position
129 * @param {Number} top The target element top position
130 * @param {Number} width The target element width
131 * @param {Number} height The target element height
133 realign : function(l, t, w, h){
137 var a = this.adjusts, d = this.el.dom, s = d.style;
139 s.left = (l+a.l)+"px";
140 s.top = (t+a.t)+"px";
141 var sw = (w+a.w), sh = (h+a.h), sws = sw +"px", shs = sh + "px";
142 if(s.width != sws || s.height != shs){
146 var cn = d.childNodes;
147 var sww = Math.max(0, (sw-12))+"px";
148 cn[0].childNodes[1].style.width = sww;
149 cn[1].childNodes[1].style.width = sww;
150 cn[2].childNodes[1].style.width = sww;
151 cn[1].style.height = Math.max(0, (sh-12))+"px";
156 <div id="method-Ext.Shadow-hide"></div>/**
161 this.el.dom.style.display = "none";
162 Ext.Shadow.Pool.push(this.el);
167 <div id="method-Ext.Shadow-setZIndex"></div>/**
168 * Adjust the z-index of this shadow
169 * @param {Number} zindex The new z-index
171 setZIndex : function(z){
174 this.el.setStyle("z-index", z);
179 // Private utility class that manages the internal Shadow cache
180 Ext.Shadow.Pool = function(){
182 var markup = Ext.isIE ?
183 '<div class="x-ie-shadow"></div>' :
184 '<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>';
189 sh = Ext.get(Ext.DomHelper.insertHtml("beforeBegin", document.body.firstChild, markup));
190 sh.autoBoxAdjust = false;