Upgrade to ExtJS 3.1.1 - Released 02/08/2010
[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     type: 'accordion',\r
98 \r
99     renderItem : function(c){\r
100         if(this.animate === false){\r
101             c.animCollapse = false;\r
102         }\r
103         c.collapsible = true;\r
104         if(this.autoWidth){\r
105             c.autoWidth = true;\r
106         }\r
107         if(this.titleCollapse){\r
108             c.titleCollapse = true;\r
109         }\r
110         if(this.hideCollapseTool){\r
111             c.hideCollapseTool = true;\r
112         }\r
113         if(this.collapseFirst !== undefined){\r
114             c.collapseFirst = this.collapseFirst;\r
115         }\r
116         if(!this.activeItem && !c.collapsed){\r
117             this.setActiveItem(c, true);\r
118         }else if(this.activeItem && this.activeItem != c){\r
119             c.collapsed = true;\r
120         }\r
121         Ext.layout.AccordionLayout.superclass.renderItem.apply(this, arguments);\r
122         c.header.addClass('x-accordion-hd');\r
123         c.on('beforeexpand', this.beforeExpand, this);\r
124     },\r
125 \r
126     onRemove: function(c){\r
127         Ext.layout.AccordionLayout.superclass.onRemove.call(this, c);\r
128         if(c.rendered){\r
129             c.header.removeClass('x-accordion-hd');\r
130         }\r
131         c.un('beforeexpand', this.beforeExpand, this);\r
132     },\r
133 \r
134     // private\r
135     beforeExpand : function(p, anim){\r
136         var ai = this.activeItem;\r
137         if(ai){\r
138             if(this.sequence){\r
139                 delete this.activeItem;\r
140                 if (!ai.collapsed){\r
141                     ai.collapse({callback:function(){\r
142                         p.expand(anim || true);\r
143                     }, scope: this});\r
144                     return false;\r
145                 }\r
146             }else{\r
147                 ai.collapse(this.animate);\r
148             }\r
149         }\r
150         this.setActive(p);\r
151         if(this.activeOnTop){\r
152             p.el.dom.parentNode.insertBefore(p.el.dom, p.el.dom.parentNode.firstChild);\r
153         }\r
154         // Items have been hidden an possibly rearranged, we need to get the container size again.\r
155         this.layout();\r
156     },\r
157 \r
158     // private\r
159     setItemSize : function(item, size){\r
160         if(this.fill && item){\r
161             var hh = 0, i, ct = this.getRenderedItems(this.container), len = ct.length, p;\r
162             // Add up all the header heights\r
163             for (i = 0; i < len; i++) {\r
164                 if((p = ct[i]) != item){\r
165                     hh += p.header.getHeight();\r
166                 }\r
167             };\r
168             // Subtract the header heights from the container size\r
169             size.height -= hh;\r
170             // Call setSize on the container to set the correct height.  For Panels, deferedHeight\r
171             // will simply store this size for when the expansion is done.\r
172             item.setSize(size);\r
173         }\r
174     },\r
175 \r
176     <div id="method-Ext.layout.AccordionLayout-setActiveItem"></div>/**\r
177      * Sets the active (expanded) item in the layout.\r
178      * @param {String/Number} item The string component id or numeric index of the item to activate\r
179      */\r
180     setActiveItem : function(item){\r
181         this.setActive(item, true);\r
182     },\r
183 \r
184     // private\r
185     setActive : function(item, expand){\r
186         var ai = this.activeItem;\r
187         item = this.container.getComponent(item);\r
188         if(ai != item){\r
189             if(item.rendered && item.collapsed && expand){\r
190                 item.expand();\r
191             }else{\r
192                 if(ai){\r
193                    ai.fireEvent('deactivate', ai);\r
194                 }\r
195                 this.activeItem = item;\r
196                 item.fireEvent('activate', item);\r
197             }\r
198         }\r
199     }\r
200 });\r
201 Ext.Container.LAYOUTS.accordion = Ext.layout.AccordionLayout;\r
202 \r
203 //backwards compat\r
204 Ext.layout.Accordion = Ext.layout.AccordionLayout;</pre>    \r
205 </body>\r
206 </html>