Upgrade to ExtJS 4.0.1 - Released 05/18/2011
[extjs.git] / docs / js / ClassLoader.js
1 /**
2  * Manages the loading of class documentation.
3  */
4 Ext.define("Docs.ClassLoader", {
5     singleton: true,
6     cache: {},
7
8     /**
9      * Loads class.
10      *
11      * @param {String} clsUrl  name of the class + optionally name of the method, separated with dash.
12      * @param {Boolean} noHistory  true to disable adding entry to browser history
13      */
14     load: function(clsUrl, noHistory) {
15         var cls = clsUrl;
16         var member;
17
18         // separate class and member name
19         var matches = clsUrl.match(/^(.*?)(?:-(.*))?$/);
20         if (matches) {
21             cls = matches[1];
22             member = matches[2];
23         }
24
25         if (!noHistory) {
26             Docs.History.push("/api/" + clsUrl);
27         }
28
29         Docs.App.setClassMode();
30         var docTabPanel = Ext.getCmp('docTabPanel');
31         if (docTabPanel) {
32             Ext.getCmp('docTabPanel').setActiveTab(0);
33         }
34
35         if (this.cache[cls]) {
36             this.showClass(this.cache[cls], member);
37         } else {
38             if (docTabPanel) {
39                 Ext.getCmp('doc-overview').setLoading(true);
40             }
41
42             Ext.data.JsonP.request({
43                 url: Docs.App.getBaseUrl() + '/output/' + cls + '.js',
44                 callbackName: cls.replace(/\./g, '_'),
45                 success: function(json, opts) {
46                     this.cache[cls] = json;
47                     this.showClass(json, member);
48                 },
49                 failure : function(response, opts) {
50                     console.log('Fail');
51                 },
52                 scope: this
53             });
54         }
55     },
56
57     showClass: function(cls, anchor) {
58         var docTabPanel = Ext.getCmp('docTabPanel');
59         if (!docTabPanel) {
60             Ext.create('Docs.ClassPanel');
61         }
62
63         Ext.get('docTabPanel').show();
64         var pageContent = Ext.get('pageContent');
65         if (pageContent) {
66             pageContent.setVisibilityMode(Ext.core.Element.DISPLAY).hide();
67         }
68
69         Ext.getCmp('treePanelCmp').selectClass(cls.name);
70         Docs.PageHeader.load(cls);
71
72         var docOverviewTab = Ext.getCmp('doc-overview');
73         docOverviewTab.load(cls);
74         docOverviewTab.setLoading(false);
75
76         if (anchor) {
77             Ext.getCmp('doc-overview').scrollToEl("#" + anchor);
78         } else {
79             var docContent = Ext.get(Ext.query('#doc-overview .x-panel-body')[0]);
80             docContent.scrollTo('top', 0);
81         }
82     }
83 });
84