3 <title>The source code</title>
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 <body onload="prettyPrint();">
8 <pre class="prettyprint lang-js">/*!
10 * Copyright(c) 2006-2009 Ext JS, LLC
12 * http://www.extjs.com/license
14 <div id="cls-Ext.layout.ContainerLayout"></div>/**
15 * @class Ext.layout.ContainerLayout
16 * <p>The ContainerLayout class is the default layout manager delegated by {@link Ext.Container} to
17 * render any child Components when no <tt>{@link Ext.Container#layout layout}</tt> is configured into
18 * a {@link Ext.Container Container}. ContainerLayout provides the basic foundation for all other layout
19 * classes in Ext. It simply renders all child Components into the Container, performing no sizing or
20 * positioning services. To utilize a layout that provides sizing and positioning of child Components,
21 * specify an appropriate <tt>{@link Ext.Container#layout layout}</tt>.</p>
22 * <p>This class is intended to be extended or created via the <tt><b>{@link Ext.Container#layout layout}</b></tt>
23 * configuration property. See <tt><b>{@link Ext.Container#layout}</b></tt> for additional details.</p>
25 Ext.layout.ContainerLayout = function(config){
26 Ext.apply(this, config);
29 Ext.layout.ContainerLayout.prototype = {
30 <div id="cfg-Ext.layout.ContainerLayout-extraCls"></div>/**
31 * @cfg {String} extraCls
32 * <p>An optional extra CSS class that will be added to the container. This can be useful for adding
33 * customized styles to the container or any of its children using standard CSS rules. See
34 * {@link Ext.Component}.{@link Ext.Component#ctCls ctCls} also.</p>
35 * <p><b>Note</b>: <tt>extraCls</tt> defaults to <tt>''</tt> except for the following classes
36 * which assign a value by default:
37 * <div class="mdetail-params"><ul>
38 * <li>{@link Ext.layout.AbsoluteLayout Absolute Layout} : <tt>'x-abs-layout-item'</tt></li>
39 * <li>{@link Ext.layout.Box Box Layout} : <tt>'x-box-item'</tt></li>
40 * <li>{@link Ext.layout.ColumnLayout Column Layout} : <tt>'x-column'</tt></li>
42 * To configure the above Classes with an extra CSS class append to the default. For example,
43 * for ColumnLayout:<pre><code>
44 * extraCls: 'x-column custom-class'
48 <div id="cfg-Ext.layout.ContainerLayout-renderHidden"></div>/**
49 * @cfg {Boolean} renderHidden
50 * True to hide each contained item on render (defaults to false).
53 <div id="prop-Ext.layout.ContainerLayout-activeItem"></div>/**
54 * A reference to the {@link Ext.Component} that is active. For example, <pre><code>
55 * if(myPanel.layout.activeItem.id == 'item-1') { ... }
57 * <tt>activeItem</tt> only applies to layout styles that can display items one at a time
58 * (like {@link Ext.layout.AccordionLayout}, {@link Ext.layout.CardLayout}
59 * and {@link Ext.layout.FitLayout}). Read-only. Related to {@link Ext.Container#activeItem}.
60 * @type {Ext.Component}
61 * @property activeItem
71 var target = this.container.getLayoutTarget();
72 this.onLayout(this.container, target);
73 this.container.fireEvent('afterlayout', this.container, this);
77 onLayout : function(ct, target){
78 this.renderAll(ct, target);
82 isValidParent : function(c, target){
83 return target && c.getDomPositionEl().dom.parentNode == (target.dom || target);
87 renderAll : function(ct, target){
88 var items = ct.items.items;
89 for(var i = 0, len = items.length; i < len; i++) {
91 if(c && (!c.rendered || !this.isValidParent(c, target))){
92 this.renderItem(c, i, target);
98 renderItem : function(c, position, target){
100 c.render(target, position);
101 this.configureItem(c, position);
102 }else if(c && !this.isValidParent(c, target)){
103 if(Ext.isNumber(position)){
104 position = target.dom.childNodes[position];
106 target.dom.insertBefore(c.getDomPositionEl().dom, position || null);
107 c.container = target;
108 this.configureItem(c, position);
113 configureItem: function(c, position){
115 var t = c.getPositionEl ? c.getPositionEl() : c;
116 t.addClass(this.extraCls);
118 if (this.renderHidden && c != this.activeItem) {
121 if(c.doLayout && this.forceLayout){
122 c.doLayout(false, true);
126 onRemove: function(c){
127 if(this.activeItem == c){
128 delete this.activeItem;
130 if(c.rendered && this.extraCls){
131 var t = c.getPositionEl ? c.getPositionEl() : c;
132 t.removeClass(this.extraCls);
137 onResize: function(){
138 var ct = this.container,
144 if(b = ct.bufferResize){
145 // Only allow if we should buffer the layout
146 if(ct.shouldBufferLayout()){
147 if(!this.resizeTask){
148 this.resizeTask = new Ext.util.DelayedTask(this.runLayout, this);
149 this.resizeBuffer = Ext.isNumber(b) ? b : 50;
151 ct.layoutPending = true;
152 this.resizeTask.delay(this.resizeBuffer);
160 runLayout: function(){
161 var ct = this.container;
163 delete ct.layoutPending;
167 setContainer : function(ct){
168 if(this.monitorResize && ct != this.container){
169 var old = this.container;
171 old.un(old.resizeEvent, this.onResize, this);
174 ct.on(ct.resizeEvent, this.onResize, this);
181 parseMargins : function(v){
185 var ms = v.split(' ');
200 top:parseInt(ms[0], 10) || 0,
201 right:parseInt(ms[1], 10) || 0,
202 bottom:parseInt(ms[2], 10) || 0,
203 left:parseInt(ms[3], 10) || 0
207 <div id="prop-Ext.layout.ContainerLayout-fieldTpl"></div>/**
208 * The {@link Ext.Template Ext.Template} used by Field rendering layout classes (such as
209 * {@link Ext.layout.FormLayout}) to create the DOM structure of a fully wrapped,
210 * labeled and styled form Field. A default Template is supplied, but this may be
211 * overriden to create custom field structures. The template processes values returned from
212 * {@link Ext.layout.FormLayout#getTemplateArgs}.
216 fieldTpl: (function() {
217 var t = new Ext.Template(
218 '<div class="x-form-item {itemCls}" tabIndex="-1">',
219 '<label for="{id}" style="{labelStyle}" class="x-form-item-label">{label}{labelSeparator}</label>',
220 '<div class="x-form-element" id="x-form-el-{id}" style="{elementStyle}">',
221 '</div><div class="{clearCls}"></div>',
224 t.disableFormats = true;
229 * Destroys this layout. This is a template method that is empty by default, but should be implemented
230 * by subclasses that require explicit destruction to purge event handlers or remove DOM nodes.
233 destroy : Ext.emptyFn
235 Ext.Container.LAYOUTS['auto'] = Ext.layout.ContainerLayout;</pre>