-Ext.Container = Ext.extend(Ext.BoxComponent, {
- <div id="cfg-Ext.Container-monitorResize"></div>/**
- * @cfg {Boolean} monitorResize
- * True to automatically monitor window resize events to handle anything that is sensitive to the current size
- * of the viewport. This value is typically managed by the chosen <code>{@link #layout}</code> and should not need
- * to be set manually.
- */
- <div id="cfg-Ext.Container-layout"></div>/**
- * @cfg {String/Object} layout
- * <p><b>*Important</b>: In order for child items to be correctly sized and
- * positioned, typically a layout manager <b>must</b> be specified through
- * the <code>layout</code> configuration option.</p>
- * <br><p>The sizing and positioning of child {@link items} is the responsibility of
- * the Container's layout manager which creates and manages the type of layout
- * you have in mind. For example:</p><pre><code>
-new Ext.Window({
- width:300, height: 300,
- layout: 'fit', // explicitly set layout manager: override the default (layout:'auto')
- items: [{
- title: 'Panel inside a Window'
- }]
-}).show();
- * </code></pre>
- * <p>If the {@link #layout} configuration is not explicitly specified for
- * a general purpose container (e.g. Container or Panel) the
- * {@link Ext.layout.ContainerLayout default layout manager} will be used
- * which does nothing but render child components sequentially into the
- * Container (no sizing or positioning will be performed in this situation).
- * Some container classes implicitly specify a default layout
- * (e.g. FormPanel specifies <code>layout:'form'</code>). Other specific
- * purpose classes internally specify/manage their internal layout (e.g.
- * GridPanel, TabPanel, TreePanel, Toolbar, Menu, etc.).</p>
- * <br><p><b><code>layout</code></b> may be specified as either as an Object or
- * as a String:</p><div><ul class="mdetail-params">
- *
- * <li><u>Specify as an Object</u></li>
- * <div><ul class="mdetail-params">
- * <li>Example usage:</li>
-<pre><code>
-layout: {
- type: 'vbox',
- padding: '5',
- align: 'left'
-}
-</code></pre>
- *
- * <li><code><b>type</b></code></li>
- * <br/><p>The layout type to be used for this container. If not specified,
- * a default {@link Ext.layout.ContainerLayout} will be created and used.</p>
- * <br/><p>Valid layout <code>type</code> values are:</p>
- * <div class="sub-desc"><ul class="mdetail-params">
- * <li><code><b>{@link Ext.layout.AbsoluteLayout absolute}</b></code></li>
- * <li><code><b>{@link Ext.layout.AccordionLayout accordion}</b></code></li>
- * <li><code><b>{@link Ext.layout.AnchorLayout anchor}</b></code></li>
- * <li><code><b>{@link Ext.layout.ContainerLayout auto}</b></code> <b>Default</b></li>
- * <li><code><b>{@link Ext.layout.BorderLayout border}</b></code></li>
- * <li><code><b>{@link Ext.layout.CardLayout card}</b></code></li>
- * <li><code><b>{@link Ext.layout.ColumnLayout column}</b></code></li>
- * <li><code><b>{@link Ext.layout.FitLayout fit}</b></code></li>
- * <li><code><b>{@link Ext.layout.FormLayout form}</b></code></li>
- * <li><code><b>{@link Ext.layout.HBoxLayout hbox}</b></code></li>
- * <li><code><b>{@link Ext.layout.MenuLayout menu}</b></code></li>
- * <li><code><b>{@link Ext.layout.TableLayout table}</b></code></li>
- * <li><code><b>{@link Ext.layout.ToolbarLayout toolbar}</b></code></li>
- * <li><code><b>{@link Ext.layout.VBoxLayout vbox}</b></code></li>
- * </ul></div>
- *
- * <li>Layout specific configuration properties</li>
- * <br/><p>Additional layout specific configuration properties may also be
- * specified. For complete details regarding the valid config options for
- * each layout type, see the layout class corresponding to the <code>type</code>
- * specified.</p>
- *
- * </ul></div>
- *
- * <li><u>Specify as a String</u></li>
- * <div><ul class="mdetail-params">
- * <li>Example usage:</li>
-<pre><code>
-layout: 'vbox',
-layoutConfig: {
- padding: '5',
- align: 'left'
-}
-</code></pre>
- * <li><code><b>layout</b></code></li>
- * <br/><p>The layout <code>type</code> to be used for this container (see list
- * of valid layout type values above).</p><br/>
- * <li><code><b>{@link #layoutConfig}</b></code></li>
- * <br/><p>Additional layout specific configuration properties. For complete
- * details regarding the valid config options for each layout type, see the
- * layout class corresponding to the <code>layout</code> specified.</p>
- * </ul></div></ul></div>
- */
- <div id="cfg-Ext.Container-layoutConfig"></div>/**
- * @cfg {Object} layoutConfig
- * This is a config object containing properties specific to the chosen
- * <b><code>{@link #layout}</code></b> if <b><code>{@link #layout}</code></b>
- * has been specified as a <i>string</i>.</p>
- */
- <div id="cfg-Ext.Container-bufferResize"></div>/**
- * @cfg {Boolean/Number} bufferResize
- * When set to true (50 milliseconds) or a number of milliseconds, the layout assigned for this container will buffer
- * the frequency it calculates and does a re-layout of components. This is useful for heavy containers or containers
- * with a large quantity of sub-components for which frequent layout calls would be expensive. Defaults to <code>50</code>.
- */
- bufferResize: 50,
-
- <div id="cfg-Ext.Container-activeItem"></div>/**
- * @cfg {String/Number} activeItem
- * A string component id or the numeric index of the component that should be initially activated within the
- * container's layout on render. For example, activeItem: 'item-1' or activeItem: 0 (index 0 = the first
- * item in the container's collection). activeItem only applies to layout styles that can display
- * items one at a time (like {@link Ext.layout.AccordionLayout}, {@link Ext.layout.CardLayout} and
- * {@link Ext.layout.FitLayout}). Related to {@link Ext.layout.ContainerLayout#activeItem}.
- */
- <div id="cfg-Ext.Container-items"></div>/**
- * @cfg {Object/Array} items
- * <pre><b>** IMPORTANT</b>: be sure to <b>{@link #layout specify a <code>layout</code>} if needed ! **</b></pre>
- * <p>A single item, or an array of child Components to be added to this container,
- * for example:</p>
- * <pre><code>
-// specifying a single item
-items: {...},
-layout: 'fit', // specify a layout!
-
-// specifying multiple items
-items: [{...}, {...}],
-layout: 'anchor', // specify a layout!
- * </code></pre>
- * <p>Each item may be:</p>
- * <div><ul class="mdetail-params">
- * <li>any type of object based on {@link Ext.Component}</li>
- * <li>a fully instanciated object or</li>
- * <li>an object literal that:</li>
- * <div><ul class="mdetail-params">
- * <li>has a specified <code>{@link Ext.Component#xtype xtype}</code></li>
- * <li>the {@link Ext.Component#xtype} specified is associated with the Component
- * desired and should be chosen from one of the available xtypes as listed
- * in {@link Ext.Component}.</li>
- * <li>If an <code>{@link Ext.Component#xtype xtype}</code> is not explicitly
- * specified, the {@link #defaultType} for that Container is used.</li>
- * <li>will be "lazily instanciated", avoiding the overhead of constructing a fully
- * instanciated Component object</li>
- * </ul></div></ul></div>
- * <p><b>Notes</b>:</p>
- * <div><ul class="mdetail-params">
- * <li>Ext uses lazy rendering. Child Components will only be rendered
- * should it become necessary. Items are automatically laid out when they are first
- * shown (no sizing is done while hidden), or in response to a {@link #doLayout} call.</li>
- * <li>Do not specify <code>{@link Ext.Panel#contentEl contentEl}</code>/
- * <code>{@link Ext.Panel#html html}</code> with <code>items</code>.</li>
- * </ul></div>
- */
- <div id="cfg-Ext.Container-defaults"></div>/**
- * @cfg {Object|Function} defaults
- * <p>This option is a means of applying default settings to all added items whether added through the {@link #items}
- * config or via the {@link #add} or {@link #insert} methods.</p>
- * <p>If an added item is a config object, and <b>not</b> an instantiated Component, then the default properties are
- * unconditionally applied. If the added item <b>is</b> an instantiated Component, then the default properties are
- * applied conditionally so as not to override existing properties in the item.</p>
- * <p>If the defaults option is specified as a function, then the function will be called using this Container as the
- * scope (<code>this</code> reference) and passing the added item as the first parameter. Any resulting object
- * from that call is then applied to the item as default properties.</p>
- * <p>For example, to automatically apply padding to the body of each of a set of
- * contained {@link Ext.Panel} items, you could pass: <code>defaults: {bodyStyle:'padding:15px'}</code>.</p>
- * <p>Usage:</p><pre><code>
-defaults: { // defaults are applied to items, not the container
- autoScroll:true
-},
-items: [
- {
- xtype: 'panel', // defaults <b>do not</b> have precedence over
- id: 'panel1', // options in config objects, so the defaults
- autoScroll: false // will not be applied here, panel1 will be autoScroll:false
- },
- new Ext.Panel({ // defaults <b>do</b> have precedence over options
- id: 'panel2', // options in components, so the defaults
- autoScroll: false // will be applied here, panel2 will be autoScroll:true.
- })
-]
- * </code></pre>
- */
-
-
- <div id="cfg-Ext.Container-autoDestroy"></div>/** @cfg {Boolean} autoDestroy
- * If true the container will automatically destroy any contained component that is removed from it, else
- * destruction must be handled manually (defaults to true).
- */
- autoDestroy : true,
-
- <div id="cfg-Ext.Container-forceLayout"></div>/** @cfg {Boolean} forceLayout
- * If true the container will force a layout initially even if hidden or collapsed. This option
- * is useful for forcing forms to render in collapsed or hidden containers. (defaults to false).
- */
- forceLayout: false,
-
- <div id="cfg-Ext.Container-hideBorders"></div>/** @cfg {Boolean} hideBorders
- * True to hide the borders of each contained component, false to defer to the component's existing
- * border settings (defaults to false).
- */
- <div id="cfg-Ext.Container-defaultType"></div>/** @cfg {String} defaultType
- * <p>The default {@link Ext.Component xtype} of child Components to create in this Container when
- * a child item is specified as a raw configuration object, rather than as an instantiated Component.</p>
- * <p>Defaults to <code>'panel'</code>, except {@link Ext.menu.Menu} which defaults to <code>'menuitem'</code>,
- * and {@link Ext.Toolbar} and {@link Ext.ButtonGroup} which default to <code>'button'</code>.</p>
- */
- defaultType : 'panel',
-
- <div id="cfg-Ext.Container-resizeEvent"></div>/** @cfg {String} resizeEvent
- * The event to listen to for resizing in layouts. Defaults to <code>'resize'</code>.
- */
- resizeEvent: 'resize',
-
- <div id="cfg-Ext.Container-bubbleEvents"></div>/**
- * @cfg {Array} bubbleEvents
- * <p>An array of events that, when fired, should be bubbled to any parent container.
- * See {@link Ext.util.Observable#enableBubble}.
- * Defaults to <code>['add', 'remove']</code>.
- */
- bubbleEvents: ['add', 'remove'],
-
- // private
- initComponent : function(){
- Ext.Container.superclass.initComponent.call(this);
-
- this.addEvents(
- <div id="event-Ext.Container-afterlayout"></div>/**
- * @event afterlayout
- * Fires when the components in this container are arranged by the associated layout manager.
- * @param {Ext.Container} this
- * @param {ContainerLayout} layout The ContainerLayout implementation for this container
- */
- 'afterlayout',
- <div id="event-Ext.Container-beforeadd"></div>/**
- * @event beforeadd
- * Fires before any {@link Ext.Component} is added or inserted into the container.
- * A handler can return false to cancel the add.
- * @param {Ext.Container} this
- * @param {Ext.Component} component The component being added
- * @param {Number} index The index at which the component will be added to the container's items collection
- */
- 'beforeadd',
- <div id="event-Ext.Container-beforeremove"></div>/**
- * @event beforeremove
- * Fires before any {@link Ext.Component} is removed from the container. A handler can return
- * false to cancel the remove.
- * @param {Ext.Container} this
- * @param {Ext.Component} component The component being removed
- */
- 'beforeremove',
- <div id="event-Ext.Container-add"></div>/**
- * @event add
- * @bubbles
- * Fires after any {@link Ext.Component} is added or inserted into the container.
- * @param {Ext.Container} this
- * @param {Ext.Component} component The component that was added
- * @param {Number} index The index at which the component was added to the container's items collection
- */
- 'add',
- <div id="event-Ext.Container-remove"></div>/**
- * @event remove
- * @bubbles
- * Fires after any {@link Ext.Component} is removed from the container.
- * @param {Ext.Container} this
- * @param {Ext.Component} component The component that was removed
- */
- 'remove'
- );
-
- <div id="prop-Ext.Container-items"></div>/**
- * The collection of components in this container as a {@link Ext.util.MixedCollection}
- * @type MixedCollection
- * @property items
- */
- var items = this.items;
- if(items){
- delete this.items;
- this.add(items);
- }
- },
-
- // private
- initItems : function(){
- if(!this.items){
- this.items = new Ext.util.MixedCollection(false, this.getComponentId);
- this.getLayout(); // initialize the layout
- }
- },
-
- // private
- setLayout : function(layout){
- if(this.layout && this.layout != layout){
- this.layout.setContainer(null);
- }
- this.layout = layout;
- this.initItems();
- layout.setContainer(this);
- },
-
- afterRender: function(){
- // Render this Container, this should be done before setLayout is called which
- // will hook onResize
- Ext.Container.superclass.afterRender.call(this);
- if(!this.layout){
- this.layout = 'auto';
- }
- if(Ext.isObject(this.layout) && !this.layout.layout){
- this.layoutConfig = this.layout;
- this.layout = this.layoutConfig.type;
- }
- if(Ext.isString(this.layout)){
- this.layout = new Ext.Container.LAYOUTS[this.layout.toLowerCase()](this.layoutConfig);
- }
- this.setLayout(this.layout);
-
- // If a CardLayout, the active item set
- if(this.activeItem !== undefined){
- var item = this.activeItem;
- delete this.activeItem;
- this.layout.setActiveItem(item);
- }
-
- // If we have no ownerCt, render and size all children
- if(!this.ownerCt){
- this.doLayout(false, true);
- }
-
- // This is a manually configured flag set by users in conjunction with renderTo.
- // Not to be confused with the flag by the same name used in Layouts.
- if(this.monitorResize === true){
- Ext.EventManager.onWindowResize(this.doLayout, this, [false]);
- }
- },
-
- <div id="method-Ext.Container-getLayoutTarget"></div>/**
- * <p>Returns the Element to be used to contain the child Components of this Container.</p>
- * <p>An implementation is provided which returns the Container's {@link #getEl Element}, but
- * if there is a more complex structure to a Container, this may be overridden to return
- * the element into which the {@link #layout layout} renders child Components.</p>
- * @return {Ext.Element} The Element to render child Components into.
- */
- getLayoutTarget : function(){
- return this.el;
- },
-
- // private - used as the key lookup function for the items collection
- getComponentId : function(comp){
- return comp.getItemId();
- },
-
- <div id="method-Ext.Container-add"></div>/**
- * <p>Adds {@link Ext.Component Component}(s) to this Container.</p>
- * <br><p><b>Description</b></u> :
- * <div><ul class="mdetail-params">
- * <li>Fires the {@link #beforeadd} event before adding</li>
- * <li>The Container's {@link #defaults default config values} will be applied
- * accordingly (see <code>{@link #defaults}</code> for details).</li>
- * <li>Fires the {@link #add} event after the component has been added.</li>
- * </ul></div>
- * <br><p><b>Notes</b></u> :
- * <div><ul class="mdetail-params">
- * <li>If the Container is <i>already rendered</i> when <code>add</code>
- * is called, you may need to call {@link #doLayout} to refresh the view which causes
- * any unrendered child Components to be rendered. This is required so that you can
- * <code>add</code> multiple child components if needed while only refreshing the layout
- * once. For example:<pre><code>
-var tb = new {@link Ext.Toolbar}();
-tb.render(document.body); // toolbar is rendered
-tb.add({text:'Button 1'}); // add multiple items ({@link #defaultType} for {@link Ext.Toolbar Toolbar} is 'button')
-tb.add({text:'Button 2'});
-tb.{@link #doLayout}(); // refresh the layout
- * </code></pre></li>
- * <li><i>Warning:</i> Containers directly managed by the BorderLayout layout manager
- * may not be removed or added. See the Notes for {@link Ext.layout.BorderLayout BorderLayout}
- * for more details.</li>
- * </ul></div>
- * @param {...Object/Array} component
- * <p>Either one or more Components to add or an Array of Components to add. See
- * <code>{@link #items}</code> for additional information.</p>
- * @return {Ext.Component/Array} The Components that were added.
- */
- add : function(comp){
- this.initItems();
- var args = arguments.length > 1;
- if(args || Ext.isArray(comp)){
- var result = [];
- Ext.each(args ? arguments : comp, function(c){
- result.push(this.add(c));
- }, this);
- return result;
- }
- var c = this.lookupComponent(this.applyDefaults(comp));
- var index = this.items.length;
- if(this.fireEvent('beforeadd', this, c, index) !== false && this.onBeforeAdd(c) !== false){
- this.items.add(c);
- // *onAdded
- c.onAdded(this, index);
- this.onAdd(c);
- this.fireEvent('add', this, c, index);
- }
- return c;
- },
-
- onAdd : function(c){
- // Empty template method
- },
-
- // private
- onAdded : function(container, pos) {
- //overridden here so we can cascade down, not worth creating a template method.
- this.ownerCt = container;
- this.initRef();
- //initialize references for child items
- this.cascade(function(c){
- c.initRef();
- });
- this.fireEvent('added', this, container, pos);
- },
-
- <div id="method-Ext.Container-insert"></div>/**
- * Inserts a Component into this Container at a specified index. Fires the
- * {@link #beforeadd} event before inserting, then fires the {@link #add} event after the
- * Component has been inserted.
- * @param {Number} index The index at which the Component will be inserted
- * into the Container's items collection
- * @param {Ext.Component} component The child Component to insert.<br><br>
- * Ext uses lazy rendering, and will only render the inserted Component should
- * it become necessary.<br><br>
- * A Component config object may be passed in order to avoid the overhead of
- * constructing a real Component object if lazy rendering might mean that the
- * inserted Component will not be rendered immediately. To take advantage of
- * this 'lazy instantiation', set the {@link Ext.Component#xtype} config
- * property to the registered type of the Component wanted.<br><br>
- * For a list of all available xtypes, see {@link Ext.Component}.
- * @return {Ext.Component} component The Component (or config object) that was
- * inserted with the Container's default config values applied.
- */
- insert : function(index, comp){
- this.initItems();
- var a = arguments, len = a.length;
- if(len > 2){
- var result = [];
- for(var i = len-1; i >= 1; --i) {
- result.push(this.insert(index, a[i]));
- }
- return result;
- }
- var c = this.lookupComponent(this.applyDefaults(comp));
- index = Math.min(index, this.items.length);
- if(this.fireEvent('beforeadd', this, c, index) !== false && this.onBeforeAdd(c) !== false){
- if(c.ownerCt == this){
- this.items.remove(c);
- }
- this.items.insert(index, c);
- c.onAdded(this, index);
- this.onAdd(c);
- this.fireEvent('add', this, c, index);
- }
- return c;
- },
-
- // private
- applyDefaults : function(c){
- var d = this.defaults;
- if(d){
- if(Ext.isFunction(d)){
- d = d.call(this, c);
- }
- if(Ext.isString(c)){
- c = Ext.ComponentMgr.get(c);
- Ext.apply(c, d);
- }else if(!c.events){
- Ext.applyIf(c, d);
- }else{
- Ext.apply(c, d);
- }
- }
- return c;
- },
-
- // private
- onBeforeAdd : function(item){
- if(item.ownerCt){
- item.ownerCt.remove(item, false);
- }
- if(this.hideBorders === true){
- item.border = (item.border === true);
- }
- },
-
- <div id="method-Ext.Container-remove"></div>/**
- * Removes a component from this container. Fires the {@link #beforeremove} event before removing, then fires
- * the {@link #remove} event after the component has been removed.
- * @param {Component/String} component The component reference or id to remove.
- * @param {Boolean} autoDestroy (optional) True to automatically invoke the removed Component's {@link Ext.Component#destroy} function.
- * Defaults to the value of this Container's {@link #autoDestroy} config.
- * @return {Ext.Component} component The Component that was removed.
- */
- remove : function(comp, autoDestroy){
- this.initItems();
- var c = this.getComponent(comp);
- if(c && this.fireEvent('beforeremove', this, c) !== false){
- this.doRemove(c, autoDestroy);
- this.fireEvent('remove', this, c);
- }
- return c;
- },
-
- onRemove: function(c){
- // Empty template method
- },
-
- // private
- doRemove: function(c, autoDestroy){
- var l = this.layout,
- hasLayout = l && this.rendered;
-
- if(hasLayout){
- l.onRemove(c);
- }
- this.items.remove(c);
- c.onRemoved();
- this.onRemove(c);
- if(autoDestroy === true || (autoDestroy !== false && this.autoDestroy)){
- c.destroy();
- }
- if(hasLayout){
- l.afterRemove(c);
- }
- },
-
- <div id="method-Ext.Container-removeAll"></div>/**
- * Removes all components from this container.
- * @param {Boolean} autoDestroy (optional) True to automatically invoke the removed Component's {@link Ext.Component#destroy} function.
- * Defaults to the value of this Container's {@link #autoDestroy} config.
- * @return {Array} Array of the destroyed components
- */
- removeAll: function(autoDestroy){
- this.initItems();
- var item, rem = [], items = [];
- this.items.each(function(i){
- rem.push(i);
- });
- for (var i = 0, len = rem.length; i < len; ++i){
- item = rem[i];
- this.remove(item, autoDestroy);
- if(item.ownerCt !== this){
- items.push(item);