3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * This layout manages multiple child Components, each is fit to the Container, where only a single child Component
17 * can be visible at any given time. This layout style is most commonly used for wizards, tab implementations, etc.
18 * This class is intended to be extended or created via the layout:'card' {@link Ext.container.Container#layout} config,
19 * and should generally not need to be created directly via the new keyword.
21 * The CardLayout's focal method is {@link #setActiveItem}. Since only one panel is displayed at a time,
22 * the only way to move from one Component to the next is by calling setActiveItem, passing the id or index of
23 * the next panel to display. The layout itself does not provide a user interface for handling this navigation,
24 * so that functionality must be provided by the developer.
26 * Containers that are configured with a card layout will have a method setActiveItem dynamically added to it.
28 * var p = new Ext.panel.Panel({
40 Ext.define('Ext.layout.container.AbstractCard', {
42 /* Begin Definitions */
44 extend: 'Ext.layout.container.Fit',
55 * @cfg {Boolean} deferredRender
56 * True to render each contained item at the time it becomes active, false to render all contained items
57 * as soon as the layout is rendered (defaults to false). If there is a significant amount of content or
58 * a lot of heavy controls being rendered into panels that are not displayed by default, setting this to
59 * true might improve performance.
61 deferredRender : false,
63 beforeLayout: function() {
65 me.activeItem = me.getActiveItem();
66 if (me.activeItem && me.deferredRender) {
67 me.renderItems([me.activeItem], me.getRenderTarget());
71 return this.callParent(arguments);
75 onLayout: function() {
77 activeItem = me.activeItem,
78 items = me.getVisibleItems(),
80 targetBox = me.getTargetBox(),
83 for (i = 0; i < ln; i++) {
85 me.setItemBox(item, targetBox);
88 if (!me.firstActivated && activeItem) {
89 if (activeItem.fireEvent('beforeactivate', activeItem) !== false) {
90 activeItem.fireEvent('activate', activeItem);
92 me.firstActivated = true;
96 isValidParent : function(item, target, position) {
97 // Note: Card layout does not care about order within the target because only one is ever visible.
98 // We only care whether the item is a direct child of the target.
99 var itemEl = item.el ? item.el.dom : Ext.getDom(item);
100 return (itemEl && itemEl.parentNode === (target.dom || target)) || false;
104 * Return the active (visible) component in the layout.
105 * @returns {Ext.Component}
107 getActiveItem: function() {
109 if (!me.activeItem && me.owner) {
110 me.activeItem = me.parseActiveItem(me.owner.activeItem);
113 if (me.activeItem && me.owner.items.indexOf(me.activeItem) != -1) {
114 return me.activeItem;
121 parseActiveItem: function(item) {
122 if (item && item.isComponent) {
125 else if (typeof item == 'number' || item === undefined) {
126 return this.getLayoutItems()[item || 0];
129 return this.owner.getComponent(item);
134 configureItem: function(item, position) {
135 this.callParent([item, position]);
136 if (this.hideInactive && this.activeItem !== item) {
144 onRemove: function(component) {
145 if (component === this.activeItem) {
146 this.activeItem = null;
147 if (this.owner.items.getCount() === 0) {
148 this.firstActivated = false;
154 getAnimation: function(newCard, owner) {
155 var newAnim = (newCard || {}).cardSwitchAnimation;
156 if (newAnim === false) {
159 return newAnim || owner.cardSwitchAnimation;
163 * Return the active (visible) component in the layout to the next card
164 * @returns {Ext.Component} The next component or false.
166 getNext: function() {
167 //NOTE: Removed the JSDoc for this function's arguments because it is not actually supported in 4.0. This
168 //should come back in 4.1
169 var wrap = arguments[0];
170 var items = this.getLayoutItems(),
171 index = Ext.Array.indexOf(items, this.activeItem);
172 return items[index + 1] || (wrap ? items[0] : false);
176 * Sets the active (visible) component in the layout to the next card
177 * @return {Ext.Component} the activated component or false when nothing activated.
180 //NOTE: Removed the JSDoc for this function's arguments because it is not actually supported in 4.0. This
181 //should come back in 4.1
182 var anim = arguments[0], wrap = arguments[1];
183 return this.setActiveItem(this.getNext(wrap), anim);
187 * Return the active (visible) component in the layout to the previous card
188 * @returns {Ext.Component} The previous component or false.
190 getPrev: function() {
191 //NOTE: Removed the JSDoc for this function's arguments because it is not actually supported in 4.0. This
192 //should come back in 4.1
193 var wrap = arguments[0];
194 var items = this.getLayoutItems(),
195 index = Ext.Array.indexOf(items, this.activeItem);
196 return items[index - 1] || (wrap ? items[items.length - 1] : false);
200 * Sets the active (visible) component in the layout to the previous card
201 * @return {Ext.Component} the activated component or false when nothing activated.
204 //NOTE: Removed the JSDoc for this function's arguments because it is not actually supported in 4.0. This
205 //should come back in 4.1
206 var anim = arguments[0], wrap = arguments[1];
207 return this.setActiveItem(this.getPrev(wrap), anim);