Upgrade to ExtJS 3.1.0 - Released 12/16/2009
[extjs.git] / docs / source / AccordionLayout.html
1 <html>\r
2 <head>\r
3   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    \r
4   <title>The source code</title>\r
5     <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />\r
6     <script type="text/javascript" src="../resources/prettify/prettify.js"></script>\r
7 </head>\r
8 <body  onload="prettyPrint();">\r
9     <pre class="prettyprint lang-js"><div id="cls-Ext.layout.AccordionLayout"></div>/**\r
10  * @class Ext.layout.AccordionLayout\r
11  * @extends Ext.layout.FitLayout\r
12  * <p>This is a layout that manages multiple Panels in an expandable accordion style such that only\r
13  * <b>one Panel can be expanded at any given time</b>. Each Panel has built-in support for expanding and collapsing.</p>\r
14  * <p>Note: Only Ext.Panels <b>and all subclasses of Ext.Panel</b> may be used in an accordion layout Container.</p>\r
15  * <p>This class is intended to be extended or created via the <tt><b>{@link Ext.Container#layout layout}</b></tt>\r
16  * configuration property.  See <tt><b>{@link Ext.Container#layout}</b></tt> for additional details.</p>\r
17  * <p>Example usage:</p>\r
18  * <pre><code>\r
19 var accordion = new Ext.Panel({\r
20     title: 'Accordion Layout',\r
21     layout:'accordion',\r
22     defaults: {\r
23         // applied to each contained panel\r
24         bodyStyle: 'padding:15px'\r
25     },\r
26     layoutConfig: {\r
27         // layout-specific configs go here\r
28         titleCollapse: false,\r
29         animate: true,\r
30         activeOnTop: true\r
31     },\r
32     items: [{\r
33         title: 'Panel 1',\r
34         html: '&lt;p&gt;Panel content!&lt;/p&gt;'\r
35     },{\r
36         title: 'Panel 2',\r
37         html: '&lt;p&gt;Panel content!&lt;/p&gt;'\r
38     },{\r
39         title: 'Panel 3',\r
40         html: '&lt;p&gt;Panel content!&lt;/p&gt;'\r
41     }]\r
42 });\r
43 </code></pre>\r
44  */\r
45 Ext.layout.AccordionLayout = Ext.extend(Ext.layout.FitLayout, {\r
46     <div id="cfg-Ext.layout.AccordionLayout-fill"></div>/**\r
47      * @cfg {Boolean} fill\r
48      * True to adjust the active item's height to fill the available space in the container, false to use the\r
49      * item's current height, or auto height if not explicitly set (defaults to true).\r
50      */\r
51     fill : true,\r
52     <div id="cfg-Ext.layout.AccordionLayout-autoWidth"></div>/**\r
53      * @cfg {Boolean} autoWidth\r
54      * True to set each contained item's width to 'auto', false to use the item's current width (defaults to true).\r
55      * Note that some components, in particular the {@link Ext.grid.GridPanel grid}, will not function properly within\r
56      * layouts if they have auto width, so in such cases this config should be set to false.\r
57      */\r
58     autoWidth : true,\r
59     <div id="cfg-Ext.layout.AccordionLayout-titleCollapse"></div>/**\r
60      * @cfg {Boolean} titleCollapse\r
61      * True to allow expand/collapse of each contained panel by clicking anywhere on the title bar, false to allow\r
62      * expand/collapse only when the toggle tool button is clicked (defaults to true).  When set to false,\r
63      * {@link #hideCollapseTool} should be false also.\r
64      */\r
65     titleCollapse : true,\r
66     <div id="cfg-Ext.layout.AccordionLayout-hideCollapseTool"></div>/**\r
67      * @cfg {Boolean} hideCollapseTool\r
68      * True to hide the contained panels' collapse/expand toggle buttons, false to display them (defaults to false).\r
69      * When set to true, {@link #titleCollapse} should be true also.\r
70      */\r
71     hideCollapseTool : false,\r
72     <div id="cfg-Ext.layout.AccordionLayout-collapseFirst"></div>/**\r
73      * @cfg {Boolean} collapseFirst\r
74      * True to make sure the collapse/expand toggle button always renders first (to the left of) any other tools\r
75      * in the contained panels' title bars, false to render it last (defaults to false).\r
76      */\r
77     collapseFirst : false,\r
78     <div id="cfg-Ext.layout.AccordionLayout-animate"></div>/**\r
79      * @cfg {Boolean} animate\r
80      * True to slide the contained panels open and closed during expand/collapse using animation, false to open and\r
81      * close directly with no animation (defaults to false).  Note: to defer to the specific config setting of each\r
82      * contained panel for this property, set this to undefined at the layout level.\r
83      */\r
84     animate : false,\r
85     <div id="cfg-Ext.layout.AccordionLayout-sequence"></div>/**\r
86      * @cfg {Boolean} sequence\r
87      * <b>Experimental</b>. If animate is set to true, this will result in each animation running in sequence.\r
88      */\r
89     sequence : false,\r
90     <div id="cfg-Ext.layout.AccordionLayout-activeOnTop"></div>/**\r
91      * @cfg {Boolean} activeOnTop\r
92      * True to swap the position of each panel as it is expanded so that it becomes the first item in the container,\r
93      * false to keep the panels in the rendered order. <b>This is NOT compatible with "animate:true"</b> (defaults to false).\r
94      */\r
95     activeOnTop : false,\r
96 \r
97     renderItem : function(c){\r
98         if(this.animate === false){\r
99             c.animCollapse = false;\r
100         }\r
101         c.collapsible = true;\r
102         if(this.autoWidth){\r
103             c.autoWidth = true;\r
104         }\r
105         if(this.titleCollapse){\r
106             c.titleCollapse = true;\r
107         }\r
108         if(this.hideCollapseTool){\r
109             c.hideCollapseTool = true;\r
110         }\r
111         if(this.collapseFirst !== undefined){\r
112             c.collapseFirst = this.collapseFirst;\r
113         }\r
114         if(!this.activeItem && !c.collapsed){\r
115             this.setActiveItem(c, true);\r
116         }else if(this.activeItem && this.activeItem != c){\r
117             c.collapsed = true;\r
118         }\r
119         Ext.layout.AccordionLayout.superclass.renderItem.apply(this, arguments);\r
120         c.header.addClass('x-accordion-hd');\r
121         c.on('beforeexpand', this.beforeExpand, this);\r
122     },\r
123     \r
124     onRemove: function(c){\r
125         Ext.layout.AccordionLayout.superclass.onRemove.call(this, c);\r
126         if(c.rendered){\r
127             c.header.removeClass('x-accordion-hd');\r
128         }\r
129         c.un('beforeexpand', this.beforeExpand, this);\r
130     },\r
131 \r
132     // private\r
133     beforeExpand : function(p, anim){\r
134         var ai = this.activeItem;\r
135         if(ai){\r
136             if(this.sequence){\r
137                 delete this.activeItem;\r
138                 if (!ai.collapsed){\r
139                     ai.collapse({callback:function(){\r
140                         p.expand(anim || true);\r
141                     }, scope: this});\r
142                     return false;\r
143                 }\r
144             }else{\r
145                 ai.collapse(this.animate);\r
146             }\r
147         }\r
148         this.setActive(p);\r
149         if(this.activeOnTop){\r
150             p.el.dom.parentNode.insertBefore(p.el.dom, p.el.dom.parentNode.firstChild);\r
151         }\r
152         this.layout();\r
153     },\r
154 \r
155     // private\r
156     setItemSize : function(item, size){\r
157         if(this.fill && item){\r
158             var hh = 0;\r
159             this.container.items.each(function(p){\r
160                 if(p != item){\r
161                     hh += p.header.getHeight();\r
162                 }    \r
163             });\r
164             size.height -= hh;\r
165             item.setSize(size);\r
166         }\r
167     },\r
168 \r
169     <div id="method-Ext.layout.AccordionLayout-setActiveItem"></div>/**\r
170      * Sets the active (expanded) item in the layout.\r
171      * @param {String/Number} item The string component id or numeric index of the item to activate\r
172      */\r
173     setActiveItem : function(item){\r
174         this.setActive(item, true);\r
175     },\r
176     \r
177     // private\r
178     setActive : function(item, expand){\r
179         var ai = this.activeItem;\r
180         item = this.container.getComponent(item);\r
181         if(ai != item){\r
182             if(item.rendered && item.collapsed && expand){\r
183                 item.expand();\r
184             }else{\r
185                 if(ai){\r
186                    ai.fireEvent('deactivate', ai);\r
187                 }\r
188                 this.activeItem = item;\r
189                 item.fireEvent('activate', item);\r
190             }\r
191         }\r
192     }\r
193 });\r
194 Ext.Container.LAYOUTS.accordion = Ext.layout.AccordionLayout;\r
195 \r
196 //backwards compat\r
197 Ext.layout.Accordion = Ext.layout.AccordionLayout;</pre>    \r
198 </body>\r
199 </html>