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