X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/7a654f8d43fdb43d78b63d90528bed6e86b608cc..3789b528d8dd8aad4558e38e22d775bcab1cbd36:/docs/js/App.js diff --git a/docs/js/App.js b/docs/js/App.js new file mode 100644 index 00000000..9b3b93f2 --- /dev/null +++ b/docs/js/App.js @@ -0,0 +1,140 @@ +/** + * Manages the front page and switching between the main parts of docs + * app. + */ +Ext.define("Docs.App", { + singleton: true, + + /** + * Returns base URL used for making AJAX requests. + * @return {String} URL + */ + getBaseUrl: function() { + return document.location.href.replace(/#.*/, "").replace(/index.html/, ""); + }, + + /** + * Initializes listeners for all kind of links on front page. + */ + init: function() { + this.initResizeWindow(); + + Ext.core.DomHelper.append(Ext.get("api-overview"), this.renderOverviewData(Docs.overviewData)); + + // load front page when clicked on logo + Ext.get(Ext.query(".header > h2 > a")[0]).addListener('click', function() { + this.setIndexMode(); + Docs.History.push(""); + }, this, {preventDefault: true}); + + // load guide when clicked on guide link + Ext.Array.forEach(Ext.query("#api-overview .guides a"), function(el) { + Ext.get(el).addListener('click', function() { + this.setGuideMode(); + Docs.Guides.load(el.className); + }, this, {preventDefault: true}); + }, this); + + // render classes tree + Ext.create('Docs.ClassTree', { + root: Docs.classData + }); + + Ext.tip.QuickTipManager.init(); + Docs.History.init(); + }, + + setIndexMode: function() { + Ext.get("top-block").setStyle({display: 'block'}); + Ext.get("top-block").update('

Ext JS 4.0 API Documentation

'); + + Ext.get("api-overview").setStyle({display: 'block'}); + Ext.get("api-guide").setStyle({display: 'none'}).update(""); + Ext.get("api-class").setStyle({display: 'none'}); + }, + + setGuideMode: function() { + Ext.get("top-block").setStyle({display: 'none'}); + + Ext.get("api-overview").setStyle({display: 'none'}); + Ext.get("api-guide").setStyle({display: 'block'}); + Ext.get("api-class").setStyle({display: 'none'}); + }, + + setClassMode: function() { + Ext.get("top-block").setStyle({display: 'block'}); + + Ext.get("api-overview").setStyle({display: 'none'}); + Ext.get("api-guide").setStyle({display: 'none'}).update(""); + Ext.get("api-class").setStyle({display: 'block'}); + }, + + initResizeWindow: function() { + this.resizeWindow(); + // Resize the main window and tree on resize + window.onresize = Ext.bind(function() { + if (!this.resizeTimeout) { + this.resizeTimeout = Ext.Function.defer(this.resizeWindow, 100, this); + } + }, this); + }, + + resizeWindow: function() { + var treePanelCmp = Ext.getCmp('treePanelCmp'), + docTabPanel = Ext.getCmp('docTabPanel'), + container = Ext.get('container'), + viewportHeight = Ext.core.Element.getViewportHeight(), + viewportWidth = Ext.core.Element.getViewportWidth(); + + if (Ext.get('notice')) { + viewportHeight = viewportHeight - 40; + } + + container.setStyle({ + position: 'absolute', + height: String(viewportHeight - 40) + 'px', + width: String(viewportWidth - 280) + 'px' + }); + + if (treePanelCmp) { + treePanelCmp.setHeight(viewportHeight - 140); + } else { + Ext.get('docContent').setHeight(viewportHeight - 90); + } + + if (docTabPanel) { + docTabPanel.setHeight(viewportHeight - 125); + } + + this.resizeTimeout = null; + }, + + renderOverviewData: function(data) { + var tpl = new Ext.XTemplate( + '', + '
', + '

{name}

', + '', + '
', + '', + '

{.}

', + '', + '
', + '
', + '
', + '
', + '
', + '
', + { + renderClasses: function(category) { + return Ext.Array.map(data.categories[category].classes, function(cls) { + return Ext.String.format('{0}', cls); + }).join("\n"); + } + } + ); + return tpl.apply(data); + } +});