TabReorderer.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * @class Ext.ux.TabReorderer
  3. * @extends Ext.ux.BoxReorderer
  4. * This plugin allow you to reorder tabs of a TabPanel.
  5. */
  6. Ext.define('Ext.ux.TabReorderer', {
  7. extend: 'Ext.ux.BoxReorderer',
  8. itemSelector: '.x-tab',
  9. init: function(tabPanel) {
  10. var me = this;
  11. me.callParent([tabPanel.getTabBar()]);
  12. // Ensure reorderable property is copied into dynamically added tabs
  13. tabPanel.onAdd = Ext.Function.createSequence(tabPanel.onAdd, me.onAdd);
  14. },
  15. afterFirstLayout: function() {
  16. var tabs,
  17. len,
  18. i = 0,
  19. tab;
  20. this.callParent(arguments);
  21. // Copy reorderable property from card into tab
  22. for (tabs = this.container.items.items, len = tabs.length; i < len; i++) {
  23. tab = tabs[i];
  24. if (tab.card) {
  25. tab.reorderable = tab.card.reorderable;
  26. }
  27. }
  28. },
  29. onAdd: function(card, index) {
  30. card.tab.reorderable = card.reorderable;
  31. },
  32. afterBoxReflow: function() {
  33. var me = this;
  34. // Cannot use callParent, this is not called in the scope of this plugin, but that of its Ext.dd.DD object
  35. Ext.ux.BoxReorderer.prototype.afterBoxReflow.apply(me, arguments);
  36. // Move the associated card to match the tab order
  37. if (me.dragCmp) {
  38. me.container.tabPanel.setActiveTab(me.dragCmp.card);
  39. me.container.tabPanel.move(me.startIndex, me.curIndex);
  40. }
  41. }
  42. });