/javascripts/lib/docs/source/AnchorLayout.html

https://bitbucket.org/ksokmesa/sina-asian · HTML · 243 lines · 226 code · 17 blank · 0 comment · 0 complexity · c509bfcc071c4bdc3308bd92bfe41ad1 MD5 · raw file

  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.2.1
  11. * Copyright(c) 2006-2010 Ext JS, Inc.
  12. * licensing@extjs.com
  13. * http://www.extjs.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();
  113. if (!target) {
  114. return {};
  115. }
  116. // Style Sized (scrollbars not included)
  117. return target.getStyleSize();
  118. },
  119. // private
  120. onLayout : function(ct, target){
  121. Ext.layout.AnchorLayout.superclass.onLayout.call(this, ct, target);
  122. var size = this.getLayoutTargetSize();
  123. var w = size.width, h = size.height;
  124. if(w < 20 && h < 20){
  125. return;
  126. }
  127. // find the container anchoring size
  128. var aw, ah;
  129. if(ct.anchorSize){
  130. if(typeof ct.anchorSize == 'number'){
  131. aw = ct.anchorSize;
  132. }else{
  133. aw = ct.anchorSize.width;
  134. ah = ct.anchorSize.height;
  135. }
  136. }else{
  137. aw = ct.initialConfig.width;
  138. ah = ct.initialConfig.height;
  139. }
  140. var cs = this.getRenderedItems(ct), len = cs.length, i, c, a, cw, ch, el, vs, boxes = [];
  141. for(i = 0; i < len; i++){
  142. c = cs[i];
  143. el = c.getPositionEl();
  144. // If a child container item has no anchor and no specific width, set the child to the default anchor size
  145. if (!c.anchor && c.items && !Ext.isNumber(c.width) && !(Ext.isIE6 && Ext.isStrict)){
  146. c.anchor = this.defaultAnchor;
  147. }
  148. if(c.anchor){
  149. a = c.anchorSpec;
  150. if(!a){ // cache all anchor values
  151. vs = c.anchor.split(' ');
  152. c.anchorSpec = a = {
  153. right: this.parseAnchor(vs[0], c.initialConfig.width, aw),
  154. bottom: this.parseAnchor(vs[1], c.initialConfig.height, ah)
  155. };
  156. }
  157. cw = a.right ? this.adjustWidthAnchor(a.right(w) - el.getMargins('lr'), c) : undefined;
  158. ch = a.bottom ? this.adjustHeightAnchor(a.bottom(h) - el.getMargins('tb'), c) : undefined;
  159. if(cw || ch){
  160. boxes.push({
  161. comp: c,
  162. width: cw || undefined,
  163. height: ch || undefined
  164. });
  165. }
  166. }
  167. }
  168. for (i = 0, len = boxes.length; i < len; i++) {
  169. c = boxes[i];
  170. c.comp.setSize(c.width, c.height);
  171. }
  172. },
  173. // private
  174. parseAnchor : function(a, start, cstart){
  175. if(a && a != 'none'){
  176. var last;
  177. // standard anchor
  178. if(this.parseAnchorRE.test(a)){
  179. var diff = cstart - start;
  180. return function(v){
  181. if(v !== last){
  182. last = v;
  183. return v - diff;
  184. }
  185. }
  186. // percentage
  187. }else if(a.indexOf('%') != -1){
  188. var ratio = parseFloat(a.replace('%', ''))*.01;
  189. return function(v){
  190. if(v !== last){
  191. last = v;
  192. return Math.floor(v*ratio);
  193. }
  194. }
  195. // simple offset adjustment
  196. }else{
  197. a = parseInt(a, 10);
  198. if(!isNaN(a)){
  199. return function(v){
  200. if(v !== last){
  201. last = v;
  202. return v + a;
  203. }
  204. }
  205. }
  206. }
  207. }
  208. return false;
  209. },
  210. // private
  211. adjustWidthAnchor : function(value, comp){
  212. return value;
  213. },
  214. // private
  215. adjustHeightAnchor : function(value, comp){
  216. return value;
  217. }
  218. <div id="prop-Ext.layout.AnchorLayout-activeItem"></div>/**
  219. * @property activeItem
  220. * @hide
  221. */
  222. });
  223. Ext.Container.LAYOUTS['anchor'] = Ext.layout.AnchorLayout;
  224. </pre>
  225. </body>
  226. </html>