3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.2.1
11 * Copyright(c) 2006-2010 Ext JS, Inc.
13 * http://www.extjs.com/license
15 <div id="cls-Ext.History"></div>/**
17 * @extends Ext.util.Observable
18 * History management component that allows you to register arbitrary tokens that signify application
19 * history state on navigation actions. You can then handle the history {@link #change} event in order
20 * to reset your application UI to the appropriate state when the user navigates forward or backward through
21 * the browser history stack.
24 Ext.History = (function () {
25 var iframe, hiddenField;
30 var href = top.location.href, i = href.indexOf("#");
31 return i >= 0 ? href.substr(i + 1) : null;
35 hiddenField.value = currentToken;
38 function handleStateChange(token) {
40 Ext.History.fireEvent('change', token);
43 function updateIFrame (token) {
44 var html = ['<html><body><div id="state">',Ext.util.Format.htmlEncode(token),'</div></body></html>'].join('');
46 var doc = iframe.contentWindow.document;
56 function checkIFrame() {
57 if (!iframe.contentWindow || !iframe.contentWindow.document) {
58 setTimeout(checkIFrame, 10);
62 var doc = iframe.contentWindow.document;
63 var elem = doc.getElementById("state");
64 var token = elem ? elem.innerText : null;
68 setInterval(function () {
70 doc = iframe.contentWindow.document;
71 elem = doc.getElementById("state");
73 var newtoken = elem ? elem.innerText : null;
75 var newHash = getHash();
77 if (newtoken !== token) {
79 handleStateChange(token);
80 top.location.hash = token;
83 } else if (newHash !== hash) {
85 updateIFrame(newHash);
92 Ext.History.fireEvent('ready', Ext.History);
96 currentToken = hiddenField.value ? hiddenField.value : getHash();
101 var hash = getHash();
102 setInterval(function () {
103 var newHash = getHash();
104 if (newHash !== hash) {
106 handleStateChange(hash);
111 Ext.History.fireEvent('ready', Ext.History);
116 <div id="prop-Ext.History-fieldId"></div>/**
117 * The id of the hidden field required for storing the current history token.
121 fieldId: 'x-history-field',
122 <div id="prop-Ext.History-iframeId"></div>/**
123 * The id of the iframe required by IE to manage the history stack.
127 iframeId: 'x-history-frame',
131 <div id="method-Ext.History-init"></div>/**
132 * Initialize the global History instance.
133 * @param {Boolean} onReady (optional) A callback function that will be called once the history
134 * component is fully initialized.
135 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to the browser window.
137 init: function (onReady, scope) {
139 Ext.callback(onReady, scope, [this]);
143 Ext.onReady(function(){
144 Ext.History.init(onReady, scope);
148 hiddenField = Ext.getDom(Ext.History.fieldId);
150 iframe = Ext.getDom(Ext.History.iframeId);
153 <div id="event-Ext.History-ready"></div>/**
155 * Fires when the Ext.History singleton has been initialized and is ready for use.
156 * @param {Ext.History} The Ext.History singleton.
159 <div id="event-Ext.History-change"></div>/**
161 * Fires when navigation back or forwards within the local page's history occurs.
162 * @param {String} token An identifier associated with the page state at that point in its history.
167 this.on('ready', onReady, scope, {single:true});
172 <div id="method-Ext.History-add"></div>/**
173 * Add a new token to the history stack. This can be any arbitrary value, although it would
174 * commonly be the concatenation of a component id and another id marking the specifc history
175 * state of that component. Example usage:
177 // Handle tab changes on a TabPanel
178 tabPanel.on('tabchange', function(tabPanel, tab){
179 Ext.History.add(tabPanel.id + ':' + tab.id);
182 * @param {String} token The value that defines a particular application-specific history state
183 * @param {Boolean} preventDuplicates When true, if the passed token matches the current token
184 * it will not save a new history step. Set to false if the same state can be saved more than once
185 * at the same history stack location (defaults to true).
187 add: function (token, preventDup) {
188 if(preventDup !== false){
189 if(this.getToken() == token){
194 return updateIFrame(token);
196 top.location.hash = token;
201 <div id="method-Ext.History-back"></div>/**
202 * Programmatically steps back one step in browser history (equivalent to the user pressing the Back button).
208 <div id="method-Ext.History-forward"></div>/**
209 * Programmatically steps forward one step in browser history (equivalent to the user pressing the Forward button).
215 <div id="method-Ext.History-getToken"></div>/**
216 * Retrieves the currently-active history token.
217 * @return {String} The token
219 getToken: function() {
220 return ready ? currentToken : getHash();
224 Ext.apply(Ext.History, new Ext.util.Observable());</pre>