You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
3.3 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 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
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. Ext.onReady(function() {
  16. // The only requirement for this to work is that you must have a hidden field and
  17. // an iframe available in the page with ids corresponding to Ext.History.fieldId
  18. // and Ext.History.iframeId. See history.html for an example.
  19. Ext.History.init();
  20. // Needed if you want to handle history for multiple components in the same page.
  21. // Should be something that won't be in component ids.
  22. var tokenDelimiter = ':';
  23. var tp = new Ext.TabPanel({
  24. renderTo: Ext.getBody(),
  25. id: 'main-tabs',
  26. height: 300,
  27. width: 600,
  28. activeTab: 0,
  29. items: [{
  30. xtype: 'tabpanel',
  31. title: 'Tab 1',
  32. id: 'tab1',
  33. activeTab: 0,
  34. tabPosition: 'bottom',
  35. items: [{
  36. title: 'Sub-tab 1',
  37. id: 'subtab1'
  38. },{
  39. title: 'Sub-tab 2',
  40. id: 'subtab2'
  41. },{
  42. title: 'Sub-tab 3',
  43. id: 'subtab3'
  44. }],
  45. listeners: {
  46. 'tabchange': function(tabPanel, tab){
  47. Ext.History.add(tabPanel.id + tokenDelimiter + tab.id);
  48. }
  49. }
  50. },{
  51. title: 'Tab 2',
  52. id: 'tab2'
  53. },{
  54. title: 'Tab 3',
  55. id: 'tab3'
  56. },{
  57. title: 'Tab 4',
  58. id: 'tab4'
  59. },{
  60. title: 'Tab 5',
  61. id: 'tab5'
  62. }],
  63. listeners: {
  64. 'tabchange': function(tabPanel, tab){
  65. // Ignore tab1 since it is a separate tab panel and we're managing history for it also.
  66. // We'll use its handler instead in that case so we don't get duplicate nav events for sub tabs.
  67. if(tab.id != 'tab1'){
  68. Ext.History.add(tabPanel.id + tokenDelimiter + tab.id);
  69. }
  70. }
  71. }
  72. });
  73. // Handle this change event in order to restore the UI to the appropriate history state
  74. Ext.History.on('change', function(token){
  75. if(token){
  76. var parts = token.split(tokenDelimiter);
  77. var tabPanel = Ext.getCmp(parts[0]);
  78. var tabId = parts[1];
  79. tabPanel.show();
  80. tabPanel.setActiveTab(tabId);
  81. }else{
  82. // This is the initial default state. Necessary if you navigate starting from the
  83. // page without any existing history token params and go back to the start state.
  84. tp.setActiveTab(0);
  85. tp.getItem(0).setActiveTab(0);
  86. }
  87. });
  88. });