1084689c3c8606940d13bb093b1ae91fd8fb4c78.svn-base 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. Ext.SplitBar = function(C, E, B, D, A) {
  7. this.el = Ext.get(C, true);
  8. this.el.dom.unselectable = "on";
  9. this.resizingEl = Ext.get(E, true);
  10. this.orientation = B || Ext.SplitBar.HORIZONTAL;
  11. this.minSize = 0;
  12. this.maxSize = 2000;
  13. this.animate = false;
  14. this.useShim = false;
  15. this.shim = null;
  16. if (!A) {
  17. this.proxy = Ext.SplitBar.createProxy(this.orientation)
  18. } else {
  19. this.proxy = Ext.get(A).dom
  20. }
  21. this.dd = new Ext.dd.DDProxy(this.el.dom.id, "XSplitBars", {
  22. dragElId : this.proxy.id
  23. });
  24. this.dd.b4StartDrag = this.onStartProxyDrag.createDelegate(this);
  25. this.dd.endDrag = this.onEndProxyDrag.createDelegate(this);
  26. this.dragSpecs = {};
  27. this.adapter = new Ext.SplitBar.BasicLayoutAdapter();
  28. this.adapter.init(this);
  29. if (this.orientation == Ext.SplitBar.HORIZONTAL) {
  30. this.placement = D
  31. || (this.el.getX() > this.resizingEl.getX()
  32. ? Ext.SplitBar.LEFT
  33. : Ext.SplitBar.RIGHT);
  34. this.el.addClass("x-splitbar-h")
  35. } else {
  36. this.placement = D
  37. || (this.el.getY() > this.resizingEl.getY()
  38. ? Ext.SplitBar.TOP
  39. : Ext.SplitBar.BOTTOM);
  40. this.el.addClass("x-splitbar-v")
  41. }
  42. this.addEvents("resize", "moved", "beforeresize", "beforeapply");
  43. Ext.SplitBar.superclass.constructor.call(this)
  44. };
  45. Ext.extend(Ext.SplitBar, Ext.util.Observable, {
  46. onStartProxyDrag : function(A, E) {
  47. this.fireEvent("beforeresize", this);
  48. this.overlay = Ext.DomHelper.append(document.body, {
  49. cls : "x-drag-overlay",
  50. html : " "
  51. }, true);
  52. this.overlay.unselectable();
  53. this.overlay.setSize(Ext.lib.Dom.getViewWidth(true),
  54. Ext.lib.Dom.getViewHeight(true));
  55. this.overlay.show();
  56. Ext.get(this.proxy).setDisplayed("block");
  57. var C = this.adapter.getElementSize(this);
  58. this.activeMinSize = this.getMinimumSize();
  59. this.activeMaxSize = this.getMaximumSize();
  60. var D = C - this.activeMinSize;
  61. var B = Math.max(this.activeMaxSize - C, 0);
  62. if (this.orientation == Ext.SplitBar.HORIZONTAL) {
  63. this.dd.resetConstraints();
  64. this.dd.setXConstraint(this.placement == Ext.SplitBar.LEFT
  65. ? D
  66. : B, this.placement == Ext.SplitBar.LEFT
  67. ? B
  68. : D);
  69. this.dd.setYConstraint(0, 0)
  70. } else {
  71. this.dd.resetConstraints();
  72. this.dd.setXConstraint(0, 0);
  73. this.dd.setYConstraint(this.placement == Ext.SplitBar.TOP
  74. ? D
  75. : B, this.placement == Ext.SplitBar.TOP
  76. ? B
  77. : D)
  78. }
  79. this.dragSpecs.startSize = C;
  80. this.dragSpecs.startPoint = [A, E];
  81. Ext.dd.DDProxy.prototype.b4StartDrag.call(this.dd, A, E)
  82. },
  83. onEndProxyDrag : function(C) {
  84. Ext.get(this.proxy).setDisplayed(false);
  85. var B = Ext.lib.Event.getXY(C);
  86. if (this.overlay) {
  87. this.overlay.remove();
  88. delete this.overlay
  89. }
  90. var A;
  91. if (this.orientation == Ext.SplitBar.HORIZONTAL) {
  92. A = this.dragSpecs.startSize
  93. + (this.placement == Ext.SplitBar.LEFT
  94. ? B[0] - this.dragSpecs.startPoint[0]
  95. : this.dragSpecs.startPoint[0] - B[0])
  96. } else {
  97. A = this.dragSpecs.startSize
  98. + (this.placement == Ext.SplitBar.TOP
  99. ? B[1] - this.dragSpecs.startPoint[1]
  100. : this.dragSpecs.startPoint[1] - B[1])
  101. }
  102. A = Math.min(Math.max(A, this.activeMinSize),
  103. this.activeMaxSize);
  104. if (A != this.dragSpecs.startSize) {
  105. if (this.fireEvent("beforeapply", this, A) !== false) {
  106. this.adapter.setElementSize(this, A);
  107. this.fireEvent("moved", this, A);
  108. this.fireEvent("resize", this, A)
  109. }
  110. }
  111. },
  112. getAdapter : function() {
  113. return this.adapter
  114. },
  115. setAdapter : function(A) {
  116. this.adapter = A;
  117. this.adapter.init(this)
  118. },
  119. getMinimumSize : function() {
  120. return this.minSize
  121. },
  122. setMinimumSize : function(A) {
  123. this.minSize = A
  124. },
  125. getMaximumSize : function() {
  126. return this.maxSize
  127. },
  128. setMaximumSize : function(A) {
  129. this.maxSize = A
  130. },
  131. setCurrentSize : function(B) {
  132. var A = this.animate;
  133. this.animate = false;
  134. this.adapter.setElementSize(this, B);
  135. this.animate = A
  136. },
  137. destroy : function(A) {
  138. if (this.shim) {
  139. this.shim.remove()
  140. }
  141. this.dd.unreg();
  142. Ext.removeNode(this.proxy);
  143. if (A) {
  144. this.el.remove()
  145. }
  146. }
  147. });
  148. Ext.SplitBar.createProxy = function(B) {
  149. var C = new Ext.Element(document.createElement("div"));
  150. C.unselectable();
  151. var A = "x-splitbar-proxy";
  152. C.addClass(A + " " + (B == Ext.SplitBar.HORIZONTAL ? A + "-h" : A + "-v"));
  153. document.body.appendChild(C.dom);
  154. return C.dom
  155. };
  156. Ext.SplitBar.BasicLayoutAdapter = function() {
  157. };
  158. Ext.SplitBar.BasicLayoutAdapter.prototype = {
  159. init : function(A) {
  160. },
  161. getElementSize : function(A) {
  162. if (A.orientation == Ext.SplitBar.HORIZONTAL) {
  163. return A.resizingEl.getWidth()
  164. } else {
  165. return A.resizingEl.getHeight()
  166. }
  167. },
  168. setElementSize : function(B, A, C) {
  169. if (B.orientation == Ext.SplitBar.HORIZONTAL) {
  170. if (!B.animate) {
  171. B.resizingEl.setWidth(A);
  172. if (C) {
  173. C(B, A)
  174. }
  175. } else {
  176. B.resizingEl.setWidth(A, true, 0.1, C, "easeOut")
  177. }
  178. } else {
  179. if (!B.animate) {
  180. B.resizingEl.setHeight(A);
  181. if (C) {
  182. C(B, A)
  183. }
  184. } else {
  185. B.resizingEl.setHeight(A, true, 0.1, C, "easeOut")
  186. }
  187. }
  188. }
  189. };
  190. Ext.SplitBar.AbsoluteLayoutAdapter = function(A) {
  191. this.basic = new Ext.SplitBar.BasicLayoutAdapter();
  192. this.container = Ext.get(A)
  193. };
  194. Ext.SplitBar.AbsoluteLayoutAdapter.prototype = {
  195. init : function(A) {
  196. this.basic.init(A)
  197. },
  198. getElementSize : function(A) {
  199. return this.basic.getElementSize(A)
  200. },
  201. setElementSize : function(B, A, C) {
  202. this.basic.setElementSize(B, A, this.moveSplitter.createDelegate(this,
  203. [B]))
  204. },
  205. moveSplitter : function(A) {
  206. var B = Ext.SplitBar;
  207. switch (A.placement) {
  208. case B.LEFT :
  209. A.el.setX(A.resizingEl.getRight());
  210. break;
  211. case B.RIGHT :
  212. A.el.setStyle("right",
  213. (this.container.getWidth() - A.resizingEl.getLeft())
  214. + "px");
  215. break;
  216. case B.TOP :
  217. A.el.setY(A.resizingEl.getBottom());
  218. break;
  219. case B.BOTTOM :
  220. A.el.setY(A.resizingEl.getTop() - A.el.getHeight());
  221. break
  222. }
  223. }
  224. };
  225. Ext.SplitBar.VERTICAL = 1;
  226. Ext.SplitBar.HORIZONTAL = 2;
  227. Ext.SplitBar.LEFT = 1;
  228. Ext.SplitBar.RIGHT = 2;
  229. Ext.SplitBar.TOP = 3;
  230. Ext.SplitBar.BOTTOM = 4;