From 3136c8f3811f3ac994e28235c9b0f4d3edb90b08 Mon Sep 17 00:00:00 2001 From: rolux Date: Wed, 13 Jun 2012 12:05:32 +0200 Subject: [PATCH] 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']) --- source/Ox.UI/js/Code/DocPanel.js | 65 ++++++++++++++++---------------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/source/Ox.UI/js/Code/DocPanel.js b/source/Ox.UI/js/Code/DocPanel.js index 66321c94..9fcd7f4e 100644 --- a/source/Ox.UI/js/Code/DocPanel.js +++ b/source/Ox.UI/js/Code/DocPanel.js @@ -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,40 +310,33 @@ 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.$page = Ox.DocPage({ - item: item, - replace: self.options.replace - }) - .bindEvent({ - example: function(data) { - that.triggerEvent('example', data); - }, - select: function(data) { - selectItem(data.id); - } - }); - that.$element.replaceElement(1, self.$page); - that.triggerEvent('select', {id: name}); - } + self.$list.options({ + selected: [item.module + '/' + ( + item.section ? item.section + '/' : '' + ) + item.name] + }); + self.$page = Ox.DocPage({ + item: item, + replace: self.options.replace + }) + .bindEvent({ + example: function(data) { + that.triggerEvent('example', data); + }, + select: function(data) { + selectItem(data.id); + } + }); + that.$element.replaceElement(1, self.$page); } 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) {