Upgrade to ExtJS 4.0.1 - Released 05/18/2011
[extjs.git] / docs / js / History.js
1 /**
2  * Browser history management using Ext.util.History.
3  */
4 Ext.define("Docs.History", {
5     singleton: true,
6
7     /**
8      * Initializes history management.
9      */
10     init: function() {
11         Ext.util.History.init(function() {
12             this.navigate(Ext.util.History.getToken());
13         }, this);
14         Ext.util.History.on("change", this.navigate, this);
15     },
16
17     // Parses current URL and navigates to the page
18     navigate: function(token) {
19         var url = this.parseToken(token);
20         if (url.type === "api") {
21             Docs.ClassLoader.load(url.key, true);
22             Ext.getCmp('treePanelCmp').selectClass(url.key.replace(/-.*$/, ''));
23         }
24         else if (url.type === "guide") {
25             Docs.App.setGuideMode();
26             Docs.Guides.load(url.key, true);
27         }
28         else {
29             Docs.App.setIndexMode();
30         }
31     },
32
33     // Parses current browser location
34     parseToken: function(token) {
35         var matches = token && token.match(/\/(api|guide)\/(.*)/);
36         return matches ? {type: matches[1], key: matches[2]} : {};
37     },
38
39     /**
40      * Adds URL to history
41      *
42      * @param {String} token  the part of URL after #
43      */
44     push: function(token) {
45         Ext.util.History.add(token);
46     }
47 });