2 * @class Ext.panel.Panel
3 * @extends Ext.panel.AbstractPanel
4 * <p>Panel is a container that has specific functionality and structural components that make
5 * it the perfect building block for application-oriented user interfaces.</p>
6 * <p>Panels are, by virtue of their inheritance from {@link Ext.container.Container}, capable
7 * of being configured with a {@link Ext.container.Container#layout layout}, and containing child Components.</p>
8 * <p>When either specifying child {@link Ext.Component#items items} of a Panel, or dynamically {@link Ext.container.Container#add adding} Components
9 * to a Panel, remember to consider how you wish the Panel to arrange those child elements, and whether
10 * those child elements need to be sized using one of Ext's built-in <code><b>{@link Ext.container.Container#layout layout}</b></code> schemes. By
11 * default, Panels use the {@link Ext.layout.container.Auto Auto} scheme. This simply renders
12 * child components, appending them one after the other inside the Container, and <b>does not apply any sizing</b>
14 * {@img Ext.panel.Panel/panel.png Panel components}
15 * <p>A Panel may also contain {@link #bbar bottom} and {@link #tbar top} toolbars, along with separate
16 * {@link #header}, {@link #footer} and {@link #body} sections (see {@link #frame} for additional
18 * <p>Panel also provides built-in {@link #collapsible collapsible, expandable} and {@link #closable} behavior.
19 * Panels can be easily dropped into any {@link Ext.container.Container Container} or layout, and the
20 * layout and rendering pipeline is {@link Ext.container.Container#add completely managed by the framework}.</p>
21 * <p><b>Note:</b> By default, the <code>{@link #closable close}</code> header tool <i>destroys</i> the Panel resulting in removal of the Panel
22 * and the destruction of any descendant Components. This makes the Panel object, and all its descendants <b>unusable</b>. To enable the close
23 * tool to simply <i>hide</i> a Panel for later re-use, configure the Panel with <b><code>{@link #closeAction closeAction: 'hide'}</code></b>.</p>
24 * <p>Usually, Panels are used as constituents within an application, in which case, they would be used as child items of Containers,
25 * and would themselves use Ext.Components as child {@link #items}. However to illustrate simply rendering a Panel into the document,
26 * here's how to do it:<pre><code>
27 Ext.create('Ext.panel.Panel', {
30 html: '<p>World!</p>',
31 renderTo: document.body
34 * <p>A more realistic scenario is a Panel created to house input fields which will not be rendered, but used as a constituent part of a Container:<pre><code>
35 var filterPanel = Ext.create('Ext.panel.Panel', {
36 bodyPadding: 5, // Don't want content to crunch against the borders
40 fieldLabel: 'Start date'
43 fieldLabel: 'End date'
47 * <p>Note that the Panel above is not configured to render into the document, nor is it configured with a size or position. In a real world scenario,
48 * the Container into which the Panel is added will use a {@link #layout} to render, size and position its child Components.</p>
49 * <p>Panels will often use specific {@link #layout}s to provide an application with shape and structure by containing and arranging child
50 * Components: <pre><code>
51 var resultsPanel = Ext.create('Ext.panel.Panel', {
55 renderTo: document.body,
57 type: 'vbox', // Arrange child items vertically
58 align: 'stretch', // Each takes up full width
61 items: [{ // Results grid specified as a config object with an xtype of 'grid'
63 columns: [{header: 'Column One'}], // One header just for show. There's no data,
64 store: Ext.create('Ext.data.ArrayStore', {}), // A dummy empty data store
65 flex: 1 // Use 1/3 of Container's height (hint to Box layout)
67 xtype: 'splitter' // A splitter between the two child items
68 }, { // Details Panel specified as a config object (no xtype defaults to 'panel').
72 fieldLabel: 'Data item',
74 }], // An array of form fields
75 flex: 2 // Use 2/3 of Container's height (hint to Box layout)
79 * The example illustrates one possible method of displaying search results. The Panel contains a grid with the resulting data arranged
80 * in rows. Each selected row may be displayed in detail in the Panel below. The {@link Ext.layout.container.VBox vbox} layout is used
81 * to arrange the two vertically. It is configured to stretch child items horizontally to full width. Child items may either be configured
82 * with a numeric height, or with a <code>flex</code> value to distribute available space proportionately.</p>
83 * <p>This Panel itself may be a child item of, for exaple, a {@link Ext.tab.Panel} which will size its child items to fit within its
85 * <p>Using these techniques, as long as the <b>layout</b> is chosen and configured correctly, an application may have any level of
86 * nested containment, all dynamically sized according to configuration, the user's preference and available browser size.</p>
88 * @param {Object} config The config object
91 Ext.define('Ext.panel.Panel', {
92 extend: 'Ext.panel.AbstractPanel',
99 'Ext.layout.component.Dock'
101 alias: 'widget.panel',
102 alternateClassName: 'Ext.Panel',
105 * @cfg {String} collapsedCls
106 * A CSS class to add to the panel's element after it has been collapsed (defaults to
107 * <code>'collapsed'</code>).
109 collapsedCls: 'collapsed',
112 * @cfg {Boolean} animCollapse
113 * <code>true</code> to animate the transition when the panel is collapsed, <code>false</code> to skip the
114 * animation (defaults to <code>true</code> if the {@link Ext.fx.Anim} class is available, otherwise <code>false</code>).
115 * May also be specified as the animation duration in milliseconds.
117 animCollapse: Ext.enableFx,
120 * @cfg {Number} minButtonWidth
121 * Minimum width of all footer toolbar buttons in pixels (defaults to <tt>75</tt>). If set, this will
122 * be used as the default value for the <tt>{@link Ext.button.Button#minWidth}</tt> config of
123 * each Button added to the <b>footer toolbar</b> via the {@link #fbar} or {@link #buttons} configurations.
124 * It will be ignored for buttons that have a minWidth configured some other way, e.g. in their own config
125 * object or via the {@link Ext.container.Container#config-defaults defaults} of their parent container.
130 * @cfg {Boolean} collapsed
131 * <code>true</code> to render the panel collapsed, <code>false</code> to render it expanded (defaults to
132 * <code>false</code>).
137 * @cfg {Boolean} collapseFirst
138 * <code>true</code> to make sure the collapse/expand toggle button always renders first (to the left of)
139 * any other tools in the panel's title bar, <code>false</code> to render it last (defaults to <code>true</code>).
144 * @cfg {Boolean} hideCollapseTool
145 * <code>true</code> to hide the expand/collapse toggle button when <code>{@link #collapsible} == true</code>,
146 * <code>false</code> to display it (defaults to <code>false</code>).
148 hideCollapseTool: false,
151 * @cfg {Boolean} titleCollapse
152 * <code>true</code> to allow expanding and collapsing the panel (when <code>{@link #collapsible} = true</code>)
153 * by clicking anywhere in the header bar, <code>false</code>) to allow it only by clicking to tool button
154 * (defaults to <code>false</code>)).
156 titleCollapse: false,
159 * @cfg {String} collapseMode
160 * <p><b>Important: this config is only effective for {@link #collapsible} Panels which are direct child items of a {@link Ext.layout.container.Border border layout}.</b></p>
161 * <p>When <i>not</i> a direct child item of a {@link Ext.layout.container.Border border layout}, then the Panel's header remains visible, and the body is collapsed to zero dimensions.
162 * If the Panel has no header, then a new header (orientated correctly depending on the {@link #collapseDirection}) will be inserted to show a the title and a re-expand tool.</p>
163 * <p>When a child item of a {@link Ext.layout.container.Border border layout}, this config has two options:
164 * <div class="mdetail-params"><ul>
165 * <li><b><code>undefined/omitted</code></b><div class="sub-desc">When collapsed, a placeholder {@link Ext.panel.Header Header} is injected into the layout to represent the Panel
166 * and to provide a UI with a Tool to allow the user to re-expand the Panel.</div></li>
167 * <li><b><code>header</code></b> : <div class="sub-desc">The Panel collapses to leave its header visible as when not inside a {@link Ext.layout.container.Border border layout}.</div></li>
172 * @cfg {Mixed} placeholder
173 * <p><b>Important: This config is only effective for {@link #collapsible} Panels which are direct child items of a {@link Ext.layout.container.Border border layout}
174 * when not using the <code>'header'</code> {@link #collapseMode}.</b></p>
175 * <p><b>Optional.</b> A Component (or config object for a Component) to show in place of this Panel when this Panel is collapsed by a
176 * {@link Ext.layout.container.Border border layout}. Defaults to a generated {@link Ext.panel.Header Header}
177 * containing a {@link Ext.panel.Tool Tool} to re-expand the Panel.</p>
181 * @cfg {Boolean} floatable
182 * <p><b>Important: This config is only effective for {@link #collapsible} Panels which are direct child items of a {@link Ext.layout.container.Border border layout}.</b></p>
183 * <tt>true</tt> to allow clicking a collapsed Panel's {@link #placeholder} to display the Panel floated
184 * above the layout, <tt>false</tt> to force the user to fully expand a collapsed region by
185 * clicking the expand button to see it again (defaults to <tt>true</tt>).
190 * @cfg {Mixed} overlapHeader
191 * True to overlap the header in a panel over the framing of the panel itself. This is needed when frame:true (and is done automatically for you). Otherwise it is undefined.
192 * If you manually add rounded corners to a panel header which does not have frame:true, this will need to be set to true.
196 * @cfg {Boolean} collapsible
197 * <p>True to make the panel collapsible and have an expand/collapse toggle Tool added into
198 * the header tool button area. False to keep the panel sized either statically, or by an owning layout manager, with no toggle Tool (defaults to false).</p>
199 * See {@link #collapseMode} and {@link #collapseDirection}
204 * @cfg {Boolean} collapseDirection
205 * <p>The direction to collapse the Panel when the toggle button is clicked.</p>
206 * <p>Defaults to the {@link #headerPosition}</p>
207 * <p><b>Important: This config is <u>ignored</u> for {@link #collapsible} Panels which are direct child items of a {@link Ext.layout.container.Border border layout}.</b></p>
208 * <p>Specify as <code>'top'</code>, <code>'bottom'</code>, <code>'left'</code> or <code>'right'</code>.</p>
212 * @cfg {Boolean} closable
213 * <p>True to display the 'close' tool button and allow the user to close the window, false to
214 * hide the button and disallow closing the window (defaults to <code>false</code>).</p>
215 * <p>By default, when close is requested by clicking the close button in the header, the {@link #close}
216 * method will be called. This will <i>{@link Ext.Component#destroy destroy}</i> the Panel and its content
217 * meaning that it may not be reused.</p>
218 * <p>To make closing a Panel <i>hide</i> the Panel so that it may be reused, set
219 * {@link #closeAction} to 'hide'.</p>
224 * @cfg {String} closeAction
225 * <p>The action to take when the close header tool is clicked:
226 * <div class="mdetail-params"><ul>
227 * <li><b><code>'{@link #destroy}'</code></b> : <b>Default</b><div class="sub-desc">
228 * {@link #destroy remove} the window from the DOM and {@link Ext.Component#destroy destroy}
229 * it and all descendant Components. The window will <b>not</b> be available to be
230 * redisplayed via the {@link #show} method.
232 * <li><b><code>'{@link #hide}'</code></b> : <div class="sub-desc">
233 * {@link #hide} the window by setting visibility to hidden and applying negative offsets.
234 * The window will be available to be redisplayed via the {@link #show} method.
237 * <p><b>Note:</b> This behavior has changed! setting *does* affect the {@link #close} method
238 * which will invoke the approriate closeAction.
240 closeAction: 'destroy',
243 * @cfg {Object/Array} dockedItems
244 * A component or series of components to be added as docked items to this panel.
245 * The docked items can be docked to either the top, right, left or bottom of a panel.
246 * This is typically used for things like toolbars or tab bars:
248 var panel = new Ext.panel.Panel({
253 text: 'Docked to the top'
260 * @cfg {Boolean} preventHeader Prevent a Header from being created and shown. Defaults to false.
262 preventHeader: false,
265 * @cfg {String} headerPosition Specify as <code>'top'</code>, <code>'bottom'</code>, <code>'left'</code> or <code>'right'</code>. Defaults to <code>'top'</code>.
267 headerPosition: 'top',
270 * @cfg {Boolean} frame
271 * True to apply a frame to the panel.
276 * @cfg {Boolean} frameHeader
277 * True to apply a frame to the panel panels header (if 'frame' is true).
283 * An array of {@link Ext.panel.Tool} configs/instances to be added to the header tool area. The tools are stored as child
284 * components of the header container. They can be accessed using {@link #down} and {#query}, as well as the other
285 * component methods. The toggle tool is automatically created if {@link #collapsible} is set to true.
286 * <p>Note that, apart from the toggle tool which is provided when a panel is collapsible, these
287 * tools only provide the visual button. Any required functionality must be provided by adding
288 * handlers that implement the necessary behavior.</p>
289 * <p>Example usage:</p>
293 qtip: 'Refresh form Data',
295 handler: function(event, toolEl, panel){
302 handler: function(event, toolEl, panel){
310 initComponent: function() {
317 * Fires after the Panel title has been set or changed.
318 * @param {Ext.panel.Panel} p the Panel which has been resized.
319 * @param {String} newTitle The new title.
320 * @param {String} oldTitle The previous panel title.
325 * Fires after the Panel iconCls has been set or changed.
326 * @param {Ext.panel.Panel} p the Panel which has been resized.
327 * @param {String} newIconCls The new iconCls.
328 * @param {String} oldIconCls The previous panel iconCls.
338 me.setUI('default-framed');
343 me.collapseDirection = me.collapseDirection || me.headerPosition || Ext.Component.DIRECTION_TOP;
345 // Backwards compatibility
349 setBorder: function(border) {
351 // method = (border === false || border === 0) ? 'addClsWithUI' : 'removeClsWithUI';
353 // me.callParent(arguments);
355 // if (me.collapsed) {
356 // me[method](me.collapsedCls + '-noborder');
360 // me.header.setBorder(border);
361 // if (me.collapsed) {
362 // me.header[method](me.collapsedCls + '-noborder');
366 this.callParent(arguments);
369 beforeDestroy: function() {
377 initAria: function() {
379 this.initHeaderAria();
382 initHeaderAria: function() {
387 el.dom.setAttribute('aria-labelledby', header.titleCmp.id);
391 getHeader: function() {
396 * Set a title for the panel's header. See {@link Ext.panel.Header#title}.
397 * @param {String} newTitle
399 setTitle: function(newTitle) {
401 oldTitle = this.title;
405 me.header.setTitle(newTitle);
411 me.reExpander.setTitle(newTitle);
413 me.fireEvent('titlechange', me, newTitle, oldTitle);
417 * Set the iconCls for the panel's header. See {@link Ext.panel.Header#iconCls}.
418 * @param {String} newIconCls
420 setIconCls: function(newIconCls) {
422 oldIconCls = me.iconCls;
424 me.iconCls = newIconCls;
425 var header = me.header;
427 header.setIconCls(newIconCls);
429 me.fireEvent('iconchange', me, newIconCls, oldIconCls);
432 bridgeToolbars: function() {
436 minButtonWidth = me.minButtonWidth;
438 function initToolbar (toolbar, pos) {
439 if (Ext.isArray(toolbar)) {
445 else if (!toolbar.xtype) {
446 toolbar.xtype = 'toolbar';
449 if (pos == 'left' || pos == 'right') {
450 toolbar.vertical = true;
455 // Backwards compatibility
458 * @cfg {Object/Array} tbar
460 Convenience method. Short for 'Top Bar'.
463 { xtype: 'button', text: 'Button 1' }
472 { xtype: 'button', text: 'Button 1' }
479 me.addDocked(initToolbar(me.tbar, 'top'));
484 * @cfg {Object/Array} bbar
486 Convenience method. Short for 'Bottom Bar'.
489 { xtype: 'button', text: 'Button 1' }
498 { xtype: 'button', text: 'Button 1' }
505 me.addDocked(initToolbar(me.bbar, 'bottom'));
510 * @cfg {Object/Array} buttons
512 Convenience method used for adding buttons docked to the bottom right of the panel. This is a
513 synonym for the {@link #fbar} config.
524 defaults: {minWidth: {@link #minButtonWidth}},
526 { xtype: 'component', flex: 1 },
527 { xtype: 'button', text: 'Button 1' }
531 The {@link #minButtonWidth} is used as the default {@link Ext.button.Button#minWidth minWidth} for
532 each of the buttons in the buttons toolbar.
537 me.fbar = me.buttons;
542 * @cfg {Object/Array} fbar
544 Convenience method used for adding items to the bottom right of the panel. Short for Footer Bar.
547 { type: 'button', text: 'Button 1' }
555 defaults: {minWidth: {@link #minButtonWidth}},
557 { xtype: 'component', flex: 1 },
558 { xtype: 'button', text: 'Button 1' }
562 The {@link #minButtonWidth} is used as the default {@link Ext.button.Button#minWidth minWidth} for
563 each of the buttons in the fbar.
568 fbar = initToolbar(me.fbar, 'bottom');
571 // Apply the minButtonWidth config to buttons in the toolbar
572 if (minButtonWidth) {
573 fbarDefaults = fbar.defaults;
574 fbar.defaults = function(config) {
575 var defaults = fbarDefaults || {};
576 if ((!config.xtype || config.xtype === 'button' || (config.isComponent && config.isXType('button'))) &&
577 !('minWidth' in defaults)) {
578 defaults = Ext.apply({minWidth: minButtonWidth}, defaults);
584 fbar = me.addDocked(fbar)[0];
594 * @cfg {Object/Array} lbar
596 * Convenience method. Short for 'Left Bar' (left-docked, vertical toolbar).
599 * { xtype: 'button', text: 'Button 1' }
608 * { xtype: 'button', text: 'Button 1' }
615 me.addDocked(initToolbar(me.lbar, 'left'));
620 * @cfg {Object/Array} rbar
622 * Convenience method. Short for 'Right Bar' (right-docked, vertical toolbar).
625 * { xtype: 'button', text: 'Button 1' }
634 * { xtype: 'button', text: 'Button 1' }
641 me.addDocked(initToolbar(me.rbar, 'right'));
648 * Tools are a Panel-specific capabilty.
649 * Panel uses initTools. Subclasses may contribute tools by implementing addTools.
651 initTools: function() {
654 me.tools = me.tools || [];
656 // Add a collapse tool unless configured to not show a collapse tool
657 // or to not even show a header.
658 if (me.collapsible && !(me.hideCollapseTool || me.header === false)) {
659 me.collapseDirection = me.collapseDirection || me.headerPosition || 'top';
660 me.collapseTool = me.expandTool = me.createComponent({
662 type: 'collapse-' + me.collapseDirection,
663 expandType: me.getOppositeDirection(me.collapseDirection),
664 handler: me.toggleCollapse,
668 // Prepend collapse tool is configured to do so.
669 if (me.collapseFirst) {
670 me.tools.unshift(me.collapseTool);
674 // Add subclass-specific tools.
677 // Make Panel closable.
679 me.addClsWithUI('closable');
682 handler: Ext.Function.bind(me.close, this, [])
686 // Append collapse tool if needed.
687 if (me.collapseTool && !me.collapseFirst) {
688 me.tools.push(me.collapseTool);
694 * Template method to be implemented in subclasses to add their tools after the collapsible tool.
696 addTools: Ext.emptyFn,
699 * <p>Closes the Panel. By default, this method, removes it from the DOM, {@link Ext.Component#destroy destroy}s
700 * the Panel object and all its descendant Components. The {@link #beforeclose beforeclose}
701 * event is fired before the close happens and will cancel the close action if it returns false.<p>
702 * <p><b>Note:</b> This method is not affected by the {@link #closeAction} setting which
703 * only affects the action triggered when clicking the {@link #closable 'close' tool in the header}.
704 * To hide the Panel without destroying it, call {@link #hide}.</p>
707 if (this.fireEvent('beforeclose', this) !== false) {
713 doClose: function() {
714 this.fireEvent('close', this);
715 this[this.closeAction]();
718 onRender: function(ct, position) {
722 // Add class-specific header tools.
723 // Panel adds collapsible and closable.
726 // Dock the header/title
729 // If initially collapsed, collapsed flag must indicate true current state at this point.
730 // Do collapse after the first time the Panel's structure has been laid out.
732 me.collapsed = false;
733 topContainer = me.findLayoutController();
734 if (!me.hidden && topContainer) {
736 afterlayout: function() {
737 me.collapse(null, false, true);
742 me.afterComponentLayout = function() {
743 delete me.afterComponentLayout;
744 Ext.getClass(me).prototype.afterComponentLayout.apply(me, arguments);
745 me.collapse(null, false, true);
750 // Call to super after adding the header, to prevent an unnecessary re-layout
751 me.callParent(arguments);
755 * Create, hide, or show the header component as appropriate based on the current config.
757 * @param {Boolean} force True to force the the header to be created
759 updateHeader: function(force) {
765 if (!me.preventHeader && (force || title || (tools && tools.length))) {
767 header = me.header = Ext.create('Ext.panel.Header', {
769 orientation : (me.headerPosition == 'left' || me.headerPosition == 'right') ? 'vertical' : 'horizontal',
770 dock : me.headerPosition || 'top',
771 textCls : me.headerTextCls,
772 iconCls : me.iconCls,
773 baseCls : me.baseCls + '-header',
776 indicateDrag: me.draggable,
778 frame : me.frame && me.frameHeader,
779 ignoreParentFrame : me.frame || me.overlapHeader,
780 ignoreBorderManagement: me.frame || me.ignoreHeaderBorderManagement,
781 listeners : me.collapsible && me.titleCollapse ? {
782 click: me.toggleCollapse,
786 me.addDocked(header, 0);
788 // Reference the Header's tool array.
789 // Header injects named references.
790 me.tools = header.tools;
800 setUI: function(ui) {
803 me.callParent(arguments);
811 getContentTarget: function() {
815 getTargetEl: function() {
816 return this.body || this.frameBody || this.el;
819 addTool: function(tool) {
820 this.tools.push(tool);
821 var header = this.header;
823 header.addTool(tool);
828 getOppositeDirection: function(d) {
829 var c = Ext.Component;
831 case c.DIRECTION_TOP:
832 return c.DIRECTION_BOTTOM;
833 case c.DIRECTION_RIGHT:
834 return c.DIRECTION_LEFT;
835 case c.DIRECTION_BOTTOM:
836 return c.DIRECTION_TOP;
837 case c.DIRECTION_LEFT:
838 return c.DIRECTION_RIGHT;
843 * Collapses the panel body so that the body becomes hidden. Docked Components parallel to the
844 * border towards which the collapse takes place will remain visible. Fires the {@link #beforecollapse} event which will
845 * cancel the collapse action if it returns false.
846 * @param {Number} direction. The direction to collapse towards. Must be one of<ul>
847 * <li>Ext.Component.DIRECTION_TOP</li>
848 * <li>Ext.Component.DIRECTION_RIGHT</li>
849 * <li>Ext.Component.DIRECTION_BOTTOM</li>
850 * <li>Ext.Component.DIRECTION_LEFT</li></ul>
851 * @param {Boolean} animate True to animate the transition, else false (defaults to the value of the
852 * {@link #animCollapse} panel config)
853 * @return {Ext.panel.Panel} this
855 collapse: function(direction, animate, /* private - passed if called at render time */ internal) {
858 height = me.getHeight(),
859 width = me.getWidth(),
862 dockedItems = me.dockedItems.items,
863 dockedItemCount = dockedItems.length,
877 afteranimate: me.afterCollapse,
880 duration: Ext.Number.from(animate, Ext.fx.Anim.prototype.duration)
883 reExpanderOrientation,
890 direction = me.collapseDirection;
893 // If internal (Called because of initial collapsed state), then no animation, and no events.
896 } else if (me.collapsed || me.fireEvent('beforecollapse', me, direction, animate) === false) {
900 reExpanderDock = direction;
901 me.expandDirection = me.getOppositeDirection(direction);
903 // Track docked items which we hide during collapsed state
904 me.hiddenDocked = [];
907 case c.DIRECTION_TOP:
908 case c.DIRECTION_BOTTOM:
909 me.expandedSize = me.getHeight();
910 reExpanderOrientation = 'horizontal';
911 collapseDimension = 'height';
912 getDimension = 'getHeight';
913 setDimension = 'setHeight';
915 // Collect the height of the visible header.
916 // Hide all docked items except the header.
917 // Hide *ALL* docked items if we're going to end up hiding the whole Panel anyway
918 for (; i < dockedItemCount; i++) {
919 comp = dockedItems[i];
920 if (comp.isVisible()) {
921 if (comp.isHeader && (!comp.dock || comp.dock == 'top' || comp.dock == 'bottom')) {
924 me.hiddenDocked.push(comp);
929 if (direction == Ext.Component.DIRECTION_BOTTOM) {
930 pos = me.getPosition()[1] - Ext.fly(me.el.dom.offsetParent).getRegion().top;
935 case c.DIRECTION_LEFT:
936 case c.DIRECTION_RIGHT:
937 me.expandedSize = me.getWidth();
938 reExpanderOrientation = 'vertical';
939 collapseDimension = 'width';
940 getDimension = 'getWidth';
941 setDimension = 'setWidth';
943 // Collect the height of the visible header.
944 // Hide all docked items except the header.
945 // Hide *ALL* docked items if we're going to end up hiding the whole Panel anyway
946 for (; i < dockedItemCount; i++) {
947 comp = dockedItems[i];
948 if (comp.isVisible()) {
949 if (comp.isHeader && (comp.dock == 'left' || comp.dock == 'right')) {
952 me.hiddenDocked.push(comp);
957 if (direction == Ext.Component.DIRECTION_RIGHT) {
958 pos = me.getPosition()[0] - Ext.fly(me.el.dom.offsetParent).getRegion().left;
959 anim.from.left = pos;
964 throw('Panel collapse must be passed a valid Component collapse direction');
967 // No scrollbars when we shrink this Panel
968 // And no laying out of any children... we're effectively *hiding* the body
969 me.setAutoScroll(false);
970 me.suspendLayout = true;
971 me.body.setVisibilityMode(Ext.core.Element.DISPLAY);
973 // Disable toggle tool during animated collapse
974 if (animate && me.collapseTool) {
975 me.collapseTool.disable();
978 // Add the collapsed class now, so that collapsed CSS rules are applied before measurements are taken.
979 me.addClsWithUI(me.collapsedCls);
980 // if (me.border === false) {
981 // me.addClsWithUI(me.collapsedCls + '-noborder');
984 // We found a header: Measure it to find the collapse-to size.
986 //we must add the collapsed cls to the header and then remove to get the proper height
987 reExpander.addClsWithUI(me.collapsedCls);
988 reExpander.addClsWithUI(me.collapsedCls + '-' + reExpander.dock);
989 if (me.border && (!me.frame || (me.frame && Ext.supports.CSS3BorderRadius))) {
990 reExpander.addClsWithUI(me.collapsedCls + '-border-' + reExpander.dock);
993 frameInfo = reExpander.getFrameInfo();
996 newSize = reExpander[getDimension]() + (frameInfo ? frameInfo[direction] : 0);
999 reExpander.removeClsWithUI(me.collapsedCls);
1000 reExpander.removeClsWithUI(me.collapsedCls + '-' + reExpander.dock);
1001 if (me.border && (!me.frame || (me.frame && Ext.supports.CSS3BorderRadius))) {
1002 reExpander.removeClsWithUI(me.collapsedCls + '-border-' + reExpander.dock);
1005 // No header: Render and insert a temporary one, and then measure it.
1008 hideMode: 'offsets',
1011 orientation: reExpanderOrientation,
1012 dock: reExpanderDock,
1013 textCls: me.headerTextCls,
1014 iconCls: me.iconCls,
1015 baseCls: me.baseCls + '-header',
1017 frame: me.frame && me.frameHeader,
1018 ignoreParentFrame: me.frame || me.overlapHeader,
1019 indicateDrag: me.draggable,
1020 cls: me.baseCls + '-collapsed-placeholder ' + ' ' + Ext.baseCSSPrefix + 'docked ' + me.baseCls + '-' + me.ui + '-collapsed',
1023 if (!me.hideCollapseTool) {
1024 reExpander[(reExpander.orientation == 'horizontal') ? 'tools' : 'items'] = [{
1026 type: 'expand-' + me.expandDirection,
1027 handler: me.toggleCollapse,
1032 // Capture the size of the re-expander.
1033 // For vertical headers in IE6 and IE7, this will be sized by a CSS rule in _panel.scss
1034 reExpander = me.reExpander = Ext.create('Ext.panel.Header', reExpander);
1035 newSize = reExpander[getDimension]() + ((reExpander.frame) ? reExpander.frameSize[direction] : 0);
1038 // Insert the new docked item
1039 me.insertDocked(0, reExpander);
1042 me.reExpander = reExpander;
1043 me.reExpander.addClsWithUI(me.collapsedCls);
1044 me.reExpander.addClsWithUI(me.collapsedCls + '-' + reExpander.dock);
1045 if (me.border && (!me.frame || (me.frame && Ext.supports.CSS3BorderRadius))) {
1046 me.reExpander.addClsWithUI(me.collapsedCls + '-border-' + me.reExpander.dock);
1049 // If collapsing right or down, we'll be also animating the left or top.
1050 if (direction == Ext.Component.DIRECTION_RIGHT) {
1051 anim.to.left = pos + (width - newSize);
1052 } else if (direction == Ext.Component.DIRECTION_BOTTOM) {
1053 anim.to.top = pos + (height - newSize);
1056 // Animate to the new size
1057 anim.to[collapseDimension] = newSize;
1059 // Remove any flex config before we attempt to collapse.
1060 me.savedFlex = me.flex;
1061 me.savedMinWidth = me.minWidth;
1062 me.savedMinHeight = me.minHeight;
1070 // EXTJSIV-1937 (would like to use setCalculateSize)
1071 // save width/height here, expand puts them back
1072 me.uncollapsedSize = { width: me.width, height: me.height };
1074 me.setSize(anim.to.width, anim.to.height);
1075 if (Ext.isDefined(anim.to.left) || Ext.isDefined(anim.to.top)) {
1076 me.setPosition(anim.to.left, anim.to.top);
1078 me.afterCollapse(false, internal);
1083 afterCollapse: function(animated, internal) {
1086 l = me.hiddenDocked.length;
1088 me.minWidth = me.savedMinWidth;
1089 me.minHeight = me.savedMinHeight;
1092 for (; i < l; i++) {
1093 me.hiddenDocked[i].hide();
1095 if (me.reExpander) {
1096 me.reExpander.updateFrame();
1097 me.reExpander.show();
1099 me.collapsed = true;
1102 me.doComponentLayout();
1106 me.resizer.disable();
1109 // If me Panel was configured with a collapse tool in its header, flip it's type
1110 if (me.collapseTool) {
1111 me.collapseTool.setType('expand-' + me.expandDirection);
1114 me.fireEvent('collapse', me);
1117 // Re-enable the toggle tool after an animated collapse
1118 if (animated && me.collapseTool) {
1119 me.collapseTool.enable();
1124 * Expands the panel body so that it becomes visible. Fires the {@link #beforeexpand} event which will
1125 * cancel the expand action if it returns false.
1126 * @param {Boolean} animate True to animate the transition, else false (defaults to the value of the
1127 * {@link #animCollapse} panel config)
1128 * @return {Ext.panel.Panel} this
1130 expand: function(animate) {
1131 if (!this.collapsed || this.fireEvent('beforeexpand', this, animate) === false) {
1135 // EXTJSIV-1937 (would like to use setCalculateSize)
1136 if (this.uncollapsedSize) {
1137 Ext.Object.each(this.uncollapsedSize, function (name, value) {
1138 if (Ext.isDefined(value)) {
1144 delete this.uncollapsedSize;
1149 l = me.hiddenDocked.length,
1150 direction = me.expandDirection,
1151 height = me.getHeight(),
1152 width = me.getWidth(),
1153 pos, anim, satisfyJSLint;
1155 // Disable toggle tool during animated expand
1156 if (animate && me.collapseTool) {
1157 me.collapseTool.disable();
1160 // Show any docked items that we hid on collapse
1161 // And hide the injected reExpander Header
1162 for (; i < l; i++) {
1163 me.hiddenDocked[i].hidden = false;
1164 me.hiddenDocked[i].el.show();
1166 if (me.reExpander) {
1167 if (me.reExpander.temporary) {
1168 me.reExpander.hide();
1170 me.reExpander.removeClsWithUI(me.collapsedCls);
1171 me.reExpander.removeClsWithUI(me.collapsedCls + '-' + me.reExpander.dock);
1172 if (me.border && (!me.frame || (me.frame && Ext.supports.CSS3BorderRadius))) {
1173 me.reExpander.removeClsWithUI(me.collapsedCls + '-border-' + me.reExpander.dock);
1175 me.reExpander.updateFrame();
1179 // If me Panel was configured with a collapse tool in its header, flip it's type
1180 if (me.collapseTool) {
1181 me.collapseTool.setType('collapse-' + me.collapseDirection);
1184 // Unset the flag before the potential call to calculateChildBox to calculate our newly flexed size
1185 me.collapsed = false;
1187 // Collapsed means body element was hidden
1190 // Remove any collapsed styling before any animation begins
1191 me.removeClsWithUI(me.collapsedCls);
1192 // if (me.border === false) {
1193 // me.removeClsWithUI(me.collapsedCls + '-noborder');
1204 afteranimate: me.afterExpand,
1209 if ((direction == Ext.Component.DIRECTION_TOP) || (direction == Ext.Component.DIRECTION_BOTTOM)) {
1211 // If autoHeight, measure the height now we have shown the body element.
1212 if (me.autoHeight) {
1213 me.setCalculatedSize(me.width, null);
1214 anim.to.height = me.getHeight();
1216 // Must size back down to collapsed for the animation.
1217 me.setCalculatedSize(me.width, anim.from.height);
1219 // If we were flexed, then we can't just restore to the saved size.
1220 // We must restore to the currently correct, flexed size, so we much ask the Box layout what that is.
1221 else if (me.savedFlex) {
1222 me.flex = me.savedFlex;
1223 anim.to.height = me.ownerCt.layout.calculateChildBox(me).height;
1226 // Else, restore to saved height
1228 anim.to.height = me.expandedSize;
1231 // top needs animating upwards
1232 if (direction == Ext.Component.DIRECTION_TOP) {
1233 pos = me.getPosition()[1] - Ext.fly(me.el.dom.offsetParent).getRegion().top;
1234 anim.from.top = pos;
1235 anim.to.top = pos - (anim.to.height - height);
1237 } else if ((direction == Ext.Component.DIRECTION_LEFT) || (direction == Ext.Component.DIRECTION_RIGHT)) {
1239 // If autoWidth, measure the width now we have shown the body element.
1241 me.setCalculatedSize(null, me.height);
1242 anim.to.width = me.getWidth();
1244 // Must size back down to collapsed for the animation.
1245 me.setCalculatedSize(anim.from.width, me.height);
1247 // If we were flexed, then we can't just restore to the saved size.
1248 // We must restore to the currently correct, flexed size, so we much ask the Box layout what that is.
1249 else if (me.savedFlex) {
1250 me.flex = me.savedFlex;
1251 anim.to.width = me.ownerCt.layout.calculateChildBox(me).width;
1254 // Else, restore to saved width
1256 anim.to.width = me.expandedSize;
1259 // left needs animating leftwards
1260 if (direction == Ext.Component.DIRECTION_LEFT) {
1261 pos = me.getPosition()[0] - Ext.fly(me.el.dom.offsetParent).getRegion().left;
1262 anim.from.left = pos;
1263 anim.to.left = pos - (anim.to.width - width);
1270 me.setSize(anim.to.width, anim.to.height);
1272 me.setLeft(anim.to.x);
1275 me.setTop(anim.to.y);
1277 me.afterExpand(false);
1283 afterExpand: function(animated) {
1285 me.setAutoScroll(me.initialConfig.autoScroll);
1287 // Restored to a calculated flex. Delete the set width and height properties so that flex works from now on.
1289 me.flex = me.savedFlex;
1290 delete me.savedFlex;
1295 // Reinstate layout out after Panel has re-expanded
1296 delete me.suspendLayout;
1297 if (animated && me.ownerCt) {
1298 me.ownerCt.doLayout();
1302 me.resizer.enable();
1305 me.fireEvent('expand', me);
1307 // Re-enable the toggle tool after an animated expand
1308 if (animated && me.collapseTool) {
1309 me.collapseTool.enable();
1314 * Shortcut for performing an {@link #expand} or {@link #collapse} based on the current state of the panel.
1315 * @return {Ext.panel.Panel} this
1317 toggleCollapse: function() {
1318 if (this.collapsed) {
1319 this.expand(this.animCollapse);
1321 this.collapse(this.collapseDirection, this.animCollapse);
1327 getKeyMap : function(){
1329 this.keyMap = Ext.create('Ext.util.KeyMap', this.el, this.keys);
1335 initDraggable : function(){
1337 * <p>If this Panel is configured {@link #draggable}, this property will contain
1338 * an instance of {@link Ext.dd.DragSource} which handles dragging the Panel.</p>
1339 * The developer must provide implementations of the abstract methods of {@link Ext.dd.DragSource}
1340 * in order to supply behaviour for each stage of the drag/drop process. See {@link #draggable}.
1341 * @type Ext.dd.DragSource.
1344 this.dd = Ext.create('Ext.panel.DD', this, Ext.isBoolean(this.draggable) ? null : this.draggable);
1347 // private - helper function for ghost
1348 ghostTools : function() {
1350 origTools = this.initialConfig.tools;
1353 Ext.each(origTools, function(tool) {
1354 // Some tools can be full components, and copying them into the ghost
1355 // actually removes them from the owning panel. You could also potentially
1356 // end up with duplicate DOM ids as well. To avoid any issues we just make
1357 // a simple bare-minimum clone of each tool for ghosting purposes.
1371 // private - used for dragging
1372 ghost: function(cls) {
1374 ghostPanel = me.ghostPanel,
1378 ghostPanel = Ext.create('Ext.panel.Panel', {
1379 renderTo: document.body,
1383 frame: Ext.supports.CSS3BorderRadius ? me.frame : false,
1385 overlapHeader: me.overlapHeader,
1386 headerPosition: me.headerPosition,
1387 width: me.getWidth(),
1388 height: me.getHeight(),
1389 iconCls: me.iconCls,
1390 baseCls: me.baseCls,
1391 tools: me.ghostTools(),
1392 cls: me.baseCls + '-ghost ' + (cls ||'')
1394 me.ghostPanel = ghostPanel;
1396 ghostPanel.floatParent = me.floatParent;
1398 ghostPanel.setZIndex(Ext.Number.from(me.el.getStyle('zIndex'), 0));
1400 ghostPanel.toFront();
1402 ghostPanel.el.show();
1403 ghostPanel.setPosition(box.x, box.y);
1404 ghostPanel.setSize(box.width, box.height);
1406 if (me.floatingItems) {
1407 me.floatingItems.hide();
1413 unghost: function(show, matchPosition) {
1415 if (!me.ghostPanel) {
1418 if (show !== false) {
1420 if (matchPosition !== false) {
1421 me.setPosition(me.ghostPanel.getPosition());
1423 if (me.floatingItems) {
1424 me.floatingItems.show();
1426 Ext.defer(me.focus, 10, me);
1428 me.ghostPanel.el.hide();
1431 initResizable: function(resizable) {
1432 if (this.collapsed) {
1433 resizable.disabled = true;
1435 this.callParent([resizable]);