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.3.1
11 * Copyright(c) 2006-2010 Sencha Inc.
12 * licensing@sencha.com
13 * http://www.sencha.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,
117 getLayoutTargetSize : function() {
118 var target = this.container.getLayoutTarget(), ret = {};
120 ret = target.getViewSize();
122 // IE in strict mode will return a width of 0 on the 1st pass of getViewSize.
123 // Use getStyleSize to verify the 0 width, the adjustment pass will then work properly
125 if (Ext.isIE && Ext.isStrict && ret.width == 0){
126 ret = target.getStyleSize();
128 ret.width -= target.getPadding('lr');
129 ret.height -= target.getPadding('tb');
135 onLayout : function(container, target) {
136 Ext.layout.AnchorLayout.superclass.onLayout.call(this, container, target);
138 var size = this.getLayoutTargetSize(),
139 containerWidth = size.width,
140 containerHeight = size.height,
141 overflow = target.getStyle('overflow'),
142 components = this.getRenderedItems(container),
143 len = components.length,
157 if(containerWidth < 20 && containerHeight < 20){
161 // find the container anchoring size
162 if(container.anchorSize) {
163 if(typeof container.anchorSize == 'number') {
164 anchorWidth = container.anchorSize;
166 anchorWidth = container.anchorSize.width;
167 anchorHeight = container.anchorSize.height;
170 anchorWidth = container.initialConfig.width;
171 anchorHeight = container.initialConfig.height;
174 for(i = 0; i < len; i++) {
175 component = components[i];
176 el = component.getPositionEl();
178 // If a child container item has no anchor and no specific width, set the child to the default anchor size
179 if (!component.anchor && component.items && !Ext.isNumber(component.width) && !(Ext.isIE6 && Ext.isStrict)){
180 component.anchor = this.defaultAnchor;
183 if(component.anchor) {
184 anchorSpec = component.anchorSpec;
185 // cache all anchor values
187 anchorsArray = component.anchor.split(' ');
188 component.anchorSpec = anchorSpec = {
189 right: this.parseAnchor(anchorsArray[0], component.initialConfig.width, anchorWidth),
190 bottom: this.parseAnchor(anchorsArray[1], component.initialConfig.height, anchorHeight)
193 calcWidth = anchorSpec.right ? this.adjustWidthAnchor(anchorSpec.right(containerWidth) - el.getMargins('lr'), component) : undefined;
194 calcHeight = anchorSpec.bottom ? this.adjustHeightAnchor(anchorSpec.bottom(containerHeight) - el.getMargins('tb'), component) : undefined;
196 if(calcWidth || calcHeight) {
198 component: component,
199 width: calcWidth || undefined,
200 height: calcHeight || undefined
205 for (i = 0, len = boxes.length; i < len; i++) {
207 box.component.setSize(box.width, box.height);
210 if (overflow && overflow != 'hidden' && !this.adjustmentPass) {
211 var newTargetSize = this.getLayoutTargetSize();
212 if (newTargetSize.width != size.width || newTargetSize.height != size.height){
213 this.adjustmentPass = true;
214 this.onLayout(container, target);
218 delete this.adjustmentPass;
222 parseAnchor : function(a, start, cstart) {
223 if (a && a != 'none') {
226 if (this.parseAnchorRE.test(a)) {
227 var diff = cstart - start;
235 } else if(a.indexOf('%') != -1) {
236 var ratio = parseFloat(a.replace('%', ''))*.01;
240 return Math.floor(v*ratio);
243 // simple offset adjustment
260 adjustWidthAnchor : function(value, comp){
265 adjustHeightAnchor : function(value, comp){
269 <div id="prop-Ext.layout.AnchorLayout-activeItem"></div>/**
270 * @property activeItem
274 Ext.Container.LAYOUTS['anchor'] = Ext.layout.AnchorLayout;