1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-layout.container.Accordion'>/**
2 </span> * @class Ext.layout.container.Accordion
3 * @extends Ext.layout.container.VBox
4 * <p>This is a layout that manages multiple Panels in an expandable accordion style such that only
5 * <b>one Panel can be expanded at any given time</b>. Each Panel has built-in support for expanding and collapsing.</p>
6 * <p>Note: Only Ext.Panels <b>and all subclasses of Ext.panel.Panel</b> may be used in an accordion layout Container.</p>
7 * {@img Ext.layout.container.Accordion/Ext.layout.container.Accordion.png Ext.layout.container.Accordion container layout}
8 * <p>Example usage:</p>
9 * <pre><code>
10 Ext.create('Ext.panel.Panel', {
11 title: 'Accordion Layout',
16 // applied to each contained panel
17 bodyStyle: 'padding:15px'
20 // layout-specific configs go here
27 html: 'Panel content!'
30 html: 'Panel content!'
33 html: 'Panel content!'
35 renderTo: Ext.getBody()
37 </code></pre>
39 Ext.define('Ext.layout.container.Accordion', {
40 extend: 'Ext.layout.container.VBox',
41 alias: ['layout.accordion'],
42 alternateClassName: 'Ext.layout.AccordionLayout',
46 <span id='Ext-layout.container.Accordion-cfg-fill'> /**
47 </span> * @cfg {Boolean} fill
48 * True to adjust the active item's height to fill the available space in the container, false to use the
49 * item's current height, or auto height if not explicitly set (defaults to true).
52 <span id='Ext-layout.container.Accordion-cfg-autoWidth'> /**
53 </span> * @cfg {Boolean} autoWidth
54 * <p><b>This config is ignored in ExtJS 4.x.</b></p>
55 * Child Panels have their width actively managed to fit within the accordion's width.
58 <span id='Ext-layout.container.Accordion-cfg-titleCollapse'> /**
59 </span> * @cfg {Boolean} titleCollapse
60 * <p><b>Not implemented in PR2.</b></p>
61 * True to allow expand/collapse of each contained panel by clicking anywhere on the title bar, false to allow
62 * expand/collapse only when the toggle tool button is clicked (defaults to true). When set to false,
63 * {@link #hideCollapseTool} should be false also.
66 <span id='Ext-layout.container.Accordion-cfg-hideCollapseTool'> /**
67 </span> * @cfg {Boolean} hideCollapseTool
68 * True to hide the contained Panels' collapse/expand toggle buttons, false to display them (defaults to false).
69 * When set to true, {@link #titleCollapse} is automatically set to <code>true</code>.
71 hideCollapseTool : false,
72 <span id='Ext-layout.container.Accordion-cfg-collapseFirst'> /**
73 </span> * @cfg {Boolean} collapseFirst
74 * True to make sure the collapse/expand toggle button always renders first (to the left of) any other tools
75 * in the contained Panels' title bars, false to render it last (defaults to false).
77 collapseFirst : false,
78 <span id='Ext-layout.container.Accordion-cfg-animate'> /**
79 </span> * @cfg {Boolean} animate
80 * True to slide the contained panels open and closed during expand/collapse using animation, false to open and
81 * close directly with no animation (defaults to <code>true</code>). Note: The layout performs animated collapsing
82 * and expanding, <i>not</i> the child Panels.
85 <span id='Ext-layout.container.Accordion-cfg-activeOnTop'> /**
86 </span> * @cfg {Boolean} activeOnTop
87 * <p><b>Not implemented in PR4.</b></p>
88 * <p>Only valid when {@link #multi" is <code>false</code>.</p>
89 * True to swap the position of each panel as it is expanded so that it becomes the first item in the container,
90 * false to keep the panels in the rendered order. <b>This is NOT compatible with "animate:true"</b> (defaults to false).
93 <span id='Ext-layout.container.Accordion-cfg-multi'> /**
94 </span> * @cfg {Boolean} multi
95 * Defaults to <code>false</code>. Set to <code>true</code> to enable multiple accordion items to be open at once.
99 constructor: function() {
102 me.callParent(arguments);
104 // animate flag must be false during initial render phase so we don't get animations.
105 me.initialAnimate = me.animate;
108 // Child Panels are not absolutely positioned if we are not filling, so use a different itemCls.
109 if (me.fill === false) {
110 me.itemCls = Ext.baseCSSPrefix + 'accordion-item';
114 // Cannot lay out a fitting accordion before we have been allocated a height.
115 // So during render phase, layout will not be performed.
116 beforeLayout: function() {
119 me.callParent(arguments);
121 if (!me.owner.el.dom.style.height) {
125 me.owner.componentLayout.monitorChildren = false;
127 me.owner.setAutoScroll(true);
131 renderItems : function(items, target) {
136 targetSize = me.getLayoutTargetSize(),
140 for (; i < ln; i++) {
142 if (!comp.rendered) {
143 renderedPanels.push(comp);
145 // Set up initial properties for Panels in an accordion.
146 if (me.collapseFirst) {
147 comp.collapseFirst = me.collapseFirst;
149 if (me.hideCollapseTool) {
150 comp.hideCollapseTool = me.hideCollapseTool;
151 comp.titleCollapse = true;
153 else if (me.titleCollapse) {
154 comp.titleCollapse = me.titleCollapse;
157 delete comp.hideHeader;
158 comp.collapsible = true;
159 comp.title = comp.title || '&#160;';
160 comp.setBorder(false);
163 comp.width = targetSize.width;
168 // If there is an expanded item, all others must be rendered collapsed.
169 if (me.expandedItem !== undefined) {
170 comp.collapsed = true;
172 // Otherwise expand the first item with collapsed explicitly configured as false
173 else if (comp.collapsed === false) {
177 comp.collapsed = true;
181 comp.animCollapse = me.initialAnimate;
182 comp.autoHeight = true;
183 comp.autoScroll = false;
188 // If no collapsed:false Panels found, make the first one expanded.
189 if (ln && me.expandedItem === undefined) {
192 comp.collapsed = false;
198 // Render all Panels.
199 me.callParent(arguments);
201 // Postprocess rendered Panels.
202 ln = renderedPanels.length;
203 for (i = 0; i < ln; i++) {
204 comp = renderedPanels[i];
206 // Delete the dimension property so that our align: 'stretch' processing manages the width from here
209 comp.header.addCls(Ext.baseCSSPrefix + 'accordion-hd');
210 comp.body.addCls(Ext.baseCSSPrefix + 'accordion-body');
212 // If we are fitting, then intercept expand/collapse requests.
215 show: me.onComponentShow,
216 beforeexpand: me.onComponentExpand,
217 beforecollapse: me.onComponentCollapse,
224 onLayout: function() {
227 me.updatePanelClasses();
230 me.callParent(arguments);
232 var targetSize = me.getLayoutTargetSize(),
233 items = me.getVisibleItems(),
237 for (; i < len; i++) {
239 if (comp.collapsed) {
240 items[i].setWidth(targetSize.width);
242 items[i].setSize(null, null);
250 updatePanelClasses: function() {
251 var children = this.getLayoutItems(),
252 ln = children.length,
253 siblingCollapsed = true,
256 for (i = 0; i < ln; i++) {
258 if (!siblingCollapsed) {
259 child.header.addCls(Ext.baseCSSPrefix + 'accordion-hd-sibling-expanded');
262 child.header.removeCls(Ext.baseCSSPrefix + 'accordion-hd-sibling-expanded');
264 if (i + 1 == ln && child.collapsed) {
265 child.header.addCls(Ext.baseCSSPrefix + 'accordion-hd-last-collapsed');
268 child.header.removeCls(Ext.baseCSSPrefix + 'accordion-hd-last-collapsed');
270 siblingCollapsed = child.collapsed;
274 // When a Component expands, adjust the heights of the other Components to be just enough to accommodate
276 // The expanded Component receives the only flex value, and so gets all remaining space.
277 onComponentExpand: function(toExpand) {
279 it = me.owner.items.items,
284 for (; i < len; i++) {
286 if (comp === toExpand && comp.collapsed) {
287 me.setExpanded(comp);
288 } else if (!me.multi && (comp.rendered && comp.header.rendered && comp !== toExpand && !comp.collapsed)) {
289 me.setCollapsed(comp);
293 me.animate = me.initialAnimate;
299 onComponentCollapse: function(comp) {
301 toExpand = comp.next() || comp.prev(),
302 expanded = me.multi ? me.owner.query('>panel:not([collapsed])') : [];
304 // If we are allowing multi, and the "toCollapse" component is NOT the only expanded Component,
305 // then ask the box layout to collapse it to its header.
307 me.setCollapsed(comp);
309 // If the collapsing Panel is the only expanded one, expand the following Component.
310 // All this is handling fill: true, so there must be at least one expanded,
311 if (expanded.length === 1 && expanded[0] === comp) {
312 me.setExpanded(toExpand);
315 me.animate = me.initialAnimate;
319 // Not allowing multi: expand the next sibling if possible, prev sibling if we collapsed the last
321 me.onComponentExpand(toExpand);
326 onComponentShow: function(comp) {
327 // Showing a Component means that you want to see it, so expand it.
328 this.onComponentExpand(comp);
331 setCollapsed: function(comp) {
332 var otherDocks = comp.getDockedItems(),
334 len = otherDocks.length,
337 // Hide all docked items except the header
338 comp.hiddenDocked = [];
339 for (; i < len; i++) {
340 dockItem = otherDocks[i];
341 if ((dockItem !== comp.header) && !dockItem.hidden) {
342 dockItem.hidden = true;
343 comp.hiddenDocked.push(dockItem);
346 comp.addCls(comp.collapsedCls);
347 comp.header.addCls(comp.collapsedHeaderCls);
348 comp.height = comp.header.getHeight();
349 comp.el.setHeight(comp.height);
350 comp.collapsed = true;
352 comp.fireEvent('collapse', comp);
353 if (comp.collapseTool) {
354 comp.collapseTool.setType('expand-' + comp.getOppositeDirection(comp.collapseDirection));
358 setExpanded: function(comp) {
359 var otherDocks = comp.hiddenDocked,
360 len = otherDocks ? otherDocks.length : 0,
363 // Show temporarily hidden docked items
364 for (; i < len; i++) {
365 otherDocks[i].hidden = false;
368 // If it was an initial native collapse which hides the body
369 if (!comp.body.isVisible()) {
372 delete comp.collapsed;
374 delete comp.componentLayout.lastComponentSize;
375 comp.suspendLayout = false;
377 comp.removeCls(comp.collapsedCls);
378 comp.header.removeCls(comp.collapsedHeaderCls);
379 comp.fireEvent('expand', comp);
380 if (comp.collapseTool) {
381 comp.collapseTool.setType('collapse-' + comp.collapseDirection);
383 comp.setAutoScroll(comp.initialConfig.autoScroll);
385 });</pre></pre></body></html>