TabReorderer.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. This file is part of Ext JS 4
  3. Copyright (c) 2011 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. 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.
  7. If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
  8. */
  9. /**
  10. * @class Ext.ux.TabReorderer
  11. * @extends Ext.ux.BoxReorderer
  12. * This plugin allow you to reorder tabs of a TabPanel.
  13. */
  14. Ext.define('Ext.ux.TabReorderer', {
  15. extend: 'Ext.ux.BoxReorderer',
  16. itemSelector: '.x-tab',
  17. init: function(tabPanel) {
  18. var me = this;
  19. me.callParent([tabPanel.getTabBar()]);
  20. // Ensure reorderable property is copied into dynamically added tabs
  21. tabPanel.onAdd = Ext.Function.createSequence(tabPanel.onAdd, me.onAdd);
  22. },
  23. afterFirstLayout: function() {
  24. var tabs,
  25. len,
  26. i = 0,
  27. tab;
  28. this.callParent(arguments);
  29. // Copy reorderable property from card into tab
  30. for (tabs = this.container.items.items, len = tabs.length; i < len; i++) {
  31. tab = tabs[i];
  32. if (tab.card) {
  33. tab.reorderable = tab.card.reorderable;
  34. }
  35. }
  36. },
  37. onAdd: function(card, index) {
  38. card.tab.reorderable = card.reorderable;
  39. },
  40. afterBoxReflow: function() {
  41. var me = this;
  42. // Cannot use callParent, this is not called in the scope of this plugin, but that of its Ext.dd.DD object
  43. Ext.ux.BoxReorderer.prototype.afterBoxReflow.apply(me, arguments);
  44. // Move the associated card to match the tab order
  45. if (me.dragCmp) {
  46. me.container.tabPanel.setActiveTab(me.dragCmp.card);
  47. me.container.tabPanel.move(me.startIndex, me.curIndex);
  48. }
  49. }
  50. });