2012-04-04 14:59:58 +00:00
|
|
|
'use strict';
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
2012-05-27 19:34:16 +00:00
|
|
|
Ox.ExamplePanel <f:Ox.Element> Example Panel
|
2012-05-21 10:38:18 +00:00
|
|
|
(options[, self]) -> <o> Example Panel
|
|
|
|
options <o> Options
|
|
|
|
self <o> Shared private variable
|
|
|
|
@*/
|
|
|
|
|
2012-04-04 14:59:58 +00:00
|
|
|
Ox.ExamplePanel = function(options, self) {
|
|
|
|
|
|
|
|
self = self || {};
|
|
|
|
var that = Ox.Element({}, self)
|
|
|
|
.defaults({
|
2012-04-09 08:42:00 +00:00
|
|
|
element: '',
|
2012-04-04 14:59:58 +00:00
|
|
|
examples: [],
|
2012-04-04 16:26:17 +00:00
|
|
|
keywords: null,
|
2012-04-04 14:59:58 +00:00
|
|
|
path: '',
|
2012-04-06 12:10:21 +00:00
|
|
|
replaceCode: [],
|
|
|
|
replaceComment: [],
|
2012-04-08 18:20:58 +00:00
|
|
|
selected: '',
|
2012-04-04 16:26:17 +00:00
|
|
|
size: 256
|
2012-04-04 14:59:58 +00:00
|
|
|
})
|
|
|
|
.options(options || {})
|
2012-05-28 19:35:41 +00:00
|
|
|
.update({
|
|
|
|
selected: function() {
|
|
|
|
self.$list.options({selected: [self.options.selected]});
|
|
|
|
}
|
|
|
|
});
|
2012-04-04 14:59:58 +00:00
|
|
|
|
|
|
|
self.$list = Ox.Element();
|
2012-04-16 07:13:22 +00:00
|
|
|
self.$page = Ox.Element();
|
2012-04-04 14:59:58 +00:00
|
|
|
|
|
|
|
that.setElement(
|
|
|
|
self.$panel = Ox.SplitPanel({
|
|
|
|
elements: [
|
|
|
|
{
|
|
|
|
element: self.$list,
|
|
|
|
size: self.options.size
|
|
|
|
},
|
|
|
|
{
|
|
|
|
element: self.$page
|
|
|
|
}
|
|
|
|
],
|
|
|
|
orientation: 'horizontal'
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
loadList(function(items) {
|
|
|
|
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,
|
2012-04-08 18:20:58 +00:00
|
|
|
max: 1,
|
|
|
|
selected: self.options.selected
|
|
|
|
? [self.options.selected] : [],
|
2012-04-04 14:59:58 +00:00
|
|
|
scrollbarVisible: true,
|
|
|
|
sort: ['+title']
|
|
|
|
})
|
|
|
|
.bindEvent({
|
|
|
|
select: function(data) {
|
2012-04-08 18:20:58 +00:00
|
|
|
selectItem(data.ids[0] || '');
|
2012-04-04 14:59:58 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
self.$panel.replaceElement(0, self.$list);
|
2012-04-16 07:13:22 +00:00
|
|
|
selectItem(self.options.selected);
|
2012-04-04 14:59:58 +00:00
|
|
|
that.triggerEvent('load', {});
|
|
|
|
});
|
|
|
|
|
|
|
|
function loadList(callback) {
|
|
|
|
var items = [];
|
|
|
|
self.options.examples.forEach(function(example) {
|
2012-04-04 16:26:17 +00:00
|
|
|
var item = {
|
|
|
|
html: self.options.path + example + '/index.html',
|
2012-04-04 14:59:58 +00:00
|
|
|
id: example,
|
2012-04-04 16:26:17 +00:00
|
|
|
js: self.options.path + example + '/js/example.js'
|
|
|
|
};
|
|
|
|
Ox.get(item.html, function(html) {
|
|
|
|
var title = html.match(/<title>(.+)<\/title>/);
|
|
|
|
item.title = title ? title[1] : 'Untitled'
|
|
|
|
Ox.get(item.js, function(js) {
|
|
|
|
var keywords = js.match(self.options.keywords);
|
|
|
|
item.keywords = keywords ? Ox.unique(keywords).sort(function(a, b) {
|
|
|
|
a = a.toLowerCase();
|
|
|
|
b = b.toLowerCase();
|
|
|
|
return a < b ? -1 : a > b ? 1 : 0;
|
|
|
|
}) : [];
|
|
|
|
items.push(item);
|
|
|
|
items.length == self.options.examples.length && callback(items);
|
2012-04-04 14:59:58 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-04-08 18:20:58 +00:00
|
|
|
function selectItem(id) {
|
2012-04-04 16:26:17 +00:00
|
|
|
var item;
|
|
|
|
if (id) {
|
|
|
|
item = Ox.getObjectById(self.items, id);
|
|
|
|
self.$panel.replaceElement(1,
|
|
|
|
self.$page = Ox.ExamplePage({
|
|
|
|
height: window.innerHeight,
|
|
|
|
html: item.html,
|
|
|
|
js: item.js,
|
|
|
|
keywords: item.keywords,
|
2012-04-06 12:10:21 +00:00
|
|
|
replaceCode: self.options.replaceCode,
|
|
|
|
replaceComment: self.options.replaceComment,
|
2012-04-04 16:26:17 +00:00
|
|
|
title: item.title,
|
2012-04-05 15:33:22 +00:00
|
|
|
width: window.innerWidth - self.options.size
|
2012-04-04 16:26:17 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
} else {
|
2012-04-16 07:13:22 +00:00
|
|
|
self.$page.empty().append(self.options.element);
|
2012-04-04 16:26:17 +00:00
|
|
|
}
|
|
|
|
self.options.selected = id;
|
|
|
|
that.triggerEvent('select', {id: id});
|
2012-04-04 14:59:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return that;
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
};
|