2 * Listeners should be defined here instead of in the view classes
4 Ext.define('Docs.controller.Classes', {
5 extend: 'Ext.app.Controller',
10 'Docs.view.cls.Overview'
28 selector: 'classheader'
32 selector: 'classtabpanel'
44 * Fired after class shown. Used for analytics event tracking.
45 * @param {String} cls name of the class.
50 * Fired after class member scrolled to view. Used for analytics event tracking.
51 * @param {String} cls name of the class.
52 * @param {String} anchor name of the member in form type-name like "method-bind".
57 * Fired after guide shown. Used for analytics event tracking.
58 * @param {String} guide name of the guide.
63 Ext.getBody().addListener('click', function(cmp, el) {
64 this.loadClass(el.rel);
72 // Can't simply assign the loadClass function as event
73 // handler, because an extra event options object is
74 // appended to the event arguments, which we don't
75 // want to give to the loadClass, as this would render
76 // the noHistory parameter to true.
77 classclick: function(cls) {
83 afterrender: function(cmp) {
84 cmp.el.addListener('click', function(cmp, el) {
85 this.showGuide(el.rel);
94 afterrender: function(cmp) {
95 // Expand member when clicked
96 cmp.el.addListener('click', function(cmp, el) {
97 Ext.get(Ext.get(el).up('.member')).toggleCls('open');
100 delegate: '.expandable'
103 // Do nothing when clicking on not-expandable items
104 cmp.el.addListener('click', Ext.emptyFn, this, {
105 preventDefault: true,
106 delegate: '.not-expandable'
118 * @param {String} clsUrl name of the class + optionally name of the method, separated with dash.
119 * @param {Boolean} noHistory true to disable adding entry to browser history
121 loadClass: function(clsUrl, noHistory) {
125 Ext.getCmp('container').layout.setActiveItem(1);
127 // separate class and member name
128 var matches = clsUrl.match(/^(.*?)(?:-(.*))?$/);
135 Docs.History.push("/api/" + clsUrl);
138 if (this.cache[cls]) {
139 this.showClass(this.cache[cls], member);
141 if (this.getTabPanel()) {
142 this.getTabPanel().setLoading(true);
145 Ext.data.JsonP.request({
146 url: this.getBaseUrl() + '/output/' + cls + '.js',
147 callbackName: cls.replace(/\./g, '_'),
148 success: function(json, opts) {
149 this.cache[cls] = json;
150 this.showClass(json, member);
152 failure : function(response, opts) {
160 showClass: function(cls, anchor) {
161 var classOverview = this.getTabPanel().down('classoverview');
163 if (this.currentCls != cls) {
164 this.getHeader().load(cls);
166 // Init overview tab if not already available
167 if (!classOverview) {
168 classOverview = Ext.create('Docs.view.cls.Overview');
169 this.getTabPanel().add(classOverview);
170 this.getTabPanel().setActiveTab(0);
172 classOverview.load(cls);
174 this.getTabPanel().setLoading(false);
176 this.getTree().selectClass(cls.name);
177 this.fireEvent('showClass', cls.name);
181 classOverview.scrollToEl("#" + anchor);
182 this.fireEvent('showMember', cls.name, anchor);
184 classOverview.getEl().down('.x-panel-body').scrollTo('top', 0);
187 this.currentCls = cls;
190 showGuide: function(name, noHistory) {
191 noHistory || Docs.History.push("/guide/" + name);
193 Ext.data.JsonP.request({
194 url: this.getBaseUrl() + "/guides/" + name + "/README.js",
196 success: function(json) {
197 Ext.getCmp("guide").update(json.guide);
198 Ext.getCmp('container').layout.setActiveItem(2);
199 Docs.Syntax.highlight(Ext.get("guide"));
200 this.fireEvent('showGuide', name);
207 * Returns base URL used for making AJAX requests.
208 * @return {String} URL
210 getBaseUrl: function() {
211 return document.location.href.replace(/#.*/, "").replace(/index.html/, "");