]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | Ext.require([\r |
2 | 'Ext.util.History',\r | |
3 | 'Ext.tab.Panel'\r | |
4 | ]);\r | |
5 | \r | |
6 | Ext.onReady(function() {\r | |
7 | // The only requirement for this to work is that you must have a hidden field and\r | |
8 | // an iframe available in the page with ids corresponding to Ext.History.fieldId\r | |
9 | // and Ext.History.iframeId. See history.html for an example.\r | |
10 | Ext.History.init();\r | |
11 | \r | |
12 | // Needed if you want to handle history for multiple components in the same page.\r | |
13 | // Should be something that won't be in component ids.\r | |
14 | var tokenDelimiter = ':';\r | |
15 | \r | |
16 | function onTabChange(tabPanel, tab) {\r | |
17 | var tabs = [],\r | |
18 | ownerCt = tabPanel.ownerCt, \r | |
19 | oldToken, newToken;\r | |
20 | \r | |
21 | tabs.push(tab.id);\r | |
22 | tabs.push(tabPanel.id);\r | |
23 | \r | |
24 | while (ownerCt && ownerCt.is('tabpanel')) {\r | |
25 | tabs.push(ownerCt.id);\r | |
26 | ownerCt = ownerCt.ownerCt;\r | |
27 | }\r | |
28 | \r | |
29 | newToken = tabs.reverse().join(tokenDelimiter);\r | |
30 | \r | |
31 | oldToken = Ext.History.getToken();\r | |
32 | \r | |
33 | if (oldToken === null || oldToken.search(newToken) === -1) {\r | |
34 | Ext.History.add(newToken);\r | |
35 | }\r | |
36 | }\r | |
37 | \r | |
38 | // Handle this change event in order to restore the UI to the appropriate history state\r | |
39 | function onAfterRender() {\r | |
40 | Ext.History.on('change', function(token) {\r | |
41 | var parts, length, i;\r | |
42 | \r | |
43 | if (token) {\r | |
44 | parts = token.split(tokenDelimiter);\r | |
45 | length = parts.length;\r | |
46 | \r | |
47 | // setActiveTab in all nested tabs\r | |
48 | for (i = 0; i < length - 1; i++) {\r | |
49 | Ext.getCmp(parts[i]).setActiveTab(Ext.getCmp(parts[i + 1]));\r | |
50 | }\r | |
51 | }\r | |
52 | });\r | |
53 | \r | |
54 | // This is the initial default state. Necessary if you navigate starting from the\r | |
55 | // page without any existing history token params and go back to the start state.\r | |
56 | var activeTab1 = Ext.getCmp('main-tabs').getActiveTab(),\r | |
57 | activeTab2 = activeTab1.getActiveTab();\r | |
58 | \r | |
59 | onTabChange(activeTab1, activeTab2);\r | |
60 | }\r | |
61 | \r | |
62 | Ext.create('Ext.TabPanel', {\r | |
63 | renderTo: Ext.getBody(),\r | |
64 | id: 'main-tabs',\r | |
65 | height: 300,\r | |
66 | width: 600,\r | |
67 | activeTab: 0,\r | |
68 | defaults: {\r | |
69 | padding: 10\r | |
70 | },\r | |
71 | \r | |
72 | items: [{\r | |
73 | xtype: 'tabpanel',\r | |
74 | title: 'Tab 1',\r | |
75 | id: 'tab1',\r | |
76 | activeTab: 0,\r | |
77 | padding: 5,\r | |
78 | border: true,\r | |
79 | plain: true,\r | |
80 | \r | |
81 | defaults: {\r | |
82 | padding: 10\r | |
83 | },\r | |
84 | \r | |
85 | items: [{\r | |
86 | title: 'Sub-tab 1',\r | |
87 | id: 'subtab1',\r | |
88 | html: 'Sub-tab 1 content'\r | |
89 | },{\r | |
90 | title: 'Sub-tab 2',\r | |
91 | id: 'subtab2',\r | |
92 | html: 'Sub-tab 2 content'\r | |
93 | },{\r | |
94 | title: 'Sub-tab 3',\r | |
95 | id: 'subtab3',\r | |
96 | html: 'Sub-tab 3 content'\r | |
97 | }],\r | |
98 | \r | |
99 | listeners: {\r | |
100 | tabchange: onTabChange\r | |
101 | }\r | |
102 | },{\r | |
103 | title: 'Tab 2',\r | |
104 | id: 'tab2',\r | |
105 | html: 'Tab 2 content'\r | |
106 | },{\r | |
107 | title: 'Tab 3',\r | |
108 | id: 'tab3',\r | |
109 | html: 'Tab 3 content'\r | |
110 | },{\r | |
111 | title: 'Tab 4',\r | |
112 | id: 'tab4',\r | |
113 | html: 'Tab 4 content'\r | |
114 | },{\r | |
115 | title: 'Tab 5',\r | |
116 | id: 'tab5',\r | |
117 | html: 'Tab 5 content'\r | |
118 | }],\r | |
119 | listeners: {\r | |
120 | tabchange: onTabChange,\r | |
121 | afterrender: onAfterRender \r | |
122 | }\r | |
123 | });\r | |
124 | }); |