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