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.

276 lines
10 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.AnchorLayout"></div>/**
  16. * @class Ext.layout.AnchorLayout
  17. * @extends Ext.layout.ContainerLayout
  18. * <p>This is a layout that enables anchoring of contained elements relative to the container's dimensions.
  19. * If the container is resized, all anchored items are automatically rerendered according to their
  20. * <b><tt>{@link #anchor}</tt></b> rules.</p>
  21. * <p>This class is intended to be extended or created via the layout:'anchor' {@link Ext.Container#layout}
  22. * config, and should generally not need to be created directly via the new keyword.</p>
  23. * <p>AnchorLayout does not have any direct config options (other than inherited ones). By default,
  24. * AnchorLayout will calculate anchor measurements based on the size of the container itself. However, the
  25. * container using the AnchorLayout can supply an anchoring-specific config property of <b>anchorSize</b>.
  26. * If anchorSize is specifed, the layout will use it as a virtual container for the purposes of calculating
  27. * anchor measurements based on it instead, allowing the container to be sized independently of the anchoring
  28. * logic if necessary. For example:</p>
  29. * <pre><code>
  30. var viewport = new Ext.Viewport({
  31. layout:'anchor',
  32. anchorSize: {width:800, height:600},
  33. items:[{
  34. title:'Item 1',
  35. html:'Content 1',
  36. width:800,
  37. anchor:'right 20%'
  38. },{
  39. title:'Item 2',
  40. html:'Content 2',
  41. width:300,
  42. anchor:'50% 30%'
  43. },{
  44. title:'Item 3',
  45. html:'Content 3',
  46. width:600,
  47. anchor:'-100 50%'
  48. }]
  49. });
  50. * </code></pre>
  51. */
  52. Ext.layout.AnchorLayout = Ext.extend(Ext.layout.ContainerLayout, {
  53. <div id="cfg-Ext.layout.AnchorLayout-anchor"></div>/**
  54. * @cfg {String} anchor
  55. * <p>This configuation option is to be applied to <b>child <tt>items</tt></b> of a container managed by
  56. * this layout (ie. configured with <tt>layout:'anchor'</tt>).</p><br/>
  57. *
  58. * <p>This value is what tells the layout how an item should be anchored to the container. <tt>items</tt>
  59. * added to an AnchorLayout accept an anchoring-specific config property of <b>anchor</b> which is a string
  60. * containing two values: the horizontal anchor value and the vertical anchor value (for example, '100% 50%').
  61. * The following types of anchor values are supported:<div class="mdetail-params"><ul>
  62. *
  63. * <li><b>Percentage</b> : Any value between 1 and 100, expressed as a percentage.<div class="sub-desc">
  64. * The first anchor is the percentage width that the item should take up within the container, and the
  65. * second is the percentage height. For example:<pre><code>
  66. // two values specified
  67. anchor: '100% 50%' // render item complete width of the container and
  68. // 1/2 height of the container
  69. // one value specified
  70. anchor: '100%' // the width value; the height will default to auto
  71. * </code></pre></div></li>
  72. *
  73. * <li><b>Offsets</b> : Any positive or negative integer value.<div class="sub-desc">
  74. * This is a raw adjustment where the first anchor is the offset from the right edge of the container,
  75. * and the second is the offset from the bottom edge. For example:<pre><code>
  76. // two values specified
  77. anchor: '-50 -100' // render item the complete width of the container
  78. // minus 50 pixels and
  79. // the complete height minus 100 pixels.
  80. // one value specified
  81. anchor: '-50' // anchor value is assumed to be the right offset value
  82. // bottom offset will default to 0
  83. * </code></pre></div></li>
  84. *
  85. * <li><b>Sides</b> : Valid values are <tt>'right'</tt> (or <tt>'r'</tt>) and <tt>'bottom'</tt>
  86. * (or <tt>'b'</tt>).<div class="sub-desc">
  87. * Either the container must have a fixed size or an anchorSize config value defined at render time in
  88. * order for these to have any effect.</div></li>
  89. *
  90. * <li><b>Mixed</b> : <div class="sub-desc">
  91. * Anchor values can also be mixed as needed. For example, to render the width offset from the container
  92. * right edge by 50 pixels and 75% of the container's height use:
  93. * <pre><code>
  94. anchor: '-50 75%'
  95. * </code></pre></div></li>
  96. *
  97. *
  98. * </ul></div>
  99. */
  100. // private
  101. monitorResize : true,
  102. type : 'anchor',
  103. <div id="cfg-Ext.layout.AnchorLayout-defaultAnchor"></div>/**
  104. * @cfg {String} defaultAnchor
  105. *
  106. * default anchor for all child container items applied if no anchor or specific width is set on the child item. Defaults to '100%'.
  107. *
  108. */
  109. defaultAnchor : '100%',
  110. parseAnchorRE : /^(r|right|b|bottom)$/i,
  111. getLayoutTargetSize : function() {
  112. var target = this.container.getLayoutTarget(), ret = {};
  113. if (target) {
  114. ret = target.getViewSize();
  115. // IE in strict mode will return a width of 0 on the 1st pass of getViewSize.
  116. // Use getStyleSize to verify the 0 width, the adjustment pass will then work properly
  117. // with getViewSize
  118. if (Ext.isIE && Ext.isStrict && ret.width == 0){
  119. ret = target.getStyleSize();
  120. }
  121. ret.width -= target.getPadding('lr');
  122. ret.height -= target.getPadding('tb');
  123. }
  124. return ret;
  125. },
  126. // private
  127. onLayout : function(container, target) {
  128. Ext.layout.AnchorLayout.superclass.onLayout.call(this, container, target);
  129. var size = this.getLayoutTargetSize(),
  130. containerWidth = size.width,
  131. containerHeight = size.height,
  132. overflow = target.getStyle('overflow'),
  133. components = this.getRenderedItems(container),
  134. len = components.length,
  135. boxes = [],
  136. box,
  137. anchorWidth,
  138. anchorHeight,
  139. component,
  140. anchorSpec,
  141. calcWidth,
  142. calcHeight,
  143. anchorsArray,
  144. totalHeight = 0,
  145. i,
  146. el;
  147. if(containerWidth < 20 && containerHeight < 20){
  148. return;
  149. }
  150. // find the container anchoring size
  151. if(container.anchorSize) {
  152. if(typeof container.anchorSize == 'number') {
  153. anchorWidth = container.anchorSize;
  154. } else {
  155. anchorWidth = container.anchorSize.width;
  156. anchorHeight = container.anchorSize.height;
  157. }
  158. } else {
  159. anchorWidth = container.initialConfig.width;
  160. anchorHeight = container.initialConfig.height;
  161. }
  162. for(i = 0; i < len; i++) {
  163. component = components[i];
  164. el = component.getPositionEl();
  165. // If a child container item has no anchor and no specific width, set the child to the default anchor size
  166. if (!component.anchor && component.items && !Ext.isNumber(component.width) && !(Ext.isIE6 && Ext.isStrict)){
  167. component.anchor = this.defaultAnchor;
  168. }
  169. if(component.anchor) {
  170. anchorSpec = component.anchorSpec;
  171. // cache all anchor values
  172. if(!anchorSpec){
  173. anchorsArray = component.anchor.split(' ');
  174. component.anchorSpec = anchorSpec = {
  175. right: this.parseAnchor(anchorsArray[0], component.initialConfig.width, anchorWidth),
  176. bottom: this.parseAnchor(anchorsArray[1], component.initialConfig.height, anchorHeight)
  177. };
  178. }
  179. calcWidth = anchorSpec.right ? this.adjustWidthAnchor(anchorSpec.right(containerWidth) - el.getMargins('lr'), component) : undefined;
  180. calcHeight = anchorSpec.bottom ? this.adjustHeightAnchor(anchorSpec.bottom(containerHeight) - el.getMargins('tb'), component) : undefined;
  181. if(calcWidth || calcHeight) {
  182. boxes.push({
  183. component: component,
  184. width: calcWidth || undefined,
  185. height: calcHeight || undefined
  186. });
  187. }
  188. }
  189. }
  190. for (i = 0, len = boxes.length; i < len; i++) {
  191. box = boxes[i];
  192. box.component.setSize(box.width, box.height);
  193. }
  194. if (overflow && overflow != 'hidden' && !this.adjustmentPass) {
  195. var newTargetSize = this.getLayoutTargetSize();
  196. if (newTargetSize.width != size.width || newTargetSize.height != size.height){
  197. this.adjustmentPass = true;
  198. this.onLayout(container, target);
  199. }
  200. }
  201. delete this.adjustmentPass;
  202. },
  203. // private
  204. parseAnchor : function(a, start, cstart) {
  205. if (a && a != 'none') {
  206. var last;
  207. // standard anchor
  208. if (this.parseAnchorRE.test(a)) {
  209. var diff = cstart - start;
  210. return function(v){
  211. if(v !== last){
  212. last = v;
  213. return v - diff;
  214. }
  215. };
  216. // percentage
  217. } else if(a.indexOf('%') != -1) {
  218. var ratio = parseFloat(a.replace('%', ''))*.01;
  219. return function(v){
  220. if(v !== last){
  221. last = v;
  222. return Math.floor(v*ratio);
  223. }
  224. };
  225. // simple offset adjustment
  226. } else {
  227. a = parseInt(a, 10);
  228. if (!isNaN(a)) {
  229. return function(v) {
  230. if (v !== last) {
  231. last = v;
  232. return v + a;
  233. }
  234. };
  235. }
  236. }
  237. }
  238. return false;
  239. },
  240. // private
  241. adjustWidthAnchor : function(value, comp){
  242. return value;
  243. },
  244. // private
  245. adjustHeightAnchor : function(value, comp){
  246. return value;
  247. }
  248. <div id="prop-Ext.layout.AnchorLayout-activeItem"></div>/**
  249. * @property activeItem
  250. * @hide
  251. */
  252. });
  253. Ext.Container.LAYOUTS['anchor'] = Ext.layout.AnchorLayout;
  254. </pre>
  255. </body>
  256. </html>