3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.3.1
11 * Copyright(c) 2006-2010 Sencha Inc.
12 * licensing@sencha.com
13 * http://www.sencha.com/license
15 <div id="cls-Ext.layout.AccordionLayout"></div>/**
16 * @class Ext.layout.AccordionLayout
17 * @extends Ext.layout.FitLayout
18 * <p>This is a layout that manages multiple Panels in an expandable accordion style such that only
19 * <b>one Panel can be expanded at any given time</b>. Each Panel has built-in support for expanding and collapsing.</p>
20 * <p>Note: Only Ext.Panels <b>and all subclasses of Ext.Panel</b> may be used in an accordion layout Container.</p>
21 * <p>This class is intended to be extended or created via the <tt><b>{@link Ext.Container#layout layout}</b></tt>
22 * configuration property. See <tt><b>{@link Ext.Container#layout}</b></tt> for additional details.</p>
23 * <p>Example usage:</p>
25 var accordion = new Ext.Panel({
26 title: 'Accordion Layout',
29 // applied to each contained panel
30 bodyStyle: 'padding:15px'
33 // layout-specific configs go here
40 html: '<p>Panel content!</p>'
43 html: '<p>Panel content!</p>'
46 html: '<p>Panel content!</p>'
51 Ext.layout.AccordionLayout = Ext.extend(Ext.layout.FitLayout, {
52 <div id="cfg-Ext.layout.AccordionLayout-fill"></div>/**
54 * True to adjust the active item's height to fill the available space in the container, false to use the
55 * item's current height, or auto height if not explicitly set (defaults to true).
58 <div id="cfg-Ext.layout.AccordionLayout-autoWidth"></div>/**
59 * @cfg {Boolean} autoWidth
60 * True to set each contained item's width to 'auto', false to use the item's current width (defaults to true).
61 * Note that some components, in particular the {@link Ext.grid.GridPanel grid}, will not function properly within
62 * layouts if they have auto width, so in such cases this config should be set to false.
65 <div id="cfg-Ext.layout.AccordionLayout-titleCollapse"></div>/**
66 * @cfg {Boolean} titleCollapse
67 * True to allow expand/collapse of each contained panel by clicking anywhere on the title bar, false to allow
68 * expand/collapse only when the toggle tool button is clicked (defaults to true). When set to false,
69 * {@link #hideCollapseTool} should be false also.
72 <div id="cfg-Ext.layout.AccordionLayout-hideCollapseTool"></div>/**
73 * @cfg {Boolean} hideCollapseTool
74 * True to hide the contained panels' collapse/expand toggle buttons, false to display them (defaults to false).
75 * When set to true, {@link #titleCollapse} should be true also.
77 hideCollapseTool : false,
78 <div id="cfg-Ext.layout.AccordionLayout-collapseFirst"></div>/**
79 * @cfg {Boolean} collapseFirst
80 * True to make sure the collapse/expand toggle button always renders first (to the left of) any other tools
81 * in the contained panels' title bars, false to render it last (defaults to false).
83 collapseFirst : false,
84 <div id="cfg-Ext.layout.AccordionLayout-animate"></div>/**
85 * @cfg {Boolean} animate
86 * True to slide the contained panels open and closed during expand/collapse using animation, false to open and
87 * close directly with no animation (defaults to false). Note: to defer to the specific config setting of each
88 * contained panel for this property, set this to undefined at the layout level.
91 <div id="cfg-Ext.layout.AccordionLayout-sequence"></div>/**
92 * @cfg {Boolean} sequence
93 * <b>Experimental</b>. If animate is set to true, this will result in each animation running in sequence.
96 <div id="cfg-Ext.layout.AccordionLayout-activeOnTop"></div>/**
97 * @cfg {Boolean} activeOnTop
98 * True to swap the position of each panel as it is expanded so that it becomes the first item in the container,
99 * false to keep the panels in the rendered order. <b>This is NOT compatible with "animate:true"</b> (defaults to false).
105 renderItem : function(c){
106 if(this.animate === false){
107 c.animCollapse = false;
109 c.collapsible = true;
113 if(this.titleCollapse){
114 c.titleCollapse = true;
116 if(this.hideCollapseTool){
117 c.hideCollapseTool = true;
119 if(this.collapseFirst !== undefined){
120 c.collapseFirst = this.collapseFirst;
122 if(!this.activeItem && !c.collapsed){
123 this.setActiveItem(c, true);
124 }else if(this.activeItem && this.activeItem != c){
127 Ext.layout.AccordionLayout.superclass.renderItem.apply(this, arguments);
128 c.header.addClass('x-accordion-hd');
129 c.on('beforeexpand', this.beforeExpand, this);
132 onRemove: function(c){
133 Ext.layout.AccordionLayout.superclass.onRemove.call(this, c);
135 c.header.removeClass('x-accordion-hd');
137 c.un('beforeexpand', this.beforeExpand, this);
141 beforeExpand : function(p, anim){
142 var ai = this.activeItem;
145 delete this.activeItem;
147 ai.collapse({callback:function(){
148 p.expand(anim || true);
153 ai.collapse(this.animate);
157 if(this.activeOnTop){
158 p.el.dom.parentNode.insertBefore(p.el.dom, p.el.dom.parentNode.firstChild);
160 // Items have been hidden an possibly rearranged, we need to get the container size again.
165 setItemSize : function(item, size){
166 if(this.fill && item){
167 var hh = 0, i, ct = this.getRenderedItems(this.container), len = ct.length, p;
168 // Add up all the header heights
169 for (i = 0; i < len; i++) {
170 if((p = ct[i]) != item && !p.hidden){
171 hh += p.header.getHeight();
174 // Subtract the header heights from the container size
176 // Call setSize on the container to set the correct height. For Panels, deferedHeight
177 // will simply store this size for when the expansion is done.
182 <div id="method-Ext.layout.AccordionLayout-setActiveItem"></div>/**
183 * Sets the active (expanded) item in the layout.
184 * @param {String/Number} item The string component id or numeric index of the item to activate
186 setActiveItem : function(item){
187 this.setActive(item, true);
191 setActive : function(item, expand){
192 var ai = this.activeItem;
193 item = this.container.getComponent(item);
195 if(item.rendered && item.collapsed && expand){
199 ai.fireEvent('deactivate', ai);
201 this.activeItem = item;
202 item.fireEvent('activate', item);
207 Ext.Container.LAYOUTS.accordion = Ext.layout.AccordionLayout;
210 Ext.layout.Accordion = Ext.layout.AccordionLayout;</pre>