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 * Abstract base class for {@link Ext.layout.container.Card Card layout}.
19 Ext.define('Ext.layout.container.AbstractCard', {
21 /* Begin Definitions */
23 extend: 'Ext.layout.container.Fit',
34 * @cfg {Boolean} deferredRender
35 * True to render each contained item at the time it becomes active, false to render all contained items
36 * as soon as the layout is rendered. If there is a significant amount of content or
37 * a lot of heavy controls being rendered into panels that are not displayed by default, setting this to
38 * true might improve performance.
40 deferredRender : false,
42 beforeLayout: function() {
45 if (me.activeItem && me.deferredRender) {
46 me.renderItems([me.activeItem], me.getRenderTarget());
50 return this.callParent(arguments);
54 renderChildren: function () {
55 if (!this.deferredRender) {
61 onLayout: function() {
63 activeItem = me.activeItem,
64 items = me.getVisibleItems(),
66 targetBox = me.getTargetBox(),
69 for (i = 0; i < ln; i++) {
71 me.setItemBox(item, targetBox);
74 if (!me.firstActivated && activeItem) {
75 if (activeItem.fireEvent('beforeactivate', activeItem) !== false) {
76 activeItem.fireEvent('activate', activeItem);
78 me.firstActivated = true;
82 isValidParent : function(item, target, position) {
83 // Note: Card layout does not care about order within the target because only one is ever visible.
84 // We only care whether the item is a direct child of the target.
85 var itemEl = item.el ? item.el.dom : Ext.getDom(item);
86 return (itemEl && itemEl.parentNode === (target.dom || target)) || false;
90 * Return the active (visible) component in the layout.
91 * @returns {Ext.Component}
93 getActiveItem: function() {
95 if (!me.activeItem && me.owner) {
96 me.activeItem = me.parseActiveItem(me.owner.activeItem);
99 if (me.activeItem && me.owner.items.indexOf(me.activeItem) != -1) {
100 return me.activeItem;
107 parseActiveItem: function(item) {
108 if (item && item.isComponent) {
111 else if (typeof item == 'number' || item === undefined) {
112 return this.getLayoutItems()[item || 0];
115 return this.owner.getComponent(item);
120 configureItem: function(item, position) {
121 this.callParent([item, position]);
122 if (this.hideInactive && this.activeItem !== item) {
130 onRemove: function(component) {
131 if (component === this.activeItem) {
132 this.activeItem = null;
133 if (this.owner.items.getCount() === 0) {
134 this.firstActivated = false;
140 getAnimation: function(newCard, owner) {
141 var newAnim = (newCard || {}).cardSwitchAnimation;
142 if (newAnim === false) {
145 return newAnim || owner.cardSwitchAnimation;
149 * Return the active (visible) component in the layout to the next card
150 * @returns {Ext.Component} The next component or false.
152 getNext: function() {
153 //NOTE: Removed the JSDoc for this function's arguments because it is not actually supported in 4.0. This
154 //should come back in 4.1
155 var wrap = arguments[0];
156 var items = this.getLayoutItems(),
157 index = Ext.Array.indexOf(items, this.activeItem);
158 return items[index + 1] || (wrap ? items[0] : false);
162 * Sets the active (visible) component in the layout to the next card
163 * @return {Ext.Component} the activated component or false when nothing activated.
166 //NOTE: Removed the JSDoc for this function's arguments because it is not actually supported in 4.0. This
167 //should come back in 4.1
168 var anim = arguments[0], wrap = arguments[1];
169 return this.setActiveItem(this.getNext(wrap), anim);
173 * Return the active (visible) component in the layout to the previous card
174 * @returns {Ext.Component} The previous component or false.
176 getPrev: function() {
177 //NOTE: Removed the JSDoc for this function's arguments because it is not actually supported in 4.0. This
178 //should come back in 4.1
179 var wrap = arguments[0];
180 var items = this.getLayoutItems(),
181 index = Ext.Array.indexOf(items, this.activeItem);
182 return items[index - 1] || (wrap ? items[items.length - 1] : false);
186 * Sets the active (visible) component in the layout to the previous card
187 * @return {Ext.Component} the activated component or false when nothing activated.
190 //NOTE: Removed the JSDoc for this function's arguments because it is not actually supported in 4.0. This
191 //should come back in 4.1
192 var anim = arguments[0], wrap = arguments[1];
193 return this.setActiveItem(this.getPrev(wrap), anim);