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

https://bitbucket.org/srogerf/javascript · HTML · 317 lines · 289 code · 28 blank · 0 comment · 0 complexity · c46c32791aa7ede081806f09725fc405 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-layout-container-Anchor'>/**
  19. </span> * @class Ext.layout.container.Anchor
  20. * @extends Ext.layout.container.Container
  21. *
  22. * This is a layout that enables anchoring of contained elements relative to the container's dimensions.
  23. * If the container is resized, all anchored items are automatically rerendered according to their
  24. * `{@link #anchor}` rules.
  25. *
  26. * This class is intended to be extended or created via the {@link Ext.container.AbstractContainer#layout layout}: 'anchor'
  27. * config, and should generally not need to be created directly via the new keyword.
  28. *
  29. * AnchorLayout does not have any direct config options (other than inherited ones). By default,
  30. * AnchorLayout will calculate anchor measurements based on the size of the container itself. However, the
  31. * container using the AnchorLayout can supply an anchoring-specific config property of `anchorSize`.
  32. *
  33. * If anchorSize is specifed, the layout will use it as a virtual container for the purposes of calculating
  34. * anchor measurements based on it instead, allowing the container to be sized independently of the anchoring
  35. * logic if necessary.
  36. *
  37. * @example
  38. * Ext.create('Ext.Panel', {
  39. * width: 500,
  40. * height: 400,
  41. * title: &quot;AnchorLayout Panel&quot;,
  42. * layout: 'anchor',
  43. * renderTo: Ext.getBody(),
  44. * items: [
  45. * {
  46. * xtype: 'panel',
  47. * title: '75% Width and 20% Height',
  48. * anchor: '75% 20%'
  49. * },
  50. * {
  51. * xtype: 'panel',
  52. * title: 'Offset -300 Width &amp; -200 Height',
  53. * anchor: '-300 -200'
  54. * },
  55. * {
  56. * xtype: 'panel',
  57. * title: 'Mixed Offset and Percent',
  58. * anchor: '-250 20%'
  59. * }
  60. * ]
  61. * });
  62. */
  63. Ext.define('Ext.layout.container.Anchor', {
  64. /* Begin Definitions */
  65. alias: 'layout.anchor',
  66. extend: 'Ext.layout.container.Container',
  67. alternateClassName: 'Ext.layout.AnchorLayout',
  68. /* End Definitions */
  69. <span id='Ext-layout-container-Anchor-cfg-anchor'> /**
  70. </span> * @cfg {String} anchor
  71. *
  72. * This configuation option is to be applied to **child `items`** of a container managed by
  73. * this layout (ie. configured with `layout:'anchor'`).
  74. *
  75. * This value is what tells the layout how an item should be anchored to the container. `items`
  76. * added to an AnchorLayout accept an anchoring-specific config property of **anchor** which is a string
  77. * containing two values: the horizontal anchor value and the vertical anchor value (for example, '100% 50%').
  78. * The following types of anchor values are supported:
  79. *
  80. * - **Percentage** : Any value between 1 and 100, expressed as a percentage.
  81. *
  82. * The first anchor is the percentage width that the item should take up within the container, and the
  83. * second is the percentage height. For example:
  84. *
  85. * // two values specified
  86. * anchor: '100% 50%' // render item complete width of the container and
  87. * // 1/2 height of the container
  88. * // one value specified
  89. * anchor: '100%' // the width value; the height will default to auto
  90. *
  91. * - **Offsets** : Any positive or negative integer value.
  92. *
  93. * This is a raw adjustment where the first anchor is the offset from the right edge of the container,
  94. * and the second is the offset from the bottom edge. For example:
  95. *
  96. * // two values specified
  97. * anchor: '-50 -100' // render item the complete width of the container
  98. * // minus 50 pixels and
  99. * // the complete height minus 100 pixels.
  100. * // one value specified
  101. * anchor: '-50' // anchor value is assumed to be the right offset value
  102. * // bottom offset will default to 0
  103. *
  104. * - **Sides** : Valid values are `right` (or `r`) and `bottom` (or `b`).
  105. *
  106. * Either the container must have a fixed size or an anchorSize config value defined at render time in
  107. * order for these to have any effect.
  108. *
  109. * - **Mixed** :
  110. *
  111. * Anchor values can also be mixed as needed. For example, to render the width offset from the container
  112. * right edge by 50 pixels and 75% of the container's height use:
  113. *
  114. * anchor: '-50 75%'
  115. */
  116. type: 'anchor',
  117. <span id='Ext-layout-container-Anchor-cfg-defaultAnchor'> /**
  118. </span> * @cfg {String} defaultAnchor
  119. * Default anchor for all child &lt;b&gt;container&lt;/b&gt; items applied if no anchor or specific width is set on the child item. Defaults to '100%'.
  120. */
  121. defaultAnchor: '100%',
  122. parseAnchorRE: /^(r|right|b|bottom)$/i,
  123. // private
  124. onLayout: function() {
  125. this.callParent(arguments);
  126. var me = this,
  127. size = me.getLayoutTargetSize(),
  128. owner = me.owner,
  129. target = me.getTarget(),
  130. ownerWidth = size.width,
  131. ownerHeight = size.height,
  132. overflow = target.getStyle('overflow'),
  133. components = me.getVisibleItems(owner),
  134. len = components.length,
  135. boxes = [],
  136. box, newTargetSize, component, anchorSpec, calcWidth, calcHeight,
  137. i, el, cleaner;
  138. if (ownerWidth &lt; 20 &amp;&amp; ownerHeight &lt; 20) {
  139. return;
  140. }
  141. // Anchor layout uses natural HTML flow to arrange the child items.
  142. // To ensure that all browsers (I'm looking at you IE!) add the bottom margin of the last child to the
  143. // containing element height, we create a zero-sized element with style clear:both to force a &quot;new line&quot;
  144. if (!me.clearEl) {
  145. me.clearEl = target.createChild({
  146. cls: Ext.baseCSSPrefix + 'clear',
  147. role: 'presentation'
  148. });
  149. }
  150. // Work around WebKit RightMargin bug. We're going to inline-block all the children only ONCE and remove it when we're done
  151. if (!Ext.supports.RightMargin) {
  152. cleaner = Ext.Element.getRightMarginFixCleaner(target);
  153. target.addCls(Ext.baseCSSPrefix + 'inline-children');
  154. }
  155. for (i = 0; i &lt; len; i++) {
  156. component = components[i];
  157. el = component.el;
  158. anchorSpec = component.anchorSpec;
  159. if (anchorSpec) {
  160. if (anchorSpec.right) {
  161. calcWidth = me.adjustWidthAnchor(anchorSpec.right(ownerWidth) - el.getMargin('lr'), component);
  162. } else {
  163. calcWidth = undefined;
  164. }
  165. if (anchorSpec.bottom) {
  166. calcHeight = me.adjustHeightAnchor(anchorSpec.bottom(ownerHeight) - el.getMargin('tb'), component);
  167. } else {
  168. calcHeight = undefined;
  169. }
  170. boxes.push({
  171. component: component,
  172. anchor: true,
  173. width: calcWidth || undefined,
  174. height: calcHeight || undefined
  175. });
  176. } else {
  177. boxes.push({
  178. component: component,
  179. anchor: false
  180. });
  181. }
  182. }
  183. // Work around WebKit RightMargin bug. We're going to inline-block all the children only ONCE and remove it when we're done
  184. if (!Ext.supports.RightMargin) {
  185. target.removeCls(Ext.baseCSSPrefix + 'inline-children');
  186. cleaner();
  187. }
  188. for (i = 0; i &lt; len; i++) {
  189. box = boxes[i];
  190. me.setItemSize(box.component, box.width, box.height);
  191. }
  192. if (overflow &amp;&amp; overflow != 'hidden' &amp;&amp; !me.adjustmentPass) {
  193. newTargetSize = me.getLayoutTargetSize();
  194. if (newTargetSize.width != size.width || newTargetSize.height != size.height) {
  195. me.adjustmentPass = true;
  196. me.onLayout();
  197. }
  198. }
  199. delete me.adjustmentPass;
  200. },
  201. // private
  202. parseAnchor: function(a, start, cstart) {
  203. if (a &amp;&amp; a != 'none') {
  204. var ratio;
  205. // standard anchor
  206. if (this.parseAnchorRE.test(a)) {
  207. var diff = cstart - start;
  208. return function(v) {
  209. return v - diff;
  210. };
  211. }
  212. // percentage
  213. else if (a.indexOf('%') != -1) {
  214. ratio = parseFloat(a.replace('%', '')) * 0.01;
  215. return function(v) {
  216. return Math.floor(v * ratio);
  217. };
  218. }
  219. // simple offset adjustment
  220. else {
  221. a = parseInt(a, 10);
  222. if (!isNaN(a)) {
  223. return function(v) {
  224. return v + a;
  225. };
  226. }
  227. }
  228. }
  229. return null;
  230. },
  231. // private
  232. adjustWidthAnchor: function(value, comp) {
  233. return value;
  234. },
  235. // private
  236. adjustHeightAnchor: function(value, comp) {
  237. return value;
  238. },
  239. configureItem: function(item) {
  240. var me = this,
  241. owner = me.owner,
  242. anchor= item.anchor,
  243. anchorsArray,
  244. anchorSpec,
  245. anchorWidth,
  246. anchorHeight;
  247. if (!item.anchor &amp;&amp; item.items &amp;&amp; !Ext.isNumber(item.width) &amp;&amp; !(Ext.isIE6 &amp;&amp; Ext.isStrict)) {
  248. item.anchor = anchor = me.defaultAnchor;
  249. }
  250. // find the container anchoring size
  251. if (owner.anchorSize) {
  252. if (typeof owner.anchorSize == 'number') {
  253. anchorWidth = owner.anchorSize;
  254. }
  255. else {
  256. anchorWidth = owner.anchorSize.width;
  257. anchorHeight = owner.anchorSize.height;
  258. }
  259. }
  260. else {
  261. anchorWidth = owner.initialConfig.width;
  262. anchorHeight = owner.initialConfig.height;
  263. }
  264. if (anchor) {
  265. // cache all anchor values
  266. anchorsArray = anchor.split(' ');
  267. item.anchorSpec = anchorSpec = {
  268. right: me.parseAnchor(anchorsArray[0], item.initialConfig.width, anchorWidth),
  269. bottom: me.parseAnchor(anchorsArray[1], item.initialConfig.height, anchorHeight)
  270. };
  271. if (anchorSpec.right) {
  272. item.layoutManagedWidth = 1;
  273. } else {
  274. item.layoutManagedWidth = 2;
  275. }
  276. if (anchorSpec.bottom) {
  277. item.layoutManagedHeight = 1;
  278. } else {
  279. item.layoutManagedHeight = 2;
  280. }
  281. } else {
  282. item.layoutManagedWidth = 2;
  283. item.layoutManagedHeight = 2;
  284. }
  285. this.callParent(arguments);
  286. }
  287. });</pre>
  288. </body>
  289. </html>