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.

234 lines
7.9 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-History'>/**
  19. </span> * @class Ext.History
  20. * @extends Ext.util.Observable
  21. * History management component that allows you to register arbitrary tokens that signify application
  22. * history state on navigation actions. You can then handle the history {@link #change} event in order
  23. * to reset your application UI to the appropriate state when the user navigates forward or backward through
  24. * the browser history stack.
  25. * @singleton
  26. */
  27. Ext.History = (function () {
  28. var iframe, hiddenField;
  29. var ready = false;
  30. var currentToken;
  31. function getHash() {
  32. var href = location.href, i = href.indexOf(&quot;#&quot;),
  33. hash = i &gt;= 0 ? href.substr(i + 1) : null;
  34. if (Ext.isGecko) {
  35. hash = decodeURIComponent(hash);
  36. }
  37. return hash;
  38. }
  39. function doSave() {
  40. hiddenField.value = currentToken;
  41. }
  42. function handleStateChange(token) {
  43. currentToken = token;
  44. Ext.History.fireEvent('change', token);
  45. }
  46. function updateIFrame (token) {
  47. var html = ['&lt;html&gt;&lt;body&gt;&lt;div id=&quot;state&quot;&gt;',Ext.util.Format.htmlEncode(token),'&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;'].join('');
  48. try {
  49. var doc = iframe.contentWindow.document;
  50. doc.open();
  51. doc.write(html);
  52. doc.close();
  53. return true;
  54. } catch (e) {
  55. return false;
  56. }
  57. }
  58. function checkIFrame() {
  59. if (!iframe.contentWindow || !iframe.contentWindow.document) {
  60. setTimeout(checkIFrame, 10);
  61. return;
  62. }
  63. var doc = iframe.contentWindow.document;
  64. var elem = doc.getElementById(&quot;state&quot;);
  65. var token = elem ? elem.innerText : null;
  66. var hash = getHash();
  67. setInterval(function () {
  68. doc = iframe.contentWindow.document;
  69. elem = doc.getElementById(&quot;state&quot;);
  70. var newtoken = elem ? elem.innerText : null;
  71. var newHash = getHash();
  72. if (newtoken !== token) {
  73. token = newtoken;
  74. handleStateChange(token);
  75. location.hash = token;
  76. hash = token;
  77. doSave();
  78. } else if (newHash !== hash) {
  79. hash = newHash;
  80. updateIFrame(newHash);
  81. }
  82. }, 50);
  83. ready = true;
  84. Ext.History.fireEvent('ready', Ext.History);
  85. }
  86. function startUp() {
  87. currentToken = hiddenField.value ? hiddenField.value : getHash();
  88. if (Ext.isIE) {
  89. checkIFrame();
  90. } else {
  91. var hash = getHash();
  92. setInterval(function () {
  93. var newHash = getHash();
  94. if (newHash !== hash) {
  95. hash = newHash;
  96. handleStateChange(hash);
  97. doSave();
  98. }
  99. }, 50);
  100. ready = true;
  101. Ext.History.fireEvent('ready', Ext.History);
  102. }
  103. }
  104. return {
  105. <span id='Ext-History-property-fieldId'> /**
  106. </span> * The id of the hidden field required for storing the current history token.
  107. * @type String
  108. * @property
  109. */
  110. fieldId: 'x-history-field',
  111. <span id='Ext-History-property-iframeId'> /**
  112. </span> * The id of the iframe required by IE to manage the history stack.
  113. * @type String
  114. * @property
  115. */
  116. iframeId: 'x-history-frame',
  117. events:{},
  118. <span id='Ext-History-method-init'> /**
  119. </span> * Initialize the global History instance.
  120. * @param {Boolean} onReady (optional) A callback function that will be called once the history
  121. * component is fully initialized.
  122. * @param {Object} scope (optional) The scope (&lt;code&gt;this&lt;/code&gt; reference) in which the callback is executed. Defaults to the browser window.
  123. */
  124. init: function (onReady, scope) {
  125. if(ready) {
  126. Ext.callback(onReady, scope, [this]);
  127. return;
  128. }
  129. if(!Ext.isReady){
  130. Ext.onReady(function(){
  131. Ext.History.init(onReady, scope);
  132. });
  133. return;
  134. }
  135. hiddenField = Ext.getDom(Ext.History.fieldId);
  136. if (Ext.isIE) {
  137. iframe = Ext.getDom(Ext.History.iframeId);
  138. }
  139. this.addEvents(
  140. <span id='Ext-History-event-ready'> /**
  141. </span> * @event ready
  142. * Fires when the Ext.History singleton has been initialized and is ready for use.
  143. * @param {Ext.History} The Ext.History singleton.
  144. */
  145. 'ready',
  146. <span id='Ext-History-event-change'> /**
  147. </span> * @event change
  148. * Fires when navigation back or forwards within the local page's history occurs.
  149. * @param {String} token An identifier associated with the page state at that point in its history.
  150. */
  151. 'change'
  152. );
  153. if(onReady){
  154. this.on('ready', onReady, scope, {single:true});
  155. }
  156. startUp();
  157. },
  158. <span id='Ext-History-method-add'> /**
  159. </span> * Add a new token to the history stack. This can be any arbitrary value, although it would
  160. * commonly be the concatenation of a component id and another id marking the specifc history
  161. * state of that component. Example usage:
  162. * &lt;pre&gt;&lt;code&gt;
  163. // Handle tab changes on a TabPanel
  164. tabPanel.on('tabchange', function(tabPanel, tab){
  165. Ext.History.add(tabPanel.id + ':' + tab.id);
  166. });
  167. &lt;/code&gt;&lt;/pre&gt;
  168. * @param {String} token The value that defines a particular application-specific history state
  169. * @param {Boolean} preventDuplicates When true, if the passed token matches the current token
  170. * it will not save a new history step. Set to false if the same state can be saved more than once
  171. * at the same history stack location (defaults to true).
  172. */
  173. add: function (token, preventDup) {
  174. if(preventDup !== false){
  175. if(this.getToken() == token){
  176. return true;
  177. }
  178. }
  179. if (Ext.isIE) {
  180. return updateIFrame(token);
  181. } else {
  182. location.hash = token;
  183. return true;
  184. }
  185. },
  186. <span id='Ext-History-method-back'> /**
  187. </span> * Programmatically steps back one step in browser history (equivalent to the user pressing the Back button).
  188. */
  189. back: function(){
  190. history.go(-1);
  191. },
  192. <span id='Ext-History-method-forward'> /**
  193. </span> * Programmatically steps forward one step in browser history (equivalent to the user pressing the Forward button).
  194. */
  195. forward: function(){
  196. history.go(1);
  197. },
  198. <span id='Ext-History-method-getToken'> /**
  199. </span> * Retrieves the currently-active history token.
  200. * @return {String} The token
  201. */
  202. getToken: function() {
  203. return ready ? currentToken : getHash();
  204. }
  205. };
  206. })();
  207. Ext.apply(Ext.History, new Ext.util.Observable());</pre>
  208. </body>
  209. </html>