Web Interface For Lite Argus Control modules
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.

303 lines
13 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>The source code</title>
  5. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  6. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  7. </head>
  8. <body onload="prettyPrint();">
  9. <pre class="prettyprint lang-js">/*!
  10. * Ext JS Library 3.3.1
  11. * Copyright(c) 2006-2010 Sencha Inc.
  12. * licensing@sencha.com
  13. * http://www.sencha.com/license
  14. */
  15. <div id="cls-Ext.layout.VBoxLayout"></div>/**
  16. * @class Ext.layout.VBoxLayout
  17. * @extends Ext.layout.BoxLayout
  18. * <p>A layout that arranges items vertically down a Container. This layout optionally divides available vertical
  19. * space between child items containing a numeric <code>flex</code> configuration.</p>
  20. * This layout may also be used to set the widths of child items by configuring it with the {@link #align} option.
  21. */
  22. Ext.layout.VBoxLayout = Ext.extend(Ext.layout.BoxLayout, {
  23. <div id="cfg-Ext.layout.VBoxLayout-align"></div>/**
  24. * @cfg {String} align
  25. * Controls how the child items of the container are aligned. Acceptable configuration values for this
  26. * property are:
  27. * <div class="mdetail-params"><ul>
  28. * <li><b><tt>left</tt></b> : <b>Default</b><div class="sub-desc">child items are aligned horizontally
  29. * at the <b>left</b> side of the container</div></li>
  30. * <li><b><tt>center</tt></b> : <div class="sub-desc">child items are aligned horizontally at the
  31. * <b>mid-width</b> of the container</div></li>
  32. * <li><b><tt>stretch</tt></b> : <div class="sub-desc">child items are stretched horizontally to fill
  33. * the width of the container</div></li>
  34. * <li><b><tt>stretchmax</tt></b> : <div class="sub-desc">child items are stretched horizontally to
  35. * the size of the largest item.</div></li>
  36. * </ul></div>
  37. */
  38. align : 'left', // left, center, stretch, strechmax
  39. type: 'vbox',
  40. <div id="cfg-Ext.layout.VBoxLayout-pack"></div>/**
  41. * @cfg {String} pack
  42. * Controls how the child items of the container are packed together. Acceptable configuration values
  43. * for this property are:
  44. * <div class="mdetail-params"><ul>
  45. * <li><b><tt>start</tt></b> : <b>Default</b><div class="sub-desc">child items are packed together at
  46. * <b>top</b> side of container</div></li>
  47. * <li><b><tt>center</tt></b> : <div class="sub-desc">child items are packed together at
  48. * <b>mid-height</b> of container</div></li>
  49. * <li><b><tt>end</tt></b> : <div class="sub-desc">child items are packed together at <b>bottom</b>
  50. * side of container</div></li>
  51. * </ul></div>
  52. */
  53. <div id="cfg-Ext.layout.VBoxLayout-flex"></div>/**
  54. * @cfg {Number} flex
  55. * This configuation option is to be applied to <b>child <tt>items</tt></b> of the container managed
  56. * by this layout. Each child item with a <tt>flex</tt> property will be flexed <b>vertically</b>
  57. * according to each item's <b>relative</b> <tt>flex</tt> value compared to the sum of all items with
  58. * a <tt>flex</tt> value specified. Any child items that have either a <tt>flex = 0</tt> or
  59. * <tt>flex = undefined</tt> will not be 'flexed' (the initial size will not be changed).
  60. */
  61. /**
  62. * @private
  63. * Calculates the size and positioning of each item in the VBox. This iterates over all of the rendered,
  64. * visible items and returns a height, width, top and left for each, as well as a reference to each. Also
  65. * returns meta data such as maxHeight which are useful when resizing layout wrappers such as this.innerCt.
  66. * @param {Array} visibleItems The array of all rendered, visible items to be calculated for
  67. * @param {Object} targetSize Object containing target size and height
  68. * @return {Object} Object containing box measurements for each child, plus meta data
  69. */
  70. calculateChildBoxes: function(visibleItems, targetSize) {
  71. var visibleCount = visibleItems.length,
  72. padding = this.padding,
  73. topOffset = padding.top,
  74. leftOffset = padding.left,
  75. paddingVert = topOffset + padding.bottom,
  76. paddingHoriz = leftOffset + padding.right,
  77. width = targetSize.width - this.scrollOffset,
  78. height = targetSize.height,
  79. availWidth = Math.max(0, width - paddingHoriz),
  80. isStart = this.pack == 'start',
  81. isCenter = this.pack == 'center',
  82. isEnd = this.pack == 'end',
  83. nonFlexHeight= 0,
  84. maxWidth = 0,
  85. totalFlex = 0,
  86. desiredHeight= 0,
  87. minimumHeight= 0,
  88. //used to cache the calculated size and position values for each child item
  89. boxes = [],
  90. //used in the for loops below, just declared here for brevity
  91. child, childWidth, childHeight, childSize, childMargins, canLayout, i, calcs, flexedWidth,
  92. horizMargins, vertMargins, stretchWidth;
  93. //gather the total flex of all flexed items and the width taken up by fixed width items
  94. for (i = 0; i < visibleCount; i++) {
  95. child = visibleItems[i];
  96. childHeight = child.height;
  97. childWidth = child.width;
  98. canLayout = !child.hasLayout && typeof child.doLayout == 'function';
  99. // Static height (numeric) requires no calcs
  100. if (typeof childHeight != 'number') {
  101. // flex and not 'auto' height
  102. if (child.flex && !childHeight) {
  103. totalFlex += child.flex;
  104. // Not flexed or 'auto' height or undefined height
  105. } else {
  106. //Render and layout sub-containers without a flex or width defined, as otherwise we
  107. //don't know how wide the sub-container should be and cannot calculate flexed widths
  108. if (!childHeight && canLayout) {
  109. child.doLayout();
  110. }
  111. childSize = child.getSize();
  112. childWidth = childSize.width;
  113. childHeight = childSize.height;
  114. }
  115. }
  116. childMargins = child.margins;
  117. vertMargins = childMargins.top + childMargins.bottom;
  118. nonFlexHeight += vertMargins + (childHeight || 0);
  119. desiredHeight += vertMargins + (child.flex ? child.minHeight || 0 : childHeight);
  120. minimumHeight += vertMargins + (child.minHeight || childHeight || 0);
  121. // Max width for align - force layout of non-layed out subcontainers without a numeric width
  122. if (typeof childWidth != 'number') {
  123. if (canLayout) {
  124. child.doLayout();
  125. }
  126. childWidth = child.getWidth();
  127. }
  128. maxWidth = Math.max(maxWidth, childWidth + childMargins.left + childMargins.right);
  129. //cache the size of each child component
  130. boxes.push({
  131. component: child,
  132. height : childHeight || undefined,
  133. width : childWidth || undefined
  134. });
  135. }
  136. var shortfall = desiredHeight - height,
  137. tooNarrow = minimumHeight > height;
  138. //the height available to the flexed items
  139. var availableHeight = Math.max(0, (height - nonFlexHeight - paddingVert));
  140. if (tooNarrow) {
  141. for (i = 0, length = visibleCount; i < length; i++) {
  142. boxes[i].height = visibleItems[i].minHeight || visibleItems[i].height || boxes[i].height;
  143. }
  144. } else {
  145. //all flexed items should be sized to their minimum width, other items should be shrunk down until
  146. //the shortfall has been accounted for
  147. if (shortfall > 0) {
  148. var minHeights = [];
  149. <div id="prop-Ext.layout.VBoxLayout-for"></div>/**
  150. * When we have a shortfall but are not tooNarrow, we need to shrink the height of each non-flexed item.
  151. * Flexed items are immediately reduced to their minHeight and anything already at minHeight is ignored.
  152. * The remaining items are collected into the minHeights array, which is later used to distribute the shortfall.
  153. */
  154. for (var index = 0, length = visibleCount; index < length; index++) {
  155. var item = visibleItems[index],
  156. minHeight = item.minHeight || 0;
  157. //shrink each non-flex tab by an equal amount to make them all fit. Flexed items are all
  158. //shrunk to their minHeight because they're flexible and should be the first to lose height
  159. if (item.flex) {
  160. boxes[index].height = minHeight;
  161. } else {
  162. minHeights.push({
  163. minHeight: minHeight,
  164. available: boxes[index].height - minHeight,
  165. index : index
  166. });
  167. }
  168. }
  169. //sort by descending minHeight value
  170. minHeights.sort(function(a, b) {
  171. return a.available > b.available ? 1 : -1;
  172. });
  173. /*
  174. * Distribute the shortfall (difference between total desired with of all items and actual height available)
  175. * between the non-flexed items. We try to distribute the shortfall evenly, but apply it to items with the
  176. * smallest difference between their height and minHeight first, so that if reducing the height by the average
  177. * amount would make that item less than its minHeight, we carry the remainder over to the next item.
  178. */
  179. for (var i = 0, length = minHeights.length; i < length; i++) {
  180. var itemIndex = minHeights[i].index;
  181. if (itemIndex == undefined) {
  182. continue;
  183. }
  184. var item = visibleItems[itemIndex],
  185. box = boxes[itemIndex],
  186. oldHeight = box.height,
  187. minHeight = item.minHeight,
  188. newHeight = Math.max(minHeight, oldHeight - Math.ceil(shortfall / (length - i))),
  189. reduction = oldHeight - newHeight;
  190. boxes[itemIndex].height = newHeight;
  191. shortfall -= reduction;
  192. }
  193. } else {
  194. //temporary variables used in the flex height calculations below
  195. var remainingHeight = availableHeight,
  196. remainingFlex = totalFlex;
  197. //calculate the height of each flexed item
  198. for (i = 0; i < visibleCount; i++) {
  199. child = visibleItems[i];
  200. calcs = boxes[i];
  201. childMargins = child.margins;
  202. horizMargins = childMargins.left + childMargins.right;
  203. if (isStart && child.flex && !child.height) {
  204. flexedHeight = Math.ceil((child.flex / remainingFlex) * remainingHeight);
  205. remainingHeight -= flexedHeight;
  206. remainingFlex -= child.flex;
  207. calcs.height = flexedHeight;
  208. calcs.dirtySize = true;
  209. }
  210. }
  211. }
  212. }
  213. if (isCenter) {
  214. topOffset += availableHeight / 2;
  215. } else if (isEnd) {
  216. topOffset += availableHeight;
  217. }
  218. //finally, calculate the left and top position of each item
  219. for (i = 0; i < visibleCount; i++) {
  220. child = visibleItems[i];
  221. calcs = boxes[i];
  222. childMargins = child.margins;
  223. topOffset += childMargins.top;
  224. horizMargins = childMargins.left + childMargins.right;
  225. calcs.left = leftOffset + childMargins.left;
  226. calcs.top = topOffset;
  227. switch (this.align) {
  228. case 'stretch':
  229. stretchWidth = availWidth - horizMargins;
  230. calcs.width = stretchWidth.constrain(child.minWidth || 0, child.maxWidth || 1000000);
  231. calcs.dirtySize = true;
  232. break;
  233. case 'stretchmax':
  234. stretchWidth = maxWidth - horizMargins;
  235. calcs.width = stretchWidth.constrain(child.minWidth || 0, child.maxWidth || 1000000);
  236. calcs.dirtySize = true;
  237. break;
  238. case 'center':
  239. var diff = availWidth - calcs.width - horizMargins;
  240. if (diff > 0) {
  241. calcs.left = leftOffset + horizMargins + (diff / 2);
  242. }
  243. }
  244. topOffset += calcs.height + childMargins.bottom;
  245. }
  246. return {
  247. boxes: boxes,
  248. meta : {
  249. maxWidth : maxWidth,
  250. nonFlexHeight: nonFlexHeight,
  251. desiredHeight: desiredHeight,
  252. minimumHeight: minimumHeight,
  253. shortfall : desiredHeight - height,
  254. tooNarrow : tooNarrow
  255. }
  256. };
  257. }
  258. });
  259. Ext.Container.LAYOUTS.vbox = Ext.layout.VBoxLayout;
  260. </pre>
  261. </body>
  262. </html>