Ox.DocPanel: fix bugs related to ids and selection (the panel's selected option is item name or empty string, the list's selected option is ['the/full/id'])

This commit is contained in:
rolux 2012-06-13 12:05:32 +02:00
parent 71499d0cfa
commit 3136c8f381

View file

@ -143,7 +143,11 @@ Ox.DocPanel = function(options, self) {
var references = js.match(self.options.references);
references && Ox.unique(references).forEach(function(reference) {
var item = getItemByName(reference);
item.examples = (item.examples || []).concat({id: example, title: title});
if (item) {
item.examples = (item.examples || []).concat(
{id: example, title: title}
);
}
});
if (++i == self.options.examples.length) {
self.options.items.forEach(function(item) {
@ -178,7 +182,7 @@ Ox.DocPanel = function(options, self) {
}
function getItemByName(name) {
var item = {};
var item = null;
Ox.forEach(self.options.items, function(v) {
if (v.name == name) {
item = v;
@ -270,7 +274,9 @@ Ox.DocPanel = function(options, self) {
})
.bindEvent({
select: function(data) {
selectItem(data.ids.length ? data.ids[0] : '')
selectItem(
data.ids.length ? Ox.last(data.ids[0].split('/')) : ''
);
}
});
self.$sidebar.replaceElement(0, self.$list);
@ -304,22 +310,14 @@ Ox.DocPanel = function(options, self) {
}
function selectItem(id) {
var item, name;
if (id && !Ox.contains(id, '/')) {
name = id;
item = getItemByName(name);
id = item ? item.module + '/' + (
item.section ? item.section + '/' : ''
) + item.name : '';
}
if (id) {
var item = id ? getItemByName(id) : null;
if (item) {
self.options.selected = id;
if (!Ox.endsWith(self.options.selected, '/')) {
if (!item) {
name = self.options.selected.split('/').slice(-1);
item = getItemByName(name);
}
self.$list.options({selected: [self.options.selected]});
self.$list.options({
selected: [item.module + '/' + (
item.section ? item.section + '/' : ''
) + item.name]
});
self.$page = Ox.DocPage({
item: item,
replace: self.options.replace
@ -333,11 +331,12 @@ Ox.DocPanel = function(options, self) {
}
});
that.$element.replaceElement(1, self.$page);
that.triggerEvent('select', {id: name});
}
} else {
self.options.selected = '';
self.$list.options({selected: []});
self.$page.empty().append(self.options.element);
}
that.triggerEvent('select', {id: self.options.selected});
}
function sortByTitle(a, b) {