You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

450 lines
16 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-SplitBar-method-constructor'><span id='Ext-SplitBar'>/**
  19. </span></span> * @class Ext.SplitBar
  20. * @extends Ext.util.Observable
  21. * Creates draggable splitter bar functionality from two elements (element to be dragged and element to be resized).
  22. * &lt;br&gt;&lt;br&gt;
  23. * Usage:
  24. * &lt;pre&gt;&lt;code&gt;
  25. var split = new Ext.SplitBar(&quot;elementToDrag&quot;, &quot;elementToSize&quot;,
  26. Ext.SplitBar.HORIZONTAL, Ext.SplitBar.LEFT);
  27. split.setAdapter(new Ext.SplitBar.AbsoluteLayoutAdapter(&quot;container&quot;));
  28. split.minSize = 100;
  29. split.maxSize = 600;
  30. split.animate = true;
  31. split.on('moved', splitterMoved);
  32. &lt;/code&gt;&lt;/pre&gt;
  33. * @constructor
  34. * Create a new SplitBar
  35. * @param {Mixed} dragElement The element to be dragged and act as the SplitBar.
  36. * @param {Mixed} resizingElement The element to be resized based on where the SplitBar element is dragged
  37. * @param {Number} orientation (optional) Either Ext.SplitBar.HORIZONTAL or Ext.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
  38. * @param {Number} placement (optional) Either Ext.SplitBar.LEFT or Ext.SplitBar.RIGHT for horizontal or
  39. Ext.SplitBar.TOP or Ext.SplitBar.BOTTOM for vertical. (By default, this is determined automatically by the initial
  40. position of the SplitBar).
  41. */
  42. Ext.SplitBar = function(dragElement, resizingElement, orientation, placement, existingProxy){
  43. <span id='Ext-SplitBar-property-el'> /** @private */
  44. </span> this.el = Ext.get(dragElement, true);
  45. this.el.unselectable();
  46. <span id='Ext-SplitBar-property-resizingEl'> /** @private */
  47. </span> this.resizingEl = Ext.get(resizingElement, true);
  48. <span id='Ext-SplitBar-property-orientation'> /**
  49. </span> * @private
  50. * The orientation of the split. Either Ext.SplitBar.HORIZONTAL or Ext.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
  51. * Note: If this is changed after creating the SplitBar, the placement property must be manually updated
  52. * @type Number
  53. */
  54. this.orientation = orientation || Ext.SplitBar.HORIZONTAL;
  55. <span id='Ext-SplitBar-property-tickSize'> /**
  56. </span> * The increment, in pixels by which to move this SplitBar. When &lt;i&gt;undefined&lt;/i&gt;, the SplitBar moves smoothly.
  57. * @type Number
  58. * @property tickSize
  59. */
  60. <span id='Ext-SplitBar-property-minSize'> /**
  61. </span> * The minimum size of the resizing element. (Defaults to 0)
  62. * @type Number
  63. */
  64. this.minSize = 0;
  65. <span id='Ext-SplitBar-property-maxSize'> /**
  66. </span> * The maximum size of the resizing element. (Defaults to 2000)
  67. * @type Number
  68. */
  69. this.maxSize = 2000;
  70. <span id='Ext-SplitBar-property-animate'> /**
  71. </span> * Whether to animate the transition to the new size
  72. * @type Boolean
  73. */
  74. this.animate = false;
  75. <span id='Ext-SplitBar-property-useShim'> /**
  76. </span> * Whether to create a transparent shim that overlays the page when dragging, enables dragging across iframes.
  77. * @type Boolean
  78. */
  79. this.useShim = false;
  80. <span id='Ext-SplitBar-property-shim'> /** @private */
  81. </span> this.shim = null;
  82. if(!existingProxy){
  83. <span id='Ext-SplitBar-property-proxy'> /** @private */
  84. </span> this.proxy = Ext.SplitBar.createProxy(this.orientation);
  85. }else{
  86. this.proxy = Ext.get(existingProxy).dom;
  87. }
  88. <span id='Ext-SplitBar-property-dd'> /** @private */
  89. </span> this.dd = new Ext.dd.DDProxy(this.el.dom.id, &quot;XSplitBars&quot;, {dragElId : this.proxy.id});
  90. <span id='Ext-SplitBar-property-b4StartDrag'> /** @private */
  91. </span> this.dd.b4StartDrag = this.onStartProxyDrag.createDelegate(this);
  92. <span id='Ext-SplitBar-property-endDrag'> /** @private */
  93. </span> this.dd.endDrag = this.onEndProxyDrag.createDelegate(this);
  94. <span id='Ext-SplitBar-property-dragSpecs'> /** @private */
  95. </span> this.dragSpecs = {};
  96. <span id='Ext-SplitBar-property-adapter'> /**
  97. </span> * @private The adapter to use to positon and resize elements
  98. */
  99. this.adapter = new Ext.SplitBar.BasicLayoutAdapter();
  100. this.adapter.init(this);
  101. if(this.orientation == Ext.SplitBar.HORIZONTAL){
  102. <span id='global-property-placement'> /** @ignore */
  103. </span> this.placement = placement || (this.el.getX() &gt; this.resizingEl.getX() ? Ext.SplitBar.LEFT : Ext.SplitBar.RIGHT);
  104. this.el.addClass(&quot;x-splitbar-h&quot;);
  105. }else{
  106. <span id='global-property-placement'> /** @ignore */
  107. </span> this.placement = placement || (this.el.getY() &gt; this.resizingEl.getY() ? Ext.SplitBar.TOP : Ext.SplitBar.BOTTOM);
  108. this.el.addClass(&quot;x-splitbar-v&quot;);
  109. }
  110. this.addEvents(
  111. <span id='Ext-SplitBar-event-resize'> /**
  112. </span> * @event resize
  113. * Fires when the splitter is moved (alias for {@link #moved})
  114. * @param {Ext.SplitBar} this
  115. * @param {Number} newSize the new width or height
  116. */
  117. &quot;resize&quot;,
  118. <span id='Ext-SplitBar-event-moved'> /**
  119. </span> * @event moved
  120. * Fires when the splitter is moved
  121. * @param {Ext.SplitBar} this
  122. * @param {Number} newSize the new width or height
  123. */
  124. &quot;moved&quot;,
  125. <span id='Ext-SplitBar-event-beforeresize'> /**
  126. </span> * @event beforeresize
  127. * Fires before the splitter is dragged
  128. * @param {Ext.SplitBar} this
  129. */
  130. &quot;beforeresize&quot;,
  131. &quot;beforeapply&quot;
  132. );
  133. Ext.SplitBar.superclass.constructor.call(this);
  134. };
  135. Ext.extend(Ext.SplitBar, Ext.util.Observable, {
  136. onStartProxyDrag : function(x, y){
  137. this.fireEvent(&quot;beforeresize&quot;, this);
  138. this.overlay = Ext.DomHelper.append(document.body, {cls: &quot;x-drag-overlay&quot;, html: &quot;&amp;#160;&quot;}, true);
  139. this.overlay.unselectable();
  140. this.overlay.setSize(Ext.lib.Dom.getViewWidth(true), Ext.lib.Dom.getViewHeight(true));
  141. this.overlay.show();
  142. Ext.get(this.proxy).setDisplayed(&quot;block&quot;);
  143. var size = this.adapter.getElementSize(this);
  144. this.activeMinSize = this.getMinimumSize();
  145. this.activeMaxSize = this.getMaximumSize();
  146. var c1 = size - this.activeMinSize;
  147. var c2 = Math.max(this.activeMaxSize - size, 0);
  148. if(this.orientation == Ext.SplitBar.HORIZONTAL){
  149. this.dd.resetConstraints();
  150. this.dd.setXConstraint(
  151. this.placement == Ext.SplitBar.LEFT ? c1 : c2,
  152. this.placement == Ext.SplitBar.LEFT ? c2 : c1,
  153. this.tickSize
  154. );
  155. this.dd.setYConstraint(0, 0);
  156. }else{
  157. this.dd.resetConstraints();
  158. this.dd.setXConstraint(0, 0);
  159. this.dd.setYConstraint(
  160. this.placement == Ext.SplitBar.TOP ? c1 : c2,
  161. this.placement == Ext.SplitBar.TOP ? c2 : c1,
  162. this.tickSize
  163. );
  164. }
  165. this.dragSpecs.startSize = size;
  166. this.dragSpecs.startPoint = [x, y];
  167. Ext.dd.DDProxy.prototype.b4StartDrag.call(this.dd, x, y);
  168. },
  169. <span id='Ext-SplitBar-method-onEndProxyDrag'> /**
  170. </span> * @private Called after the drag operation by the DDProxy
  171. */
  172. onEndProxyDrag : function(e){
  173. Ext.get(this.proxy).setDisplayed(false);
  174. var endPoint = Ext.lib.Event.getXY(e);
  175. if(this.overlay){
  176. Ext.destroy(this.overlay);
  177. delete this.overlay;
  178. }
  179. var newSize;
  180. if(this.orientation == Ext.SplitBar.HORIZONTAL){
  181. newSize = this.dragSpecs.startSize +
  182. (this.placement == Ext.SplitBar.LEFT ?
  183. endPoint[0] - this.dragSpecs.startPoint[0] :
  184. this.dragSpecs.startPoint[0] - endPoint[0]
  185. );
  186. }else{
  187. newSize = this.dragSpecs.startSize +
  188. (this.placement == Ext.SplitBar.TOP ?
  189. endPoint[1] - this.dragSpecs.startPoint[1] :
  190. this.dragSpecs.startPoint[1] - endPoint[1]
  191. );
  192. }
  193. newSize = Math.min(Math.max(newSize, this.activeMinSize), this.activeMaxSize);
  194. if(newSize != this.dragSpecs.startSize){
  195. if(this.fireEvent('beforeapply', this, newSize) !== false){
  196. this.adapter.setElementSize(this, newSize);
  197. this.fireEvent(&quot;moved&quot;, this, newSize);
  198. this.fireEvent(&quot;resize&quot;, this, newSize);
  199. }
  200. }
  201. },
  202. <span id='Ext-SplitBar-method-getAdapter'> /**
  203. </span> * Get the adapter this SplitBar uses
  204. * @return The adapter object
  205. */
  206. getAdapter : function(){
  207. return this.adapter;
  208. },
  209. <span id='Ext-SplitBar-method-setAdapter'> /**
  210. </span> * Set the adapter this SplitBar uses
  211. * @param {Object} adapter A SplitBar adapter object
  212. */
  213. setAdapter : function(adapter){
  214. this.adapter = adapter;
  215. this.adapter.init(this);
  216. },
  217. <span id='Ext-SplitBar-method-getMinimumSize'> /**
  218. </span> * Gets the minimum size for the resizing element
  219. * @return {Number} The minimum size
  220. */
  221. getMinimumSize : function(){
  222. return this.minSize;
  223. },
  224. <span id='Ext-SplitBar-method-setMinimumSize'> /**
  225. </span> * Sets the minimum size for the resizing element
  226. * @param {Number} minSize The minimum size
  227. */
  228. setMinimumSize : function(minSize){
  229. this.minSize = minSize;
  230. },
  231. <span id='Ext-SplitBar-method-getMaximumSize'> /**
  232. </span> * Gets the maximum size for the resizing element
  233. * @return {Number} The maximum size
  234. */
  235. getMaximumSize : function(){
  236. return this.maxSize;
  237. },
  238. <span id='Ext-SplitBar-method-setMaximumSize'> /**
  239. </span> * Sets the maximum size for the resizing element
  240. * @param {Number} maxSize The maximum size
  241. */
  242. setMaximumSize : function(maxSize){
  243. this.maxSize = maxSize;
  244. },
  245. <span id='Ext-SplitBar-method-setCurrentSize'> /**
  246. </span> * Sets the initialize size for the resizing element
  247. * @param {Number} size The initial size
  248. */
  249. setCurrentSize : function(size){
  250. var oldAnimate = this.animate;
  251. this.animate = false;
  252. this.adapter.setElementSize(this, size);
  253. this.animate = oldAnimate;
  254. },
  255. <span id='Ext-SplitBar-method-destroy'> /**
  256. </span> * Destroy this splitbar.
  257. * @param {Boolean} removeEl True to remove the element
  258. */
  259. destroy : function(removeEl){
  260. Ext.destroy(this.shim, Ext.get(this.proxy));
  261. this.dd.unreg();
  262. if(removeEl){
  263. this.el.remove();
  264. }
  265. this.purgeListeners();
  266. }
  267. });
  268. <span id='Ext-SplitBar-method-createProxy'>/**
  269. </span> * @private static Create our own proxy element element. So it will be the same same size on all browsers, we won't use borders. Instead we use a background color.
  270. */
  271. Ext.SplitBar.createProxy = function(dir){
  272. var proxy = new Ext.Element(document.createElement(&quot;div&quot;));
  273. document.body.appendChild(proxy.dom);
  274. proxy.unselectable();
  275. var cls = 'x-splitbar-proxy';
  276. proxy.addClass(cls + ' ' + (dir == Ext.SplitBar.HORIZONTAL ? cls +'-h' : cls + '-v'));
  277. return proxy.dom;
  278. };
  279. <span id='Ext-SplitBar-BasicLayoutAdapter'>/**
  280. </span> * @class Ext.SplitBar.BasicLayoutAdapter
  281. * Default Adapter. It assumes the splitter and resizing element are not positioned
  282. * elements and only gets/sets the width of the element. Generally used for table based layouts.
  283. */
  284. Ext.SplitBar.BasicLayoutAdapter = function(){
  285. };
  286. Ext.SplitBar.BasicLayoutAdapter.prototype = {
  287. // do nothing for now
  288. init : function(s){
  289. },
  290. <span id='Ext-SplitBar-BasicLayoutAdapter-method-getElementSize'> /**
  291. </span> * Called before drag operations to get the current size of the resizing element.
  292. * @param {Ext.SplitBar} s The SplitBar using this adapter
  293. */
  294. getElementSize : function(s){
  295. if(s.orientation == Ext.SplitBar.HORIZONTAL){
  296. return s.resizingEl.getWidth();
  297. }else{
  298. return s.resizingEl.getHeight();
  299. }
  300. },
  301. <span id='Ext-SplitBar-BasicLayoutAdapter-method-setElementSize'> /**
  302. </span> * Called after drag operations to set the size of the resizing element.
  303. * @param {Ext.SplitBar} s The SplitBar using this adapter
  304. * @param {Number} newSize The new size to set
  305. * @param {Function} onComplete A function to be invoked when resizing is complete
  306. */
  307. setElementSize : function(s, newSize, onComplete){
  308. if(s.orientation == Ext.SplitBar.HORIZONTAL){
  309. if(!s.animate){
  310. s.resizingEl.setWidth(newSize);
  311. if(onComplete){
  312. onComplete(s, newSize);
  313. }
  314. }else{
  315. s.resizingEl.setWidth(newSize, true, .1, onComplete, 'easeOut');
  316. }
  317. }else{
  318. if(!s.animate){
  319. s.resizingEl.setHeight(newSize);
  320. if(onComplete){
  321. onComplete(s, newSize);
  322. }
  323. }else{
  324. s.resizingEl.setHeight(newSize, true, .1, onComplete, 'easeOut');
  325. }
  326. }
  327. }
  328. };
  329. <span id='Ext-SplitBar-AbsoluteLayoutAdapter'>/**
  330. </span> *@class Ext.SplitBar.AbsoluteLayoutAdapter
  331. * @extends Ext.SplitBar.BasicLayoutAdapter
  332. * Adapter that moves the splitter element to align with the resized sizing element.
  333. * Used with an absolute positioned SplitBar.
  334. * @param {Mixed} container The container that wraps around the absolute positioned content. If it's
  335. * document.body, make sure you assign an id to the body element.
  336. */
  337. Ext.SplitBar.AbsoluteLayoutAdapter = function(container){
  338. this.basic = new Ext.SplitBar.BasicLayoutAdapter();
  339. this.container = Ext.get(container);
  340. };
  341. Ext.SplitBar.AbsoluteLayoutAdapter.prototype = {
  342. init : function(s){
  343. this.basic.init(s);
  344. },
  345. getElementSize : function(s){
  346. return this.basic.getElementSize(s);
  347. },
  348. setElementSize : function(s, newSize, onComplete){
  349. this.basic.setElementSize(s, newSize, this.moveSplitter.createDelegate(this, [s]));
  350. },
  351. moveSplitter : function(s){
  352. var yes = Ext.SplitBar;
  353. switch(s.placement){
  354. case yes.LEFT:
  355. s.el.setX(s.resizingEl.getRight());
  356. break;
  357. case yes.RIGHT:
  358. s.el.setStyle(&quot;right&quot;, (this.container.getWidth() - s.resizingEl.getLeft()) + &quot;px&quot;);
  359. break;
  360. case yes.TOP:
  361. s.el.setY(s.resizingEl.getBottom());
  362. break;
  363. case yes.BOTTOM:
  364. s.el.setY(s.resizingEl.getTop() - s.el.getHeight());
  365. break;
  366. }
  367. }
  368. };
  369. <span id='Ext-SplitBar-AbsoluteLayoutAdapter-static-property-VERTICAL'>/**
  370. </span> * Orientation constant - Create a vertical SplitBar
  371. * @static
  372. * @type Number
  373. */
  374. Ext.SplitBar.VERTICAL = 1;
  375. <span id='Ext-SplitBar-AbsoluteLayoutAdapter-static-property-HORIZONTAL'>/**
  376. </span> * Orientation constant - Create a horizontal SplitBar
  377. * @static
  378. * @type Number
  379. */
  380. Ext.SplitBar.HORIZONTAL = 2;
  381. <span id='Ext-SplitBar-AbsoluteLayoutAdapter-static-property-LEFT'>/**
  382. </span> * Placement constant - The resizing element is to the left of the splitter element
  383. * @static
  384. * @type Number
  385. */
  386. Ext.SplitBar.LEFT = 1;
  387. <span id='Ext-SplitBar-AbsoluteLayoutAdapter-static-property-RIGHT'>/**
  388. </span> * Placement constant - The resizing element is to the right of the splitter element
  389. * @static
  390. * @type Number
  391. */
  392. Ext.SplitBar.RIGHT = 2;
  393. <span id='Ext-SplitBar-AbsoluteLayoutAdapter-static-property-TOP'>/**
  394. </span> * Placement constant - The resizing element is positioned above the splitter element
  395. * @static
  396. * @type Number
  397. */
  398. Ext.SplitBar.TOP = 3;
  399. <span id='Ext-SplitBar-AbsoluteLayoutAdapter-static-property-BOTTOM'>/**
  400. </span> * Placement constant - The resizing element is positioned under splitter element
  401. * @static
  402. * @type Number
  403. */
  404. Ext.SplitBar.BOTTOM = 4;
  405. </pre>
  406. </body>
  407. </html>