Upgrade to ExtJS 3.2.1 - Released 04/27/2010
[extjs.git] / docs / source / tabs.html
1 <html>
2 <head>
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>
7 </head>
8 <body  onload="prettyPrint();">
9     <pre class="prettyprint lang-js">/*!
10  * Ext JS Library 3.2.1
11  * Copyright(c) 2006-2010 Ext JS, Inc.
12  * licensing@extjs.com
13  * http://www.extjs.com/license
14  */
15 Ext.ns('Ext.ux');
16
17 Ext.ux.Tabs = Ext.extend(Ext.util.Observable, {
18         // Configuration options
19     activeTab: 0,
20     
21         // Our class constructor
22     constructor : function(element, config) {
23         Ext.apply(this, config);
24         Ext.ux.Tabs.superclass.constructor.call(this);
25         
26         this.addEvents(
27             'beforetabchange',
28             'tabchange'
29         );
30         
31         this.el = Ext.get(element);
32         this.init();
33     },
34     
35     init : function() {
36         var me = this;
37
38                 this.el.addClass('ux-tabs-container');
39                 
40                 this.tabStrip = this.el.child('ul');
41                 this.tabStrip.addClass('ux-tabs-strip');
42                 
43                 this.tabStrip.on('click', this.onStripClick, this, {delegate: 'a'});
44                 
45                 this.tabs = this.tabStrip.select('> li');
46                 this.cards = this.el.select('> div');
47                 
48                 this.cardsContainer = this.el.createChild({
49                         cls: 'ux-tabs-cards'
50                 });             
51                 this.cardsContainer.setWidth(this.el.getWidth());
52                 
53                 this.cards.addClass('ux-tabs-card');
54                 this.cards.appendTo(this.cardsContainer);
55                 
56                 this.el.createChild({
57                         cls: 'ux-tabs-clearfix'
58                 });
59                 
60                 this.setActiveTab(this.activeTab || 0);
61         },
62         
63         onStripClick : function(ev, t) {
64                 if(t && t.href && t.href.indexOf('#')) {
65                         ev.preventDefault();                    
66                         this.setActiveTab(t.href.split('#')[1]);
67                 }
68         },
69         
70         setActiveTab : function(tab) {
71                 var card;               
72                 if(Ext.isString(tab)) {
73                         card = Ext.get(tab);
74                         tab = this.tabStrip.child('a[href=#' + tab + ']').parent();
75                 }
76                 else if (Ext.isNumber(tab)) {
77                         tab = this.tabs.item(tab);
78                         card = Ext.get(tab.first().dom.href.split('#')[1]);
79                 }
80                 
81                 if(tab && card && this.fireEvent('beforetabchange', tab, card) !== false) {
82                         card.radioClass('ux-tabs-card-active');
83                         tab.radioClass('ux-tabs-tab-active');
84                         this.fireEvent('tabchange', tab, card);
85                 }
86         }
87 });</pre>    
88 </body>
89 </html>