DocPanel: add 'expanded' option; don't fail when no element gets passed; don't fail when files is an empty array; some reformatting

This commit is contained in:
rolux 2012-06-23 12:53:04 +02:00
parent 63d12160cd
commit 0b2371e73e

View file

@ -9,22 +9,23 @@ Ox.DocPanel <f> Documentation Panel
results [o] Array of results results [o] Array of results
select <!> select select <!> select
options <o> Options object options <o> Options object
collapsible <b|false> If true, the list can be collabsed collapsible <b|false> If true, the list can be collabsed
element <e> Default content element <e> Default content
files <a|[]> Files to parse for docs (alternative to items option) expanded <b> If true, modules and sections are expanded in the list
getModule <f> Returns module for given item files <a|[]> Files to parse for docs (alternative to items option)
getSection <f> Returns section for given item getModule <f> Returns module for given item
items <a|[]> Array of doc items (alternative to files option) getSection <f> Returns section for given item
path <s|''> Path prefix items <a|[]> Array of doc items (alternative to files option)
references <r|null> RegExp to find references path <s|''> Path prefix
replace <[[]]|[]> See Ox.SyntaxHighlighter references <r|null> RegExp to find references
resizable <b|true> If true, list is resizable replace <[[]]|[]> See Ox.SyntaxHighlighter
resize <a|[128, 256, 384]> List resize positions resizable <b|true> If true, list is resizable
runTests <b|false> If true, run tests resize <a|[128, 256, 384]> List resize positions
selected <s|''> Id of the selected item runTests <b|false> If true, run tests
showTests <b|false> If true, show test results in list selected <s|''> Id of the selected item
showTooltips <b|false> If true, show test result tooltips in list showTests <b|false> If true, show test results in list
size <s|256> Default list size showTooltips <b|false> If true, show test result tooltips in list
size <s|256> Default list size
self <o> Shared private variable self <o> Shared private variable
@*/ @*/
@ -34,9 +35,10 @@ Ox.DocPanel = function(options, self) {
var that = Ox.Element({}, self) var that = Ox.Element({}, self)
.defaults({ .defaults({
collapsible: false, collapsible: false,
element: '', element: null,
examples: [], examples: [],
examplesPath: '', examplesPath: '',
expanded: false,
files: [], files: [],
getModule: function(item) { getModule: function(item) {
return item.file.replace(self.options.path, ''); return item.file.replace(self.options.path, '');
@ -78,9 +80,7 @@ Ox.DocPanel = function(options, self) {
self.$testsStatus = $('<div>') self.$testsStatus = $('<div>')
.css({marginTop: '5px', textAlign: 'center'}) .css({marginTop: '5px', textAlign: 'center'})
.appendTo(self.$toolbar); .appendTo(self.$toolbar);
if (!self.options.showTests) { if (!self.options.results) {
self.$testsStatus.hide();
} else if (!self.options.results) {
self.options.results = {}; self.options.results = {};
self.$testsButton = Ox.Button({title: 'Run Tests'}) self.$testsButton = Ox.Button({title: 'Run Tests'})
.css({margin: '4px auto'}) .css({margin: '4px auto'})
@ -109,7 +109,7 @@ Ox.DocPanel = function(options, self) {
}) })
); );
if (self.options.files) { if (self.options.files && self.options.files.length) {
self.options.files = Ox.makeArray(self.options.files); self.options.files = Ox.makeArray(self.options.files);
self.options.items = Ox.doc(self.options.files.map(function(file) { self.options.items = Ox.doc(self.options.files.map(function(file) {
return self.options.path + file; return self.options.path + file;
@ -147,21 +147,25 @@ Ox.DocPanel = function(options, self) {
title = match ? match[1] : 'Untitled'; title = match ? match[1] : 'Untitled';
Ox.get(path + '/js/example.js', function(js) { Ox.get(path + '/js/example.js', function(js) {
var references = js.match(self.options.references); var references = js.match(self.options.references);
references && Ox.unique(references).forEach(function(reference) { if (references) {
var item = getItemByName(reference); Ox.unique(references).forEach(function(reference) {
if (item) { var item = getItemByName(reference);
item.examples = (item.examples || []).concat( if (item) {
{id: example, title: title} item.examples = (
); item.examples || []
} ).concat({id: example, title: title});
}); }
});
}
if (++i == self.options.examples.length) { if (++i == self.options.examples.length) {
self.options.items.forEach(function(item) { self.options.items.forEach(function(item) {
item.examples && item.examples.sort(function(a, b) { if (item.examples) {
a = a.title.toLowerCase(); item.examples.sort(function(a, b) {
b = b.title.toLowerCase(); a = a.title.toLowerCase();
return a < b ? -1 : a > b ? 1 : 0; b = b.title.toLowerCase();
}); return a < b ? -1 : a > b ? 1 : 0;
});
}
}); });
callback(); callback();
} }
@ -270,6 +274,7 @@ Ox.DocPanel = function(options, self) {
}); });
}); });
self.$list = Ox.TreeList({ self.$list = Ox.TreeList({
expanded: self.options.expanded,
icon: self.options.showTests icon: self.options.showTests
? getIcon ? getIcon
: Ox.UI.getImageURL('symbolCenter'), : Ox.UI.getImageURL('symbolCenter'),
@ -341,7 +346,7 @@ Ox.DocPanel = function(options, self) {
} else { } else {
self.options.selected = ''; self.options.selected = '';
self.$list.options({selected: []}); self.$list.options({selected: []});
self.$page.empty().append(self.options.element); self.$page.empty().append(self.options.element || $('<div>'));
} }
that.triggerEvent('select', {id: self.options.selected}); that.triggerEvent('select', {id: self.options.selected});
} }