Web UI for ARGUS server
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.

354 lines
13 KiB

6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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.BoxLayout"></div>/**
  16. * @class Ext.layout.BoxLayout
  17. * @extends Ext.layout.ContainerLayout
  18. * <p>Base Class for HBoxLayout and VBoxLayout Classes. Generally it should not need to be used directly.</p>
  19. */
  20. Ext.layout.BoxLayout = Ext.extend(Ext.layout.ContainerLayout, {
  21. <div id="cfg-Ext.layout.BoxLayout-defaultMargins"></div>/**
  22. * @cfg {Object} defaultMargins
  23. * <p>If the individual contained items do not have a <tt>margins</tt>
  24. * property specified, the default margins from this property will be
  25. * applied to each item.</p>
  26. * <br><p>This property may be specified as an object containing margins
  27. * to apply in the format:</p><pre><code>
  28. {
  29. top: (top margin),
  30. right: (right margin),
  31. bottom: (bottom margin),
  32. left: (left margin)
  33. }</code></pre>
  34. * <p>This property may also be specified as a string containing
  35. * space-separated, numeric margin values. The order of the sides associated
  36. * with each value matches the way CSS processes margin values:</p>
  37. * <div class="mdetail-params"><ul>
  38. * <li>If there is only one value, it applies to all sides.</li>
  39. * <li>If there are two values, the top and bottom borders are set to the
  40. * first value and the right and left are set to the second.</li>
  41. * <li>If there are three values, the top is set to the first value, the left
  42. * and right are set to the second, and the bottom is set to the third.</li>
  43. * <li>If there are four values, they apply to the top, right, bottom, and
  44. * left, respectively.</li>
  45. * </ul></div>
  46. * <p>Defaults to:</p><pre><code>
  47. * {top:0, right:0, bottom:0, left:0}
  48. * </code></pre>
  49. */
  50. defaultMargins : {left:0,top:0,right:0,bottom:0},
  51. <div id="cfg-Ext.layout.BoxLayout-padding"></div>/**
  52. * @cfg {String} padding
  53. * <p>Sets the padding to be applied to all child items managed by this layout.</p>
  54. * <p>This property must be specified as a string containing
  55. * space-separated, numeric padding values. The order of the sides associated
  56. * with each value matches the way CSS processes padding values:</p>
  57. * <div class="mdetail-params"><ul>
  58. * <li>If there is only one value, it applies to all sides.</li>
  59. * <li>If there are two values, the top and bottom borders are set to the
  60. * first value and the right and left are set to the second.</li>
  61. * <li>If there are three values, the top is set to the first value, the left
  62. * and right are set to the second, and the bottom is set to the third.</li>
  63. * <li>If there are four values, they apply to the top, right, bottom, and
  64. * left, respectively.</li>
  65. * </ul></div>
  66. * <p>Defaults to: <code>"0"</code></p>
  67. */
  68. padding : '0',
  69. // documented in subclasses
  70. pack : 'start',
  71. // private
  72. monitorResize : true,
  73. type: 'box',
  74. scrollOffset : 0,
  75. extraCls : 'x-box-item',
  76. targetCls : 'x-box-layout-ct',
  77. innerCls : 'x-box-inner',
  78. constructor : function(config){
  79. Ext.layout.BoxLayout.superclass.constructor.call(this, config);
  80. if (Ext.isString(this.defaultMargins)) {
  81. this.defaultMargins = this.parseMargins(this.defaultMargins);
  82. }
  83. var handler = this.overflowHandler;
  84. if (typeof handler == 'string') {
  85. handler = {
  86. type: handler
  87. };
  88. }
  89. var handlerType = 'none';
  90. if (handler && handler.type != undefined) {
  91. handlerType = handler.type;
  92. }
  93. var constructor = Ext.layout.boxOverflow[handlerType];
  94. if (constructor[this.type]) {
  95. constructor = constructor[this.type];
  96. }
  97. this.overflowHandler = new constructor(this, handler);
  98. },
  99. /**
  100. * @private
  101. * Runs the child box calculations and caches them in childBoxCache. Subclasses can used these cached values
  102. * when laying out
  103. */
  104. onLayout: function(container, target) {
  105. Ext.layout.BoxLayout.superclass.onLayout.call(this, container, target);
  106. var tSize = this.getLayoutTargetSize(),
  107. items = this.getVisibleItems(container),
  108. calcs = this.calculateChildBoxes(items, tSize),
  109. boxes = calcs.boxes,
  110. meta = calcs.meta;
  111. //invoke the overflow handler, if one is configured
  112. if (tSize.width > 0) {
  113. var handler = this.overflowHandler,
  114. method = meta.tooNarrow ? 'handleOverflow' : 'clearOverflow';
  115. var results = handler[method](calcs, tSize);
  116. if (results) {
  117. if (results.targetSize) {
  118. tSize = results.targetSize;
  119. }
  120. if (results.recalculate) {
  121. items = this.getVisibleItems(container);
  122. calcs = this.calculateChildBoxes(items, tSize);
  123. boxes = calcs.boxes;
  124. }
  125. }
  126. }
  127. /**
  128. * @private
  129. * @property layoutTargetLastSize
  130. * @type Object
  131. * Private cache of the last measured size of the layout target. This should never be used except by
  132. * BoxLayout subclasses during their onLayout run.
  133. */
  134. this.layoutTargetLastSize = tSize;
  135. /**
  136. * @private
  137. * @property childBoxCache
  138. * @type Array
  139. * Array of the last calculated height, width, top and left positions of each visible rendered component
  140. * within the Box layout.
  141. */
  142. this.childBoxCache = calcs;
  143. this.updateInnerCtSize(tSize, calcs);
  144. this.updateChildBoxes(boxes);
  145. // Putting a box layout into an overflowed container is NOT correct and will make a second layout pass necessary.
  146. this.handleTargetOverflow(tSize, container, target);
  147. },
  148. <div id="method-Ext.layout.BoxLayout-updateChildBoxes"></div>/**
  149. * Resizes and repositions each child component
  150. * @param {Array} boxes The box measurements
  151. */
  152. updateChildBoxes: function(boxes) {
  153. for (var i = 0, length = boxes.length; i < length; i++) {
  154. var box = boxes[i],
  155. comp = box.component;
  156. if (box.dirtySize) {
  157. comp.setSize(box.width, box.height);
  158. }
  159. // Don't set positions to NaN
  160. if (isNaN(box.left) || isNaN(box.top)) {
  161. continue;
  162. }
  163. comp.setPosition(box.left, box.top);
  164. }
  165. },
  166. /**
  167. * @private
  168. * Called by onRender just before the child components are sized and positioned. This resizes the innerCt
  169. * to make sure all child items fit within it. We call this before sizing the children because if our child
  170. * items are larger than the previous innerCt size the browser will insert scrollbars and then remove them
  171. * again immediately afterwards, giving a performance hit.
  172. * Subclasses should provide an implementation.
  173. * @param {Object} currentSize The current height and width of the innerCt
  174. * @param {Array} calculations The new box calculations of all items to be laid out
  175. */
  176. updateInnerCtSize: function(tSize, calcs) {
  177. var align = this.align,
  178. padding = this.padding,
  179. width = tSize.width,
  180. height = tSize.height;
  181. if (this.type == 'hbox') {
  182. var innerCtWidth = width,
  183. innerCtHeight = calcs.meta.maxHeight + padding.top + padding.bottom;
  184. if (align == 'stretch') {
  185. innerCtHeight = height;
  186. } else if (align == 'middle') {
  187. innerCtHeight = Math.max(height, innerCtHeight);
  188. }
  189. } else {
  190. var innerCtHeight = height,
  191. innerCtWidth = calcs.meta.maxWidth + padding.left + padding.right;
  192. if (align == 'stretch') {
  193. innerCtWidth = width;
  194. } else if (align == 'center') {
  195. innerCtWidth = Math.max(width, innerCtWidth);
  196. }
  197. }
  198. this.innerCt.setSize(innerCtWidth || undefined, innerCtHeight || undefined);
  199. },
  200. /**
  201. * @private
  202. * This should be called after onLayout of any BoxLayout subclass. If the target's overflow is not set to 'hidden',
  203. * we need to lay out a second time because the scrollbars may have modified the height and width of the layout
  204. * target. Having a Box layout inside such a target is therefore not recommended.
  205. * @param {Object} previousTargetSize The size and height of the layout target before we just laid out
  206. * @param {Ext.Container} container The container
  207. * @param {Ext.Element} target The target element
  208. */
  209. handleTargetOverflow: function(previousTargetSize, container, target) {
  210. var overflow = target.getStyle('overflow');
  211. if (overflow && overflow != 'hidden' &&!this.adjustmentPass) {
  212. var newTargetSize = this.getLayoutTargetSize();
  213. if (newTargetSize.width != previousTargetSize.width || newTargetSize.height != previousTargetSize.height){
  214. this.adjustmentPass = true;
  215. this.onLayout(container, target);
  216. }
  217. }
  218. delete this.adjustmentPass;
  219. },
  220. // private
  221. isValidParent : function(c, target) {
  222. return this.innerCt && c.getPositionEl().dom.parentNode == this.innerCt.dom;
  223. },
  224. /**
  225. * @private
  226. * Returns all items that are both rendered and visible
  227. * @return {Array} All matching items
  228. */
  229. getVisibleItems: function(ct) {
  230. var ct = ct || this.container,
  231. t = ct.getLayoutTarget(),
  232. cti = ct.items.items,
  233. len = cti.length,
  234. i, c, items = [];
  235. for (i = 0; i < len; i++) {
  236. if((c = cti[i]).rendered && this.isValidParent(c, t) && c.hidden !== true && c.collapsed !== true && c.shouldLayout !== false){
  237. items.push(c);
  238. }
  239. }
  240. return items;
  241. },
  242. // private
  243. renderAll : function(ct, target) {
  244. if (!this.innerCt) {
  245. // the innerCt prevents wrapping and shuffling while the container is resizing
  246. this.innerCt = target.createChild({cls:this.innerCls});
  247. this.padding = this.parseMargins(this.padding);
  248. }
  249. Ext.layout.BoxLayout.superclass.renderAll.call(this, ct, this.innerCt);
  250. },
  251. getLayoutTargetSize : function() {
  252. var target = this.container.getLayoutTarget(), ret;
  253. if (target) {
  254. ret = target.getViewSize();
  255. // IE in strict mode will return a width of 0 on the 1st pass of getViewSize.
  256. // Use getStyleSize to verify the 0 width, the adjustment pass will then work properly
  257. // with getViewSize
  258. if (Ext.isIE && Ext.isStrict && ret.width == 0){
  259. ret = target.getStyleSize();
  260. }
  261. ret.width -= target.getPadding('lr');
  262. ret.height -= target.getPadding('tb');
  263. }
  264. return ret;
  265. },
  266. // private
  267. renderItem : function(c) {
  268. if(Ext.isString(c.margins)){
  269. c.margins = this.parseMargins(c.margins);
  270. }else if(!c.margins){
  271. c.margins = this.defaultMargins;
  272. }
  273. Ext.layout.BoxLayout.superclass.renderItem.apply(this, arguments);
  274. },
  275. /**
  276. * @private
  277. */
  278. destroy: function() {
  279. Ext.destroy(this.overflowHandler);
  280. Ext.layout.BoxLayout.superclass.destroy.apply(this, arguments);
  281. }
  282. });
  283. Ext.ns('Ext.layout.boxOverflow');
  284. <div id="cls-Ext.layout.boxOverflow.None"></div>/**
  285. * @class Ext.layout.boxOverflow.None
  286. * @extends Object
  287. * Base class for Box Layout overflow handlers. These specialized classes are invoked when a Box Layout
  288. * (either an HBox or a VBox) has child items that are either too wide (for HBox) or too tall (for VBox)
  289. * for its container.
  290. */
  291. Ext.layout.boxOverflow.None = Ext.extend(Object, {
  292. constructor: function(layout, config) {
  293. this.layout = layout;
  294. Ext.apply(this, config || {});
  295. },
  296. handleOverflow: Ext.emptyFn,
  297. clearOverflow: Ext.emptyFn
  298. });
  299. Ext.layout.boxOverflow.none = Ext.layout.boxOverflow.None;
  300. </pre>
  301. </body>
  302. </html>