3 <title>The source code</title>
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 <body onload="prettyPrint();">
8 <pre class="prettyprint lang-js">/*!
10 * Copyright(c) 2006-2009 Ext JS, LLC
12 * http://www.extjs.com/license
14 <div id="cls-Ext.layout.AccordionLayout"></div>/**
\r
15 * @class Ext.layout.AccordionLayout
\r
16 * @extends Ext.layout.FitLayout
\r
17 * <p>This is a layout that manages multiple Panels in an expandable accordion style such that only
\r
18 * <b>one Panel can be expanded at any given time</b>. Each Panel has built-in support for expanding and collapsing.</p>
\r
19 * <p>Note: Only Ext.Panels <b>and all subclasses of Ext.Panel</b> may be used in an accordion layout Container.</p>
\r
20 * <p>This class is intended to be extended or created via the <tt><b>{@link Ext.Container#layout layout}</b></tt>
\r
21 * configuration property. See <tt><b>{@link Ext.Container#layout}</b></tt> for additional details.</p>
\r
22 * <p>Example usage:</p>
\r
24 var accordion = new Ext.Panel({
\r
25 title: 'Accordion Layout',
\r
28 // applied to each contained panel
\r
29 bodyStyle: 'padding:15px'
\r
32 // layout-specific configs go here
\r
33 titleCollapse: false,
\r
39 html: '<p>Panel content!</p>'
\r
42 html: '<p>Panel content!</p>'
\r
45 html: '<p>Panel content!</p>'
\r
50 Ext.layout.AccordionLayout = Ext.extend(Ext.layout.FitLayout, {
\r
51 <div id="cfg-Ext.layout.AccordionLayout-fill"></div>/**
\r
52 * @cfg {Boolean} fill
\r
53 * True to adjust the active item's height to fill the available space in the container, false to use the
\r
54 * item's current height, or auto height if not explicitly set (defaults to true).
\r
57 <div id="cfg-Ext.layout.AccordionLayout-autoWidth"></div>/**
\r
58 * @cfg {Boolean} autoWidth
\r
59 * True to set each contained item's width to 'auto', false to use the item's current width (defaults to true).
\r
60 * Note that some components, in particular the {@link Ext.grid.GridPanel grid}, will not function properly within
\r
61 * layouts if they have auto width, so in such cases this config should be set to false.
\r
64 <div id="cfg-Ext.layout.AccordionLayout-titleCollapse"></div>/**
\r
65 * @cfg {Boolean} titleCollapse
\r
66 * True to allow expand/collapse of each contained panel by clicking anywhere on the title bar, false to allow
\r
67 * expand/collapse only when the toggle tool button is clicked (defaults to true). When set to false,
\r
68 * {@link #hideCollapseTool} should be false also.
\r
70 titleCollapse : true,
\r
71 <div id="cfg-Ext.layout.AccordionLayout-hideCollapseTool"></div>/**
\r
72 * @cfg {Boolean} hideCollapseTool
\r
73 * True to hide the contained panels' collapse/expand toggle buttons, false to display them (defaults to false).
\r
74 * When set to true, {@link #titleCollapse} should be true also.
\r
76 hideCollapseTool : false,
\r
77 <div id="cfg-Ext.layout.AccordionLayout-collapseFirst"></div>/**
\r
78 * @cfg {Boolean} collapseFirst
\r
79 * True to make sure the collapse/expand toggle button always renders first (to the left of) any other tools
\r
80 * in the contained panels' title bars, false to render it last (defaults to false).
\r
82 collapseFirst : false,
\r
83 <div id="cfg-Ext.layout.AccordionLayout-animate"></div>/**
\r
84 * @cfg {Boolean} animate
\r
85 * True to slide the contained panels open and closed during expand/collapse using animation, false to open and
\r
86 * close directly with no animation (defaults to false). Note: to defer to the specific config setting of each
\r
87 * contained panel for this property, set this to undefined at the layout level.
\r
90 <div id="cfg-Ext.layout.AccordionLayout-sequence"></div>/**
\r
91 * @cfg {Boolean} sequence
\r
92 * <b>Experimental</b>. If animate is set to true, this will result in each animation running in sequence.
\r
95 <div id="cfg-Ext.layout.AccordionLayout-activeOnTop"></div>/**
\r
96 * @cfg {Boolean} activeOnTop
\r
97 * True to swap the position of each panel as it is expanded so that it becomes the first item in the container,
\r
98 * false to keep the panels in the rendered order. <b>This is NOT compatible with "animate:true"</b> (defaults to false).
\r
100 activeOnTop : false,
\r
102 renderItem : function(c){
\r
103 if(this.animate === false){
\r
104 c.animCollapse = false;
\r
106 c.collapsible = true;
\r
107 if(this.autoWidth){
\r
108 c.autoWidth = true;
\r
110 if(this.titleCollapse){
\r
111 c.titleCollapse = true;
\r
113 if(this.hideCollapseTool){
\r
114 c.hideCollapseTool = true;
\r
116 if(this.collapseFirst !== undefined){
\r
117 c.collapseFirst = this.collapseFirst;
\r
119 if(!this.activeItem && !c.collapsed){
\r
120 this.activeItem = c;
\r
121 }else if(this.activeItem && this.activeItem != c){
\r
122 c.collapsed = true;
\r
124 Ext.layout.AccordionLayout.superclass.renderItem.apply(this, arguments);
\r
125 c.header.addClass('x-accordion-hd');
\r
126 c.on('beforeexpand', this.beforeExpand, this);
\r
129 onRemove: function(c){
\r
130 Ext.layout.AccordionLayout.superclass.onRemove.call(this, c);
\r
132 c.header.removeClass('x-accordion-hd');
\r
134 c.un('beforeexpand', this.beforeExpand, this);
\r
138 beforeExpand : function(p, anim){
\r
139 var ai = this.activeItem;
\r
142 delete this.activeItem;
\r
143 if (!ai.collapsed){
\r
144 ai.collapse({callback:function(){
\r
145 p.expand(anim || true);
\r
150 ai.collapse(this.animate);
\r
153 this.activeItem = p;
\r
154 if(this.activeOnTop){
\r
155 p.el.dom.parentNode.insertBefore(p.el.dom, p.el.dom.parentNode.firstChild);
\r
161 setItemSize : function(item, size){
\r
162 if(this.fill && item){
\r
164 this.container.items.each(function(p){
\r
166 hh += p.header.getHeight();
\r
170 item.setSize(size);
\r
174 <div id="method-Ext.layout.AccordionLayout-setActiveItem"></div>/**
\r
175 * Sets the active (expanded) item in the layout.
\r
176 * @param {String/Number} item The string component id or numeric index of the item to activate
\r
178 setActiveItem : function(item){
\r
179 item = this.container.getComponent(item);
\r
180 if(this.activeItem != item){
\r
181 if(item.rendered && item.collapsed){
\r
184 this.activeItem = item;
\r
190 Ext.Container.LAYOUTS.accordion = Ext.layout.AccordionLayout;
\r
193 Ext.layout.Accordion = Ext.layout.AccordionLayout;</pre>