3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
20 Ext.onReady(function() {
21 // The only requirement for this to work is that you must have a hidden field and
22 // an iframe available in the page with ids corresponding to Ext.History.fieldId
23 // and Ext.History.iframeId. See history.html for an example.
26 // Needed if you want to handle history for multiple components in the same page.
27 // Should be something that won't be in component ids.
28 var tokenDelimiter = ':';
30 function onTabChange(tabPanel, tab) {
32 ownerCt = tabPanel.ownerCt,
36 tabs.push(tabPanel.id);
38 while (ownerCt && ownerCt.is('tabpanel')) {
39 tabs.push(ownerCt.id);
40 ownerCt = ownerCt.ownerCt;
43 newToken = tabs.reverse().join(tokenDelimiter);
45 oldToken = Ext.History.getToken();
47 if (oldToken === null || oldToken.search(newToken) === -1) {
48 Ext.History.add(newToken);
52 // Handle this change event in order to restore the UI to the appropriate history state
53 function onAfterRender() {
54 Ext.History.on('change', function(token) {
55 var parts, tabPanel, length, i;
58 parts = token.split(tokenDelimiter);
59 length = parts.length;
61 // setActiveTab in all nested tabs
62 for (i = 0; i < length - 1; i++) {
63 Ext.getCmp(parts[i]).setActiveTab(Ext.getCmp(parts[i + 1]));
68 // This is the initial default state. Necessary if you navigate starting from the
69 // page without any existing history token params and go back to the start state.
70 var activeTab1 = Ext.getCmp('main-tabs').getActiveTab(),
71 activeTab2 = activeTab1.getActiveTab();
73 onTabChange(activeTab1, activeTab2);
76 Ext.create('Ext.TabPanel', {
77 renderTo: Ext.getBody(),
102 html: 'Sub-tab 1 content'
106 html: 'Sub-tab 2 content'
110 html: 'Sub-tab 3 content'
114 tabchange: onTabChange
119 html: 'Tab 2 content'
123 html: 'Tab 3 content'
127 html: 'Tab 4 content'
131 html: 'Tab 5 content'
134 tabchange: onTabChange,
135 afterrender: onAfterRender