3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.3.1
11 * Copyright(c) 2006-2010 Sencha Inc.
12 * licensing@sencha.com
13 * http://www.sencha.com/license
15 <div id="cls-Ext.layout.CardLayout"></div>/**
16 * @class Ext.layout.CardLayout
17 * @extends Ext.layout.FitLayout
18 * <p>This layout manages multiple child Components, each fitted to the Container, where only a single child Component can be
19 * visible at any given time. This layout style is most commonly used for wizards, tab implementations, etc.
20 * This class is intended to be extended or created via the layout:'card' {@link Ext.Container#layout} config,
21 * and should generally not need to be created directly via the new keyword.</p>
22 * <p>The CardLayout's focal method is {@link #setActiveItem}. Since only one panel is displayed at a time,
23 * the only way to move from one Component to the next is by calling setActiveItem, passing the id or index of
24 * the next panel to display. The layout itself does not provide a user interface for handling this navigation,
25 * so that functionality must be provided by the developer.</p>
26 * <p>In the following example, a simplistic wizard setup is demonstrated. A button bar is added
27 * to the footer of the containing panel to provide navigation buttons. The buttons will be handled by a
28 * common navigation routine -- for this example, the implementation of that routine has been ommitted since
29 * it can be any type of custom logic. Note that other uses of a CardLayout (like a tab control) would require a
30 * completely different implementation. For serious implementations, a better approach would be to extend
31 * CardLayout to provide the custom functionality needed. Example usage:</p>
33 var navHandler = function(direction){
34 // This routine could contain business logic required to manage the navigation steps.
35 // It would call setActiveItem as needed, manage navigation button state, handle any
36 // branching logic that might be required, handle alternate actions like cancellation
37 // or finalization, etc. A complete wizard implementation could get pretty
38 // sophisticated depending on the complexity required, and should probably be
39 // done as a subclass of CardLayout in a real-world implementation.
42 var card = new Ext.Panel({
43 title: 'Example Wizard',
45 activeItem: 0, // make sure the active item is set on the container config!
46 bodyStyle: 'padding:15px',
48 // applied to each contained panel
51 // just an example of one possible navigation scheme, using buttons
56 handler: navHandler.createDelegate(this, [-1]),
59 '->', // greedy spacer so that the buttons are aligned to each side
63 handler: navHandler.createDelegate(this, [1])
66 // the panels (or "cards") within the layout
69 html: '<h1>Welcome to the Wizard!</h1><p>Step 1 of 3</p>'
72 html: '<p>Step 2 of 3</p>'
75 html: '<h1>Congratulations!</h1><p>Step 3 of 3 - Complete</p>'
80 Ext.layout.CardLayout = Ext.extend(Ext.layout.FitLayout, {
81 <div id="cfg-Ext.layout.CardLayout-deferredRender"></div>/**
82 * @cfg {Boolean} deferredRender
83 * True to render each contained item at the time it becomes active, false to render all contained items
84 * as soon as the layout is rendered (defaults to false). If there is a significant amount of content or
85 * a lot of heavy controls being rendered into panels that are not displayed by default, setting this to
86 * true might improve performance.
88 deferredRender : false,
90 <div id="cfg-Ext.layout.CardLayout-layoutOnCardChange"></div>/**
91 * @cfg {Boolean} layoutOnCardChange
92 * True to force a layout of the active item when the active card is changed. Defaults to false.
94 layoutOnCardChange : false,
96 <div id="cfg-Ext.layout.CardLayout-renderHidden"></div>/**
97 * @cfg {Boolean} renderHidden @hide
104 <div id="method-Ext.layout.CardLayout-setActiveItem"></div>/**
105 * Sets the active (visible) item in the layout.
106 * @param {String/Number} item The string component id or numeric index of the item to activate
108 setActiveItem : function(item){
109 var ai = this.activeItem,
111 item = ct.getComponent(item);
113 // Is this a valid, different card?
114 if(item && ai != item){
116 // Changing cards, hide the current one
119 if (ai.hidden !== true) {
122 ai.fireEvent('deactivate', ai);
125 var layout = item.doLayout && (this.layoutOnCardChange || !item.rendered);
127 // Change activeItem reference
128 this.activeItem = item;
130 // The container is about to get a recursive layout, remove any deferLayout reference
131 // because it will trigger a redundant layout.
132 delete item.deferLayout;
134 // Show the new component
142 item.fireEvent('activate', item);
147 renderAll : function(ct, target){
148 if(this.deferredRender){
149 this.renderItem(this.activeItem, undefined, target);
151 Ext.layout.CardLayout.superclass.renderAll.call(this, ct, target);
155 Ext.Container.LAYOUTS['card'] = Ext.layout.CardLayout;