Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / examples / ux / TabReorderer.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 /**
16  * @class Ext.ux.TabReorderer
17  * @extends Ext.ux.BoxReorderer
18  * This plugin allow you to reorder tabs of a TabPanel.
19  */
20 Ext.define('Ext.ux.TabReorderer', {
21
22     extend: 'Ext.ux.BoxReorderer',
23
24     itemSelector: '.x-tab',
25
26     init: function(tabPanel) {
27         var me = this;
28         
29         me.callParent([tabPanel.getTabBar()]);
30
31         // Ensure reorderable property is copied into dynamically added tabs
32         tabPanel.onAdd = Ext.Function.createSequence(tabPanel.onAdd, me.onAdd);
33     },
34
35     afterFirstLayout: function() {
36         var tabs,
37             len,
38             i = 0,
39             tab;
40
41         this.callParent(arguments);
42
43         // Copy reorderable property from card into tab
44         for (tabs = this.container.items.items, len = tabs.length; i < len; i++) {
45             tab = tabs[i];
46             if (tab.card) {
47                 tab.reorderable = tab.card.reorderable;
48             }
49         }
50     },
51
52     onAdd: function(card, index) {
53         card.tab.reorderable = card.reorderable;
54     },
55
56     afterBoxReflow: function() {
57         var me = this;
58
59         // Cannot use callParent, this is not called in the scope of this plugin, but that of its Ext.dd.DD object
60         Ext.ux.BoxReorderer.prototype.afterBoxReflow.apply(me, arguments);
61
62         // Move the associated card to match the tab order
63         if (me.dragCmp) {
64             me.container.tabPanel.setActiveTab(me.dragCmp.card);
65             me.container.tabPanel.move(me.startIndex, me.curIndex);
66         }
67     }
68 });