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
|
@ -11,6 +11,7 @@ Ox.DocPanel <f> Documentation Panel
|
||||||
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
|
||||||
|
expanded <b> If true, modules and sections are expanded in the list
|
||||||
files <a|[]> Files to parse for docs (alternative to items option)
|
files <a|[]> Files to parse for docs (alternative to items option)
|
||||||
getModule <f> Returns module for given item
|
getModule <f> Returns module for given item
|
||||||
getSection <f> Returns section for given item
|
getSection <f> Returns section for given item
|
||||||
|
@ -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) {
|
||||||
|
Ox.unique(references).forEach(function(reference) {
|
||||||
var item = getItemByName(reference);
|
var item = getItemByName(reference);
|
||||||
if (item) {
|
if (item) {
|
||||||
item.examples = (item.examples || []).concat(
|
item.examples = (
|
||||||
{id: example, title: title}
|
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) {
|
||||||
|
item.examples.sort(function(a, b) {
|
||||||
a = a.title.toLowerCase();
|
a = a.title.toLowerCase();
|
||||||
b = b.title.toLowerCase();
|
b = b.title.toLowerCase();
|
||||||
return a < b ? -1 : a > b ? 1 : 0;
|
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});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue