X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/7a654f8d43fdb43d78b63d90528bed6e86b608cc..3789b528d8dd8aad4558e38e22d775bcab1cbd36:/docs/js/OverviewPanel.js diff --git a/docs/js/OverviewPanel.js b/docs/js/OverviewPanel.js new file mode 100644 index 00000000..4b5ea9b0 --- /dev/null +++ b/docs/js/OverviewPanel.js @@ -0,0 +1,292 @@ +/** + * Renders the whole class-documentation page. + */ +Ext.define('Docs.OverviewPanel', { + extend: 'Ext.panel.Panel', + + id: 'doc-overview', + cls: 'doc-tab iScroll', + title: 'Overview', + autoScroll: true, + + listeners: { + afterrender: function(cmp) { + // Expand member when clicked + cmp.el.addListener('click', function(cmp, el) { + Ext.get(Ext.get(el).up('.member')).toggleCls('open'); + }, this, { + preventDefault: true, + delegate: '.expandable' + }); + // Do nothing when clicking on not-expandable items + cmp.el.addListener('click', Ext.emptyFn, this, { + preventDefault: true, + delegate: '.not-expandable' + }); + + cmp.el.addListener('click', function(cmp, el) { + Docs.ClassLoader.load(el.rel); + }, this, { + preventDefault: true, + delegate: '.docClass' + }); + } + }, + + /** + * Scrolls the specified element into view + * + * @param {String} query DomQuery selector string. + */ + scrollToEl: function(query) { + var el = Ext.get(Ext.query(query)[0]); + if (el) { + var isMember = el.hasCls("member"); + var scrollOffset = el.getY() - (isMember ? 170 : 160); + var docContent = Ext.get(Ext.query('#doc-overview .x-panel-body')[0]); + var currentScroll = docContent.getScroll()['top']; + docContent.scrollTo('top', currentScroll + scrollOffset, true); + + if (isMember && el.down(".expandable")) { + el.addCls('open'); + } + } + }, + + /** + * Renders class documentation in this panel. + * + * @param {Object} docClass + */ + load: function(docClass) { + this.docClass = docClass; + this.removeDocked(this.toolbar, true); + this.toolbar = Ext.create('Docs.OverviewToolbar', { + docClass: docClass + }); + this.addDocked(this.toolbar); + + this.update(this.renderClass(docClass)); + this.syntaxHighlight(); + }, + + // Marks all code blocks with "prettyprint" class and then calls + // the prettify library function to highlight them. + syntaxHighlight: function() { + Ext.Array.forEach(Ext.query("pre > code"), function(el) { + Ext.get(el).addCls("prettyprint"); + }); + prettyPrint(); + }, + + renderClass: function(cls) { + this.classTpl = this.classTpl || new Ext.XTemplate( + '
', + '{hierarchy}', + '{doc}', + '
', + '{members}', + '
', + '
' + ); + + return this.classTpl.apply({ + doc: cls.doc, + hierarchy: this.renderHierarchy(cls), + members: this.renderMembers(cls) + }); + }, + + renderHierarchy: function(cls) { + if (cls.superclasses.length === 0 && cls.allMixins.length === 0) { + return ""; + } + + this.hierarchyTpl = this.hierarchyTpl || new Ext.XTemplate( + '
',
+            '',
+                '

Hierarchy

', + '{tree}', + '
', + '', + '

Mixins

', + '', + '
{.}
', + '
', + '
', + '
' + ); + + return this.hierarchyTpl.apply({ + tree: cls.superclasses.length ? this.renderClassTree(cls.superclasses.concat(cls.name), true) : "", + mixins: Ext.Array.map(cls.allMixins, this.renderLink, this) + }); + }, + + renderClassTree: function(superclasses, firstChild) { + if (superclasses.length === 0) { + return ""; + } + + this.classTreeTpl = this.classTreeTpl || new Ext.XTemplate( + '
', + '{link}', + '{subtree}', + '
' + ); + + var name = superclasses[0]; + return this.classTreeTpl.apply({ + firstChild: firstChild ? 'first-child' : '', + link: superclasses.length > 1 ? this.renderLink(name) : ''+name+'', + subtree: this.renderClassTree(superclasses.slice(1)) + }); + }, + + renderLink: function(className) { + return Ext.String.format('{0}', className); + }, + + renderMembers: function(cls) { + var typeTitles = { + cfg: "Config options", + property: "Properties", + method: "Methods", + event: "Events" + }; + + // Skip rendering empty sections + var html = []; + for (var type in typeTitles) { + if (cls[type].length > 0) { + html.push(this.renderSection(cls[type], type, typeTitles[type])); + } + } + return html.join(""); + }, + + renderSection: function(members, type, title) { + this.sectionTpl = this.sectionTpl || new Ext.XTemplate( + '
', + '
Defined By
', + '

{title}

', + '{members}', + '
' + ); + + return this.sectionTpl.apply({ + type: type, + title: title, + members: Ext.Array.map(members, this.renderMemberDiv, this).join("") + }); + }, + + renderMemberDiv: function(member, index) { + this.memberTpl = this.memberTpl || new Ext.XTemplate( + '
', + // leftmost column: expand button + '', + ' ', + '', + // member name and type + link to owner class and source + '
', + '
', + '{member}
', + 'view source', + '
', + '{name}{signature}', + '
', + // short and long descriptions + '
', + '
{[this.shortDoc(values)]}
', + '
{longDoc}
', + '
', + '
', + { + // Returns contents for short documentation + shortDoc: function(cfg) { + return cfg.shortDoc ? cfg.shortDoc : cfg.doc; + } + } + ); + + return this.memberTpl.apply(Ext.apply({ + // use classname "first-child" when it's first member in its category + firstChild: (index === 0) ? "first-child" : "", + // use classname "expandable" when member has shortened description + expandable: member.shortDoc ? "expandable" : "not-expandable", + // use classname "inherited" when member is not defined in this class + inherited: member.member === this.docClass.name ? "not-inherited" : "inherited", + // method params signature or property type signature + signature: this.renderSignature(member), + // full documentation together with optional parameters and return value + longDoc: this.renderLongDoc(member) + }, member)); + }, + + renderSignature: function(member) { + if (member.tagname === "cfg" || member.tagname === "property") { + return " : " + member.type + ""; + } + else { + var ps = Ext.Array.map(member.params, this.renderShortParam, this).join(", "); + var signature = '( ' + ps + " )"; + if (member.tagname === "method") { + return signature + " : " + member["return"].type; + } + else { + return signature; + } + } + }, + + renderShortParam: function(param) { + var p = param.type + " " + param.name; + return param.optional ? "["+p+"]" : p; + }, + + renderLongDoc: function(member) { + var doc = member.doc; + + if (member.params && member.params.length > 0) { + doc += '

Parameters

'; + var ps = Ext.Array.map(member.params, this.renderLongParam, this).join(""); + doc += ""; + } + + if (member["return"]) { + doc += this.renderReturn(member["return"]); + } + + return doc; + }, + + renderLongParam: function(param) { + this.paramTpl = this.paramTpl || new Ext.XTemplate( + '
  • ', + '{name} : {type}', + '
    ', + '{doc}', + '
    ', + '
  • ' + ); + + return this.paramTpl.apply(param); + }, + + renderReturn: function(returnDoc) { + this.returnTpl = this.returnTpl || new Ext.XTemplate( + '

    Returns

    ', + '' + ); + + return this.returnTpl.apply(returnDoc); + } +});