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