diff --git a/source/Ox.UI/js/Code/ExamplePanel.js b/source/Ox.UI/js/Code/ExamplePanel.js index 6a1022d6..24ca3e30 100644 --- a/source/Ox.UI/js/Code/ExamplePanel.js +++ b/source/Ox.UI/js/Code/ExamplePanel.js @@ -27,7 +27,7 @@ Ox.ExamplePanel = function(options, self) { .options(options || {}) .update({ selected: function() { - self.$list.options({selected: [self.options.selected]}); + selectItem(self.options.selected); } }); @@ -49,32 +49,35 @@ Ox.ExamplePanel = function(options, self) { }) ); - loadList(function(items) { + loadItems(function(items) { + var treeItems = []; self.items = items; - self.$list = Ox.TextList({ - columns: [ - { - id: 'id', - unique: true - }, - { - id: 'title', - operator: '+', - title: 'Title', - visible: true, - width: self.options.size - Ox.UI.SCROLLBAR_SIZE - } - ], - items: self.items, - max: 1, - selected: self.options.selected - ? [self.options.selected] : [], - scrollbarVisible: true, - sort: ['+title'] + items.forEach(function(item) { + var sectionIndex = Ox.getIndexById(treeItems, item.section + '/'); + if (sectionIndex == -1) { + treeItems.push({ + id: item.section + '/', + items: [], + title: item.sectionTitle + }); + sectionIndex = treeItems.length - 1; + } + treeItems[sectionIndex].items.push(item); + }); + self.$list = Ox.TreeList({ + expanded: true, + items: treeItems, + selected: self.options.selected ? [self.options.selected] : [], + width: self.options.size }) .bindEvent({ select: function(data) { - selectItem(data.ids[0] || ''); + Ox.print('SELECT', data.ids[0]) + if (!data.ids[0] || !Ox.endsWith(data.ids[0], '/')) { + selectItem( + data.ids[0] ? data.ids[0].split('/').pop() : '' + ); + } } }); self.$panel.replaceElement(0, self.$list); @@ -82,17 +85,31 @@ Ox.ExamplePanel = function(options, self) { that.triggerEvent('load', {}); }); - function loadList(callback) { + function getItemByName(name) { + var item = null; + Ox.forEach(self.items, function(v) { + if (v.id.split('/').pop() == name) { + item = v; + Ox.Break(); + } + }); + return item; + } + + function loadItems(callback) { var items = []; self.options.examples.forEach(function(example) { var item = { html: self.options.path + example + '/index.html', id: example, - js: self.options.path + example + '/js/example.js' + js: self.options.path + example + '/js/example.js', + section: example.split('/').shift() }; Ox.get(item.html, function(html) { - var title = html.match(/