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