6 Ext.onReady(function() {
7 // The only requirement for this to work is that you must have a hidden field and
8 // an iframe available in the page with ids corresponding to Ext.History.fieldId
9 // and Ext.History.iframeId. See history.html for an example.
12 // Needed if you want to handle history for multiple components in the same page.
13 // Should be something that won't be in component ids.
14 var tokenDelimiter = ':';
16 function onTabChange(tabPanel, tab) {
18 ownerCt = tabPanel.ownerCt,
22 tabs.push(tabPanel.id);
24 while (ownerCt && ownerCt.is('tabpanel')) {
25 tabs.push(ownerCt.id);
26 ownerCt = ownerCt.ownerCt;
29 newToken = tabs.reverse().join(tokenDelimiter);
31 oldToken = Ext.History.getToken();
33 if (oldToken === null || oldToken.search(newToken) === -1) {
34 Ext.History.add(newToken);
38 // Handle this change event in order to restore the UI to the appropriate history state
39 function onAfterRender() {
40 Ext.History.on('change', function(token) {
41 var parts, tabPanel, length, i;
44 parts = token.split(tokenDelimiter);
45 length = parts.length;
47 // setActiveTab in all nested tabs
48 for (i = 0; i < length - 1; i++) {
49 Ext.getCmp(parts[i]).setActiveTab(Ext.getCmp(parts[i + 1]));
54 // This is the initial default state. Necessary if you navigate starting from the
55 // page without any existing history token params and go back to the start state.
56 var activeTab1 = Ext.getCmp('main-tabs').getActiveTab(),
57 activeTab2 = activeTab1.getActiveTab();
59 onTabChange(activeTab1, activeTab2);
62 Ext.create('Ext.TabPanel', {
63 renderTo: Ext.getBody(),
88 html: 'Sub-tab 1 content'
92 html: 'Sub-tab 2 content'
96 html: 'Sub-tab 3 content'
100 tabchange: onTabChange
105 html: 'Tab 2 content'
109 html: 'Tab 3 content'
113 html: 'Tab 4 content'
117 html: 'Tab 5 content'
120 tabchange: onTabChange,
121 afterrender: onAfterRender