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
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
19 var accordion = new Ext.Panel({
\r
20 title: 'Accordion Layout',
\r
23 // applied to each contained panel
\r
24 bodyStyle: 'padding:15px'
\r
27 // layout-specific configs go here
\r
28 titleCollapse: false,
\r
34 html: '<p>Panel content!</p>'
\r
37 html: '<p>Panel content!</p>'
\r
40 html: '<p>Panel content!</p>'
\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
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
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
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
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
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
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
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
95 activeOnTop : false,
\r
99 renderItem : function(c){
\r
100 if(this.animate === false){
\r
101 c.animCollapse = false;
\r
103 c.collapsible = true;
\r
104 if(this.autoWidth){
\r
105 c.autoWidth = true;
\r
107 if(this.titleCollapse){
\r
108 c.titleCollapse = true;
\r
110 if(this.hideCollapseTool){
\r
111 c.hideCollapseTool = true;
\r
113 if(this.collapseFirst !== undefined){
\r
114 c.collapseFirst = this.collapseFirst;
\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
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
126 onRemove: function(c){
\r
127 Ext.layout.AccordionLayout.superclass.onRemove.call(this, c);
\r
129 c.header.removeClass('x-accordion-hd');
\r
131 c.un('beforeexpand', this.beforeExpand, this);
\r
135 beforeExpand : function(p, anim){
\r
136 var ai = this.activeItem;
\r
139 delete this.activeItem;
\r
140 if (!ai.collapsed){
\r
141 ai.collapse({callback:function(){
\r
142 p.expand(anim || true);
\r
147 ai.collapse(this.animate);
\r
151 if(this.activeOnTop){
\r
152 p.el.dom.parentNode.insertBefore(p.el.dom, p.el.dom.parentNode.firstChild);
\r
154 // Items have been hidden an possibly rearranged, we need to get the container size again.
\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
168 // Subtract the header heights from the container size
\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
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
180 setActiveItem : function(item){
\r
181 this.setActive(item, true);
\r
185 setActive : function(item, expand){
\r
186 var ai = this.activeItem;
\r
187 item = this.container.getComponent(item);
\r
189 if(item.rendered && item.collapsed && expand){
\r
193 ai.fireEvent('deactivate', ai);
\r
195 this.activeItem = item;
\r
196 item.fireEvent('activate', item);
\r
201 Ext.Container.LAYOUTS.accordion = Ext.layout.AccordionLayout;
\r
204 Ext.layout.Accordion = Ext.layout.AccordionLayout;</pre>
\r