3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js"><div id="cls-Ext.layout.AccordionLayout"></div>/**
\r
9 * @class Ext.layout.AccordionLayout
\r
10 * @extends Ext.layout.FitLayout
\r
11 * <p>This is a layout that contains multiple panels in an expandable accordion style such that only
\r
12 * <b>one panel can be open at any given time</b>. Each panel has built-in support for expanding and collapsing.
\r
13 * <p>This class is intended to be extended or created via the <tt><b>{@link Ext.Container#layout layout}</b></tt>
\r
14 * configuration property. See <tt><b>{@link Ext.Container#layout}</b></tt> for additional details.</p>
\r
15 * <p>Example usage:</p>
\r
17 var accordion = new Ext.Panel({
\r
18 title: 'Accordion Layout',
\r
21 // applied to each contained panel
\r
22 bodyStyle: 'padding:15px'
\r
25 // layout-specific configs go here
\r
26 titleCollapse: false,
\r
32 html: '<p>Panel content!</p>'
\r
35 html: '<p>Panel content!</p>'
\r
38 html: '<p>Panel content!</p>'
\r
43 Ext.layout.AccordionLayout = Ext.extend(Ext.layout.FitLayout, {
\r
44 <div id="cfg-Ext.layout.AccordionLayout-fill"></div>/**
\r
45 * @cfg {Boolean} fill
\r
46 * True to adjust the active item's height to fill the available space in the container, false to use the
\r
47 * item's current height, or auto height if not explicitly set (defaults to true).
\r
50 <div id="cfg-Ext.layout.AccordionLayout-autoWidth"></div>/**
\r
51 * @cfg {Boolean} autoWidth
\r
52 * True to set each contained item's width to 'auto', false to use the item's current width (defaults to true).
\r
53 * Note that some components, in particular the {@link Ext.grid.GridPanel grid}, will not function properly within
\r
54 * layouts if they have auto width, so in such cases this config should be set to false.
\r
57 <div id="cfg-Ext.layout.AccordionLayout-titleCollapse"></div>/**
\r
58 * @cfg {Boolean} titleCollapse
\r
59 * True to allow expand/collapse of each contained panel by clicking anywhere on the title bar, false to allow
\r
60 * expand/collapse only when the toggle tool button is clicked (defaults to true). When set to false,
\r
61 * {@link #hideCollapseTool} should be false also.
\r
63 titleCollapse : true,
\r
64 <div id="cfg-Ext.layout.AccordionLayout-hideCollapseTool"></div>/**
\r
65 * @cfg {Boolean} hideCollapseTool
\r
66 * True to hide the contained panels' collapse/expand toggle buttons, false to display them (defaults to false).
\r
67 * When set to true, {@link #titleCollapse} should be true also.
\r
69 hideCollapseTool : false,
\r
70 <div id="cfg-Ext.layout.AccordionLayout-collapseFirst"></div>/**
\r
71 * @cfg {Boolean} collapseFirst
\r
72 * True to make sure the collapse/expand toggle button always renders first (to the left of) any other tools
\r
73 * in the contained panels' title bars, false to render it last (defaults to false).
\r
75 collapseFirst : false,
\r
76 <div id="cfg-Ext.layout.AccordionLayout-animate"></div>/**
\r
77 * @cfg {Boolean} animate
\r
78 * True to slide the contained panels open and closed during expand/collapse using animation, false to open and
\r
79 * close directly with no animation (defaults to false). Note: to defer to the specific config setting of each
\r
80 * contained panel for this property, set this to undefined at the layout level.
\r
83 <div id="cfg-Ext.layout.AccordionLayout-sequence"></div>/**
\r
84 * @cfg {Boolean} sequence
\r
85 * <b>Experimental</b>. If animate is set to true, this will result in each animation running in sequence.
\r
88 <div id="cfg-Ext.layout.AccordionLayout-activeOnTop"></div>/**
\r
89 * @cfg {Boolean} activeOnTop
\r
90 * True to swap the position of each panel as it is expanded so that it becomes the first item in the container,
\r
91 * false to keep the panels in the rendered order. <b>This is NOT compatible with "animate:true"</b> (defaults to false).
\r
93 activeOnTop : false,
\r
95 renderItem : function(c){
\r
96 if(this.animate === false){
\r
97 c.animCollapse = false;
\r
99 c.collapsible = true;
\r
100 if(this.autoWidth){
\r
101 c.autoWidth = true;
\r
103 if(this.titleCollapse){
\r
104 c.titleCollapse = true;
\r
106 if(this.hideCollapseTool){
\r
107 c.hideCollapseTool = true;
\r
109 if(this.collapseFirst !== undefined){
\r
110 c.collapseFirst = this.collapseFirst;
\r
112 if(!this.activeItem && !c.collapsed){
\r
113 this.activeItem = c;
\r
114 }else if(this.activeItem && this.activeItem != c){
\r
115 c.collapsed = true;
\r
117 Ext.layout.AccordionLayout.superclass.renderItem.apply(this, arguments);
\r
118 c.header.addClass('x-accordion-hd');
\r
119 c.on('beforeexpand', this.beforeExpand, this);
\r
123 beforeExpand : function(p, anim){
\r
124 var ai = this.activeItem;
\r
127 delete this.activeItem;
\r
128 if (!ai.collapsed){
\r
129 ai.collapse({callback:function(){
\r
130 p.expand(anim || true);
\r
135 ai.collapse(this.animate);
\r
138 this.activeItem = p;
\r
139 if(this.activeOnTop){
\r
140 p.el.dom.parentNode.insertBefore(p.el.dom, p.el.dom.parentNode.firstChild);
\r
146 setItemSize : function(item, size){
\r
147 if(this.fill && item){
\r
149 this.container.items.each(function(p){
\r
151 hh += p.header.getHeight();
\r
155 item.setSize(size);
\r
159 <div id="method-Ext.layout.AccordionLayout-setActiveItem"></div>/**
\r
160 * Sets the active (expanded) item in the layout.
\r
161 * @param {String/Number} item The string component id or numeric index of the item to activate
\r
163 setActiveItem : function(item){
\r
164 item = this.container.getComponent(item);
\r
165 if(this.activeItem != item){
\r
166 if(item.rendered && item.collapsed){
\r
169 this.activeItem = item;
\r
175 Ext.Container.LAYOUTS.accordion = Ext.layout.AccordionLayout;
\r
178 Ext.layout.Accordion = Ext.layout.AccordionLayout;</pre>
\r