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.

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