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>
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.
13 * http://www.extjs.com/license
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>
30 var viewport = new Ext.Viewport({
32 anchorSize: {width:800, height:600},
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/>
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>
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>
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>
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>
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:
95 * </code></pre></div></li>
102 monitorResize : true,
106 <div id="cfg-Ext.layout.AnchorLayout-defaultAnchor"></div>/**
107 * @cfg {String} defaultAnchor
109 * default anchor for all child container items applied if no anchor or specific width is set on the child item. Defaults to '100%'.
112 defaultAnchor : '100%',
114 parseAnchorRE : /^(r|right|b|bottom)$/i,
116 getLayoutTargetSize : function() {
117 var target = this.container.getLayoutTarget();
121 // Style Sized (scrollbars not included)
122 return target.getStyleSize();
126 onLayout : function(ct, target){
127 Ext.layout.AnchorLayout.superclass.onLayout.call(this, ct, target);
128 var size = this.getLayoutTargetSize();
130 var w = size.width, h = size.height;
132 if(w < 20 && h < 20){
136 // find the container anchoring size
139 if(typeof ct.anchorSize == 'number'){
142 aw = ct.anchorSize.width;
143 ah = ct.anchorSize.height;
146 aw = ct.initialConfig.width;
147 ah = ct.initialConfig.height;
150 var cs = this.getRenderedItems(ct), len = cs.length, i, c, a, cw, ch, el, vs, boxes = [];
151 for(i = 0; i < len; i++){
153 el = c.getPositionEl();
155 // If a child container item has no anchor and no specific width, set the child to the default anchor size
156 if (!c.anchor && c.items && !Ext.isNumber(c.width) && !(Ext.isIE6 && Ext.isStrict)){
157 c.anchor = this.defaultAnchor;
162 if(!a){ // cache all anchor values
163 vs = c.anchor.split(' ');
165 right: this.parseAnchor(vs[0], c.initialConfig.width, aw),
166 bottom: this.parseAnchor(vs[1], c.initialConfig.height, ah)
169 cw = a.right ? this.adjustWidthAnchor(a.right(w) - el.getMargins('lr'), c) : undefined;
170 ch = a.bottom ? this.adjustHeightAnchor(a.bottom(h) - el.getMargins('tb'), c) : undefined;
175 width: cw || undefined,
176 height: ch || undefined
181 for (i = 0, len = boxes.length; i < len; i++) {
183 c.comp.setSize(c.width, c.height);
188 parseAnchor : function(a, start, cstart){
189 if(a && a != 'none'){
192 if(this.parseAnchorRE.test(a)){
193 var diff = cstart - start;
201 }else if(a.indexOf('%') != -1){
202 var ratio = parseFloat(a.replace('%', ''))*.01;
206 return Math.floor(v*ratio);
209 // simple offset adjustment
226 adjustWidthAnchor : function(value, comp){
231 adjustHeightAnchor : function(value, comp){
235 <div id="prop-Ext.layout.AnchorLayout-activeItem"></div>/**
236 * @property activeItem
240 Ext.Container.LAYOUTS['anchor'] = Ext.layout.AnchorLayout;