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
97 renderItem : function(c){
\r
98 if(this.animate === false){
\r
99 c.animCollapse = false;
\r
101 c.collapsible = true;
\r
102 if(this.autoWidth){
\r
103 c.autoWidth = true;
\r
105 if(this.titleCollapse){
\r
106 c.titleCollapse = true;
\r
108 if(this.hideCollapseTool){
\r
109 c.hideCollapseTool = true;
\r
111 if(this.collapseFirst !== undefined){
\r
112 c.collapseFirst = this.collapseFirst;
\r
114 if(!this.activeItem && !c.collapsed){
\r
115 this.setActiveItem(c, true);
\r
116 }else if(this.activeItem && this.activeItem != c){
\r
117 c.collapsed = true;
\r
119 Ext.layout.AccordionLayout.superclass.renderItem.apply(this, arguments);
\r
120 c.header.addClass('x-accordion-hd');
\r
121 c.on('beforeexpand', this.beforeExpand, this);
\r
124 onRemove: function(c){
\r
125 Ext.layout.AccordionLayout.superclass.onRemove.call(this, c);
\r
127 c.header.removeClass('x-accordion-hd');
\r
129 c.un('beforeexpand', this.beforeExpand, this);
\r
133 beforeExpand : function(p, anim){
\r
134 var ai = this.activeItem;
\r
137 delete this.activeItem;
\r
138 if (!ai.collapsed){
\r
139 ai.collapse({callback:function(){
\r
140 p.expand(anim || true);
\r
145 ai.collapse(this.animate);
\r
149 if(this.activeOnTop){
\r
150 p.el.dom.parentNode.insertBefore(p.el.dom, p.el.dom.parentNode.firstChild);
\r
156 setItemSize : function(item, size){
\r
157 if(this.fill && item){
\r
159 this.container.items.each(function(p){
\r
161 hh += p.header.getHeight();
\r
165 item.setSize(size);
\r
169 <div id="method-Ext.layout.AccordionLayout-setActiveItem"></div>/**
\r
170 * Sets the active (expanded) item in the layout.
\r
171 * @param {String/Number} item The string component id or numeric index of the item to activate
\r
173 setActiveItem : function(item){
\r
174 this.setActive(item, true);
\r
178 setActive : function(item, expand){
\r
179 var ai = this.activeItem;
\r
180 item = this.container.getComponent(item);
\r
182 if(item.rendered && item.collapsed && expand){
\r
186 ai.fireEvent('deactivate', ai);
\r
188 this.activeItem = item;
\r
189 item.fireEvent('activate', item);
\r
194 Ext.Container.LAYOUTS.accordion = Ext.layout.AccordionLayout;
\r
197 Ext.layout.Accordion = Ext.layout.AccordionLayout;</pre>
\r