PageRenderTime 188ms CodeModel.GetById 48ms RepoModel.GetById 16ms app.codeStats 0ms

/ext-4.0.7/docs/source/SplitterTracker.html

https://bitbucket.org/srogerf/javascript
HTML | 232 lines | 208 code | 24 blank | 0 comment | 0 complexity | f26ae1baf7b6caf9dce62008ca2c2acf MD5 | raw file
  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-resizer-SplitterTracker'>/**
  19. </span> * @class Ext.resizer.SplitterTracker
  20. * @extends Ext.dd.DragTracker
  21. * Private utility class for Ext.Splitter.
  22. * @private
  23. */
  24. Ext.define('Ext.resizer.SplitterTracker', {
  25. extend: 'Ext.dd.DragTracker',
  26. requires: ['Ext.util.Region'],
  27. enabled: true,
  28. overlayCls: Ext.baseCSSPrefix + 'resizable-overlay',
  29. getPrevCmp: function() {
  30. var splitter = this.getSplitter();
  31. return splitter.previousSibling();
  32. },
  33. getNextCmp: function() {
  34. var splitter = this.getSplitter();
  35. return splitter.nextSibling();
  36. },
  37. // ensure the tracker is enabled, store boxes of previous and next
  38. // components and calculate the constrain region
  39. onBeforeStart: function(e) {
  40. var me = this,
  41. prevCmp = me.getPrevCmp(),
  42. nextCmp = me.getNextCmp(),
  43. collapseEl = me.getSplitter().collapseEl,
  44. overlay;
  45. if (collapseEl &amp;&amp; (e.getTarget() === me.getSplitter().collapseEl.dom)) {
  46. return false;
  47. }
  48. // SplitterTracker is disabled if any of its adjacents are collapsed.
  49. if (nextCmp.collapsed || prevCmp.collapsed) {
  50. return false;
  51. }
  52. overlay = me.overlay = Ext.getBody().createChild({
  53. cls: me.overlayCls,
  54. html: '&amp;#160;'
  55. });
  56. overlay.unselectable();
  57. overlay.setSize(Ext.Element.getViewWidth(true), Ext.Element.getViewHeight(true));
  58. overlay.show();
  59. // store boxes of previous and next
  60. me.prevBox = prevCmp.getEl().getBox();
  61. me.nextBox = nextCmp.getEl().getBox();
  62. me.constrainTo = me.calculateConstrainRegion();
  63. },
  64. // We move the splitter el. Add the proxy class.
  65. onStart: function(e) {
  66. var splitter = this.getSplitter();
  67. splitter.addCls(splitter.baseCls + '-active');
  68. },
  69. // calculate the constrain Region in which the splitter el may be moved.
  70. calculateConstrainRegion: function() {
  71. var me = this,
  72. splitter = me.getSplitter(),
  73. splitWidth = splitter.getWidth(),
  74. defaultMin = splitter.defaultSplitMin,
  75. orient = splitter.orientation,
  76. prevBox = me.prevBox,
  77. prevCmp = me.getPrevCmp(),
  78. nextBox = me.nextBox,
  79. nextCmp = me.getNextCmp(),
  80. // prev and nextConstrainRegions are the maximumBoxes minus the
  81. // minimumBoxes. The result is always the intersection
  82. // of these two boxes.
  83. prevConstrainRegion, nextConstrainRegion;
  84. // vertical splitters, so resizing left to right
  85. if (orient === 'vertical') {
  86. // Region constructor accepts (top, right, bottom, left)
  87. // anchored/calculated from the left
  88. prevConstrainRegion = Ext.create('Ext.util.Region',
  89. prevBox.y,
  90. // Right boundary is x + maxWidth if there IS a maxWidth.
  91. // Otherwise it is calculated based upon the minWidth of the next Component
  92. (prevCmp.maxWidth ? prevBox.x + prevCmp.maxWidth : nextBox.right - (nextCmp.minWidth || defaultMin)) + splitWidth,
  93. prevBox.bottom,
  94. prevBox.x + (prevCmp.minWidth || defaultMin)
  95. );
  96. // anchored/calculated from the right
  97. nextConstrainRegion = Ext.create('Ext.util.Region',
  98. nextBox.y,
  99. nextBox.right - (nextCmp.minWidth || defaultMin),
  100. nextBox.bottom,
  101. // Left boundary is right - maxWidth if there IS a maxWidth.
  102. // Otherwise it is calculated based upon the minWidth of the previous Component
  103. (nextCmp.maxWidth ? nextBox.right - nextCmp.maxWidth : prevBox.x + (prevBox.minWidth || defaultMin)) - splitWidth
  104. );
  105. } else {
  106. // anchored/calculated from the top
  107. prevConstrainRegion = Ext.create('Ext.util.Region',
  108. prevBox.y + (prevCmp.minHeight || defaultMin),
  109. prevBox.right,
  110. // Bottom boundary is y + maxHeight if there IS a maxHeight.
  111. // Otherwise it is calculated based upon the minWidth of the next Component
  112. (prevCmp.maxHeight ? prevBox.y + prevCmp.maxHeight : nextBox.bottom - (nextCmp.minHeight || defaultMin)) + splitWidth,
  113. prevBox.x
  114. );
  115. // anchored/calculated from the bottom
  116. nextConstrainRegion = Ext.create('Ext.util.Region',
  117. // Top boundary is bottom - maxHeight if there IS a maxHeight.
  118. // Otherwise it is calculated based upon the minHeight of the previous Component
  119. (nextCmp.maxHeight ? nextBox.bottom - nextCmp.maxHeight : prevBox.y + (prevCmp.minHeight || defaultMin)) - splitWidth,
  120. nextBox.right,
  121. nextBox.bottom - (nextCmp.minHeight || defaultMin),
  122. nextBox.x
  123. );
  124. }
  125. // intersection of the two regions to provide region draggable
  126. return prevConstrainRegion.intersect(nextConstrainRegion);
  127. },
  128. // Performs the actual resizing of the previous and next components
  129. performResize: function(e) {
  130. var me = this,
  131. offset = me.getOffset('dragTarget'),
  132. splitter = me.getSplitter(),
  133. orient = splitter.orientation,
  134. prevCmp = me.getPrevCmp(),
  135. nextCmp = me.getNextCmp(),
  136. owner = splitter.ownerCt,
  137. layout = owner.getLayout();
  138. // Inhibit automatic container layout caused by setSize calls below.
  139. owner.suspendLayout = true;
  140. if (orient === 'vertical') {
  141. if (prevCmp) {
  142. if (!prevCmp.maintainFlex) {
  143. delete prevCmp.flex;
  144. prevCmp.setSize(me.prevBox.width + offset[0], prevCmp.getHeight());
  145. }
  146. }
  147. if (nextCmp) {
  148. if (!nextCmp.maintainFlex) {
  149. delete nextCmp.flex;
  150. nextCmp.setSize(me.nextBox.width - offset[0], nextCmp.getHeight());
  151. }
  152. }
  153. // verticals
  154. } else {
  155. if (prevCmp) {
  156. if (!prevCmp.maintainFlex) {
  157. delete prevCmp.flex;
  158. prevCmp.setSize(prevCmp.getWidth(), me.prevBox.height + offset[1]);
  159. }
  160. }
  161. if (nextCmp) {
  162. if (!nextCmp.maintainFlex) {
  163. delete nextCmp.flex;
  164. nextCmp.setSize(prevCmp.getWidth(), me.nextBox.height - offset[1]);
  165. }
  166. }
  167. }
  168. delete owner.suspendLayout;
  169. layout.onLayout();
  170. },
  171. // Cleans up the overlay (if we have one) and calls the base. This cannot be done in
  172. // onEnd, because onEnd is only called if a drag is detected but the overlay is created
  173. // regardless (by onBeforeStart).
  174. endDrag: function () {
  175. var me = this;
  176. if (me.overlay) {
  177. me.overlay.remove();
  178. delete me.overlay;
  179. }
  180. me.callParent(arguments); // this calls onEnd
  181. },
  182. // perform the resize and remove the proxy class from the splitter el
  183. onEnd: function(e) {
  184. var me = this,
  185. splitter = me.getSplitter();
  186. splitter.removeCls(splitter.baseCls + '-active');
  187. me.performResize();
  188. },
  189. // Track the proxy and set the proper XY coordinates
  190. // while constraining the drag
  191. onDrag: function(e) {
  192. var me = this,
  193. offset = me.getOffset('dragTarget'),
  194. splitter = me.getSplitter(),
  195. splitEl = splitter.getEl(),
  196. orient = splitter.orientation;
  197. if (orient === &quot;vertical&quot;) {
  198. splitEl.setX(me.startRegion.left + offset[0]);
  199. } else {
  200. splitEl.setY(me.startRegion.top + offset[1]);
  201. }
  202. },
  203. getSplitter: function() {
  204. return Ext.getCmp(this.getDragCt().id);
  205. }
  206. });</pre>
  207. </body>
  208. </html>