1
0
Fork 0
forked from 0x2620/oxjs

ExamplePanel/ExamplePage: add mode/selected option ('source' or 'live')

This commit is contained in:
rolux 2012-07-05 21:38:02 +02:00
commit 01717f3727
2 changed files with 47 additions and 30 deletions

View file

@ -5,8 +5,10 @@ Ox.ExamplePanel <f> Example Panel
options <o> Options
self <o> Shared private variable
([options[, self]]) -> <o:Ox.SplitPanel> Example Panel
load <!> load
select <!> select
change <!> Change event
value <s> 'source' or 'live'
load <!> Load event
select <!> Select event
id <s> selected example
@*/
@ -17,6 +19,7 @@ Ox.ExamplePanel = function(options, self) {
.defaults({
element: '',
examples: [],
mode: 'source',
path: '',
references: null,
replaceCode: [],
@ -26,7 +29,15 @@ Ox.ExamplePanel = function(options, self) {
})
.options(options || {})
.update({
mode: function() {
Ox.print('mode handler', self.options.selected)
if (self.options.selected) {
self.$page.options({selected: self.options.mode});
}
},
selected: function() {
Ox.print('selected handler');
self.options.mode = 'source';
selectItem(self.options.selected);
}
});
@ -74,6 +85,7 @@ Ox.ExamplePanel = function(options, self) {
.bindEvent({
select: function(data) {
if (!data.ids[0] || !Ox.endsWith(data.ids[0], '/')) {
self.options.mode = 'source';
selectItem(
data.ids[0] ? data.ids[0].split('/').pop() : ''
);
@ -82,7 +94,7 @@ Ox.ExamplePanel = function(options, self) {
});
self.$panel.replaceElement(0, self.$list);
selectItem(self.options.selected);
that.triggerEvent('load', {});
that.triggerEvent('load', {items: self.items});
});
function getItemByName(name) {
@ -127,7 +139,8 @@ Ox.ExamplePanel = function(options, self) {
}
function selectItem(id) {
var item = id ? getItemByName(id) : null;
var item = id ? getItemByName(id) : null,
selected = self.options.selected;
if (item) {
self.options.selected = id;
self.$list.options({selected: [item.section + '/' + id]});
@ -138,10 +151,14 @@ Ox.ExamplePanel = function(options, self) {
references: item.references,
replaceCode: self.options.replaceCode,
replaceComment: self.options.replaceComment,
selected: self.options.mode,
title: item.title,
width: window.innerWidth - self.options.size
})
.bindEvent({
change: function(data) {
that.triggerEvent('change', data);
},
close: function() {
selectItem();
}
@ -152,7 +169,9 @@ Ox.ExamplePanel = function(options, self) {
self.$list.options({selected: []});
self.$page.empty().append(self.options.element);
}
that.triggerEvent('select', {id: self.options.selected});
if (self.options.selected != selected) {
that.triggerEvent('select', {id: self.options.selected});
}
}
function sortById(a, b) {