TabReorderer.js 1.4 KB

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