a24b19d98e09d497ddec2468ddcb694635e1b02a.svn-base 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * Ext JS Library 2.0 Copyright(c) 2006-2007, Ext JS, LLC. licensing@extjs.com
  3. *
  4. * http://extjs.com/license
  5. */
  6. /**
  7. * @class Ext.Shadow Simple class that can provide a shadow effect for any
  8. * element. Note that the element MUST be absolutely positioned, and the
  9. * shadow does not provide any shimming. This should be used only in
  10. * simple cases -- for more advanced functionality that can also provide
  11. * the same shadow effect, see the {@link Ext.Layer} class.
  12. * @constructor Create a new Shadow
  13. * @param {Object}
  14. * config The config object
  15. */
  16. Ext.Shadow = function(config) {
  17. Ext.apply(this, config);
  18. if (typeof this.mode != "string") {
  19. this.mode = this.defaultMode;
  20. }
  21. var o = this.offset, a = {
  22. h : 0
  23. };
  24. var rad = Math.floor(this.offset / 2);
  25. switch (this.mode.toLowerCase()) { // all this hideous nonsense calculates
  26. // the various offsets for shadows
  27. case "drop" :
  28. a.w = 0;
  29. a.l = a.t = o;
  30. a.t -= 1;
  31. if (Ext.isIE) {
  32. a.l -= this.offset + rad;
  33. a.t -= this.offset + rad;
  34. a.w -= rad;
  35. a.h -= rad;
  36. a.t += 1;
  37. }
  38. break;
  39. case "sides" :
  40. a.w = (o * 2);
  41. a.l = -o;
  42. a.t = o - 1;
  43. if (Ext.isIE) {
  44. a.l -= (this.offset - rad);
  45. a.t -= this.offset + rad;
  46. a.l += 1;
  47. a.w -= (this.offset - rad) * 2;
  48. a.w -= rad + 1;
  49. a.h -= 1;
  50. }
  51. break;
  52. case "frame" :
  53. a.w = a.h = (o * 2);
  54. a.l = a.t = -o;
  55. a.t += 1;
  56. a.h -= 2;
  57. if (Ext.isIE) {
  58. a.l -= (this.offset - rad);
  59. a.t -= (this.offset - rad);
  60. a.l += 1;
  61. a.w -= (this.offset + rad + 1);
  62. a.h -= (this.offset + rad);
  63. a.h += 1;
  64. }
  65. break;
  66. };
  67. this.adjusts = a;
  68. };
  69. Ext.Shadow.prototype = {
  70. /**
  71. * @cfg {String} mode The shadow display mode. Supports the following
  72. * options:<br />
  73. * sides: Shadow displays on both sides and bottom only<br />
  74. * frame: Shadow displays equally on all four sides<br />
  75. * drop: Traditional bottom-right drop shadow (default)
  76. */
  77. /**
  78. * @cfg {String} offset The number of pixels to offset the shadow from the
  79. * element (defaults to 4)
  80. */
  81. offset : 4,
  82. // private
  83. defaultMode : "drop",
  84. /**
  85. * Displays the shadow under the target element
  86. *
  87. * @param {Mixed}
  88. * targetEl The id or element under which the shadow should
  89. * display
  90. */
  91. show : function(target) {
  92. target = Ext.get(target);
  93. if (!this.el) {
  94. this.el = Ext.Shadow.Pool.pull();
  95. if (this.el.dom.nextSibling != target.dom) {
  96. this.el.insertBefore(target);
  97. }
  98. }
  99. this.el.setStyle("z-index", this.zIndex
  100. || parseInt(target.getStyle("z-index"), 10) - 1);
  101. if (Ext.isIE) {
  102. this.el.dom.style.filter = "progid:DXImageTransform.Microsoft.alpha(opacity=50) progid:DXImageTransform.Microsoft.Blur(pixelradius="
  103. + (this.offset) + ")";
  104. }
  105. this.realign(target.getLeft(true), target.getTop(true), target
  106. .getWidth(), target.getHeight());
  107. this.el.dom.style.display = "block";
  108. },
  109. /**
  110. * Returns true if the shadow is visible, else false
  111. */
  112. isVisible : function() {
  113. return this.el ? true : false;
  114. },
  115. /**
  116. * Direct alignment when values are already available. Show must be called
  117. * at least once before calling this method to ensure it is initialized.
  118. *
  119. * @param {Number}
  120. * left The target element left position
  121. * @param {Number}
  122. * top The target element top position
  123. * @param {Number}
  124. * width The target element width
  125. * @param {Number}
  126. * height The target element height
  127. */
  128. realign : function(l, t, w, h) {
  129. if (!this.el) {
  130. return;
  131. }
  132. var a = this.adjusts, d = this.el.dom, s = d.style;
  133. var iea = 0;
  134. s.left = (l + a.l) + "px";
  135. s.top = (t + a.t) + "px";
  136. var sw = (w + a.w), sh = (h + a.h), sws = sw + "px", shs = sh + "px";
  137. if (s.width != sws || s.height != shs) {
  138. s.width = sws;
  139. s.height = shs;
  140. if (!Ext.isIE) {
  141. var cn = d.childNodes;
  142. var sww = Math.max(0, (sw - 12)) + "px";
  143. cn[0].childNodes[1].style.width = sww;
  144. cn[1].childNodes[1].style.width = sww;
  145. cn[2].childNodes[1].style.width = sww;
  146. cn[1].style.height = Math.max(0, (sh - 12)) + "px";
  147. }
  148. }
  149. },
  150. /**
  151. * Hides this shadow
  152. */
  153. hide : function() {
  154. if (this.el) {
  155. this.el.dom.style.display = "none";
  156. Ext.Shadow.Pool.push(this.el);
  157. delete this.el;
  158. }
  159. },
  160. /**
  161. * Adjust the z-index of this shadow
  162. *
  163. * @param {Number}
  164. * zindex The new z-index
  165. */
  166. setZIndex : function(z) {
  167. this.zIndex = z;
  168. if (this.el) {
  169. this.el.setStyle("z-index", z);
  170. }
  171. }
  172. };
  173. // Private utility class that manages the internal Shadow cache
  174. Ext.Shadow.Pool = function() {
  175. var p = [];
  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>';
  179. return {
  180. pull : function() {
  181. var sh = p.shift();
  182. if (!sh) {
  183. sh = Ext.get(Ext.DomHelper.insertHtml("beforeBegin",
  184. document.body.firstChild, markup));
  185. sh.autoBoxAdjust = false;
  186. }
  187. return sh;
  188. },
  189. push : function(sh) {
  190. p.push(sh);
  191. }
  192. };
  193. }();