4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-layout-container-AbstractCard'>/**
19 </span> * @class Ext.layout.container.AbstractCard
20 * @extends Ext.layout.container.Fit
21 * <p>This layout manages multiple child Components, each is fit to the Container, where only a single child Component
22 * can be visible at any given time. This layout style is most commonly used for wizards, tab implementations, etc.
23 * This class is intended to be extended or created via the layout:'card' {@link Ext.container.Container#layout} config,
24 * and should generally not need to be created directly via the new keyword.</p>
25 * <p>The CardLayout's focal method is {@link #setActiveItem}. Since only one panel is displayed at a time,
26 * the only way to move from one Component to the next is by calling setActiveItem, passing the id or index of
27 * the next panel to display. The layout itself does not provide a user interface for handling this navigation,
28 * so that functionality must be provided by the developer.</p>
29 * <p>Containers that are configured with a card layout will have a method setActiveItem dynamically added to it.
30 * <pre><code>
31 var p = new Ext.panel.Panel({
41 </code></pre>
45 Ext.define('Ext.layout.container.AbstractCard', {
47 /* Begin Definitions */
49 extend: 'Ext.layout.container.Fit',
59 <span id='Ext-layout-container-AbstractCard-cfg-deferredRender'> /**
60 </span> * @cfg {Boolean} deferredRender
61 * True to render each contained item at the time it becomes active, false to render all contained items
62 * as soon as the layout is rendered (defaults to false). If there is a significant amount of content or
63 * a lot of heavy controls being rendered into panels that are not displayed by default, setting this to
64 * true might improve performance.
66 deferredRender : false,
68 beforeLayout: function() {
70 me.activeItem = me.getActiveItem();
71 if (me.activeItem && me.deferredRender) {
72 me.renderItems([me.activeItem], me.getRenderTarget());
76 return this.callParent(arguments);
80 onLayout: function() {
82 activeItem = me.activeItem,
83 items = me.getVisibleItems(),
85 targetBox = me.getTargetBox(),
88 for (i = 0; i < ln; i++) {
90 me.setItemBox(item, targetBox);
93 if (!me.firstActivated && activeItem) {
94 if (activeItem.fireEvent('beforeactivate', activeItem) !== false) {
95 activeItem.fireEvent('activate', activeItem);
97 me.firstActivated = true;
101 isValidParent : function(item, target, position) {
102 // Note: Card layout does not care about order within the target because only one is ever visible.
103 // We only care whether the item is a direct child of the target.
104 var itemEl = item.el ? item.el.dom : Ext.getDom(item);
105 return (itemEl && itemEl.parentNode === (target.dom || target)) || false;
108 <span id='Ext-layout-container-AbstractCard-method-getActiveItem'> /**
109 </span> * Return the active (visible) component in the layout.
110 * @returns {Ext.Component}
112 getActiveItem: function() {
114 if (!me.activeItem && me.owner) {
115 me.activeItem = me.parseActiveItem(me.owner.activeItem);
118 if (me.activeItem && me.owner.items.indexOf(me.activeItem) != -1) {
119 return me.activeItem;
126 parseActiveItem: function(item) {
127 if (item && item.isComponent) {
130 else if (typeof item == 'number' || item === undefined) {
131 return this.getLayoutItems()[item || 0];
134 return this.owner.getComponent(item);
139 configureItem: function(item, position) {
140 this.callParent([item, position]);
141 if (this.hideInactive && this.activeItem !== item) {
149 onRemove: function(component) {
150 if (component === this.activeItem) {
151 this.activeItem = null;
152 if (this.owner.items.getCount() === 0) {
153 this.firstActivated = false;
159 getAnimation: function(newCard, owner) {
160 var newAnim = (newCard || {}).cardSwitchAnimation;
161 if (newAnim === false) {
164 return newAnim || owner.cardSwitchAnimation;
167 <span id='Ext-layout-container-AbstractCard-method-getNext'> /**
168 </span> * Return the active (visible) component in the layout to the next card
169 * @returns {Ext.Component}
171 getNext: function(wrap) {
172 //NOTE: Removed the JSDoc for this function's arguments because it is not actually supported in 4.0. This
173 //should come back in 4.1
175 var items = this.getLayoutItems(),
176 index = Ext.Array.indexOf(items, this.activeItem);
177 return items[index + 1] || (wrap ? items[0] : false);
180 <span id='Ext-layout-container-AbstractCard-method-next'> /**
181 </span> * Sets the active (visible) component in the layout to the next card
183 next: function(anim, wrap) {
184 //NOTE: Removed the JSDoc for this function's arguments because it is not actually supported in 4.0. This
185 //should come back in 4.1
187 return this.setActiveItem(this.getNext(wrap), anim);
190 <span id='Ext-layout-container-AbstractCard-method-getPrev'> /**
191 </span> * Return the active (visible) component in the layout to the previous card
192 * @returns {Ext.Component}
194 getPrev: function(wrap) {
195 //NOTE: Removed the JSDoc for this function's arguments because it is not actually supported in 4.0. This
196 //should come back in 4.1
198 var items = this.getLayoutItems(),
199 index = Ext.Array.indexOf(items, this.activeItem);
200 return items[index - 1] || (wrap ? items[items.length - 1] : false);
203 <span id='Ext-layout-container-AbstractCard-method-prev'> /**
204 </span> * Sets the active (visible) component in the layout to the previous card
206 prev: function(anim, wrap) {
207 //NOTE: Removed the JSDoc for this function's arguments because it is not actually supported in 4.0. This
208 //should come back in 4.1
210 return this.setActiveItem(this.getPrev(wrap), anim);