2 * Ext JS Library 2.2.1
\r
3 * Copyright(c) 2006-2009, Ext JS, LLC.
\r
4 * licensing@extjs.com
\r
6 * http://extjs.com/license
\r
10 * @class Ext.layout.Accordion
\r
11 * @extends Ext.layout.FitLayout
\r
12 * <p>This is a layout that contains multiple panels in an expandable accordion style such that only one
\r
13 * panel can be open at any given time. Each panel has built-in support for expanding and collapsing.
\r
14 * This class is intended to be extended or created via the layout:'accordion' {@link Ext.Container#layout}
\r
15 * config, and should generally not need to be created directly via the new keyword.</p>
\r
16 * <p>Note that when creating a layout via config, the layout-specific config properties must be passed in via
\r
17 * the {@link Ext.Container#layoutConfig} object which will then be applied internally to the layout.
\r
18 * Example usage:</p>
\r
20 var accordion = new Ext.Panel({
\r
21 title: 'Accordion Layout',
\r
24 // applied to each contained panel
\r
25 bodyStyle: 'padding:15px'
\r
28 // layout-specific configs go here
\r
29 titleCollapse: false,
\r
35 html: '<p>Panel content!</p>'
\r
38 html: '<p>Panel content!</p>'
\r
41 html: '<p>Panel content!</p>'
\r
46 Ext.layout.Accordion = Ext.extend(Ext.layout.FitLayout, {
\r
48 * @cfg {Boolean} fill
\r
49 * True to adjust the active item's height to fill the available space in the container, false to use the
\r
50 * item's current height, or auto height if not explicitly set (defaults to true).
\r
54 * @cfg {Boolean} autoWidth
\r
55 * True to set each contained item's width to 'auto', false to use the item's current width (defaults to true).
\r
56 * Note that some components, in particular the {@link Ext.grid.GridPanel grid}, will not function properly within
\r
57 * layouts if they have auto width, so in such cases this config should be set to false.
\r
61 * @cfg {Boolean} titleCollapse
\r
62 * True to allow expand/collapse of each contained panel by clicking anywhere on the title bar, false to allow
\r
63 * expand/collapse only when the toggle tool button is clicked (defaults to true). When set to false,
\r
64 * {@link #hideCollapseTool} should be false also.
\r
66 titleCollapse : true,
\r
68 * @cfg {Boolean} hideCollapseTool
\r
69 * True to hide the contained panels' collapse/expand toggle buttons, false to display them (defaults to false).
\r
70 * When set to true, {@link #titleCollapse} should be true also.
\r
72 hideCollapseTool : false,
\r
74 * @cfg {Boolean} collapseFirst
\r
75 * True to make sure the collapse/expand toggle button always renders first (to the left of) any other tools
\r
76 * in the contained panels' title bars, false to render it last (defaults to false).
\r
78 collapseFirst : false,
\r
80 * @cfg {Boolean} animate
\r
81 * True to slide the contained panels open and closed during expand/collapse using animation, false to open and
\r
82 * close directly with no animation (defaults to false). Note: to defer to the specific config setting of each
\r
83 * contained panel for this property, set this to undefined at the layout level.
\r
87 * @cfg {Boolean} sequence
\r
88 * <b>Experimental</b>. If animate is set to true, this will result in each animation running in sequence.
\r
92 * @cfg {Boolean} activeOnTop
\r
93 * True to swap the position of each panel as it is expanded so that it becomes the first item in the container,
\r
94 * false to keep the panels in the rendered order. <b>This is NOT compatible with "animate:true"</b> (defaults to false).
\r
96 activeOnTop : false,
\r
98 renderItem : function(c){
\r
99 if(this.animate === false){
\r
100 c.animCollapse = false;
\r
102 c.collapsible = true;
\r
103 if(this.autoWidth){
\r
104 c.autoWidth = true;
\r
106 if(this.titleCollapse){
\r
107 c.titleCollapse = true;
\r
109 if(this.hideCollapseTool){
\r
110 c.hideCollapseTool = true;
\r
112 if(this.collapseFirst !== undefined){
\r
113 c.collapseFirst = this.collapseFirst;
\r
115 if(!this.activeItem && !c.collapsed){
\r
116 this.activeItem = c;
\r
117 }else if(this.activeItem){
\r
118 c.collapsed = true;
\r
120 Ext.layout.Accordion.superclass.renderItem.apply(this, arguments);
\r
121 c.header.addClass('x-accordion-hd');
\r
122 c.on('beforeexpand', this.beforeExpand, this);
\r
126 beforeExpand : function(p, anim){
\r
127 var ai = this.activeItem;
\r
130 delete this.activeItem;
\r
131 if (!ai.collapsed){
\r
132 ai.collapse({callback:function(){
\r
133 p.expand(anim || true);
\r
138 ai.collapse(this.animate);
\r
141 this.activeItem = p;
\r
142 if(this.activeOnTop){
\r
143 p.el.dom.parentNode.insertBefore(p.el.dom, p.el.dom.parentNode.firstChild);
\r
149 setItemSize : function(item, size){
\r
150 if(this.fill && item){
\r
151 var items = this.container.items.items;
\r
153 for(var i = 0, len = items.length; i < len; i++){
\r
156 hh += (p.getSize().height - p.bwrap.getHeight());
\r
160 item.setSize(size);
\r
164 Ext.Container.LAYOUTS['accordion'] = Ext.layout.Accordion;