Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / examples / tabs / tabs-adv.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
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.
11
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 Ext.Loader.setConfig({enabled: true});
16
17 Ext.Loader.setPath('Ext.ux', '../ux/');
18
19 Ext.require([
20     'Ext.tab.*',
21     'Ext.ux.TabCloseMenu'
22 ]);
23
24 Ext.onReady(function() {
25     var currentItem;
26     var tabs = Ext.createWidget('tabpanel', {
27         renderTo: 'tabs',
28         resizeTabs: true,
29         enableTabScroll: true,
30         width: 600,
31         height: 250,
32         defaults: {
33             autoScroll:true,
34             bodyPadding: 10
35         },
36         items: [{
37             title: 'Tab 1',
38             iconCls: 'tabs',
39             html: 'Tab Body<br/><br/>' + Ext.example.bogusMarkup,
40             closable: true
41         }],
42         plugins: Ext.create('Ext.ux.TabCloseMenu', {
43             extraItemsTail: [
44                 '-',
45                 {
46                     text: 'Closable',
47                     checked: true,
48                     hideOnClick: true,
49                     handler: function (item) {
50                         currentItem.tab.setClosable(item.checked);
51                     }
52                 }
53             ],
54             listeners: {
55                 aftermenu: function () {
56                     currentItem = null;
57                 },
58                 beforemenu: function (menu, item) {
59                     var menuitem = menu.child('*[text="Closable"]');
60                     currentItem = item;
61                     menuitem.setChecked(item.closable);
62                 }
63             }
64         })
65     });
66
67     // tab generation code
68     var index = 0;
69     while(index < 3){
70         addTab(index % 2);
71     }
72
73     function addTab (closable) {
74         ++index;
75         tabs.add({
76             title: 'New Tab ' + index,
77             iconCls: 'tabs',
78             html: 'Tab Body ' + index + '<br/><br/>' + Ext.example.bogusMarkup,
79             closable: !!closable
80         }).show();
81     }
82
83     Ext.createWidget('button', {
84         renderTo: 'addButtonCt',
85         text: 'Add Closable Tab',
86         handler: function () {
87             addTab(true);
88         },
89         iconCls:'new-tab'
90     });
91
92     Ext.createWidget('button', {
93         renderTo: 'addButtonCt',
94         text: 'Add Unclosable Tab',
95         handler: function () {
96             addTab(false);
97         },
98         iconCls:'new-tab',
99         style: 'margin-left: 8px;'
100     });
101 });
102