fix bugs in readme section

This commit is contained in:
rolux 2012-06-20 11:04:44 +02:00
parent a3f0a38bf2
commit 6145b889e5

View file

@ -243,7 +243,7 @@ Ox.load(function() {
app.data = Ox.extend(app.data, data); app.data = Ox.extend(app.data, data);
app.data.pages.forEach(function(page) { app.data.pages.forEach(function(page) {
var id = page.id == 'doc' ? 'documentation' : page.id; var id = page.id == 'doc' ? 'documentation' : page.id;
Ox.get('readme/html/_' + id + '.html' + q, function(html) { Ox.get('readme/index/' + id + '.html' + q, function(html) {
app.data.html[id] = html; app.data.html[id] = html;
if (Ox.len(app.data.html) == app.data.pages.length) { if (Ox.len(app.data.html) == app.data.pages.length) {
navigator.onLine ? Ox.getJSON(url, function(data) { navigator.onLine ? Ox.getJSON(url, function(data) {
@ -542,31 +542,41 @@ Ox.load(function() {
return $panel; return $panel;
}, },
readme: function() { readme: function() {
var $list = Ox.Container().css({overflowY: 'scroll'}), var $list = Ox.Container()
$text = Ox.Container().addClass('OxSerif OxSelectable text'), .css({overflowY: 'scroll'})
// self = {}, .on({
that = Ox.SplitPanel({ click: function(e) {
var $target = $(e.target),
$parent = $target.parent();
if ($parent.is('.item')) {
$target = $parent;
}
selectItem(
$target.is('.item') && (
$target.is(':not(.selected)')
|| !e.metaKey
) ? $target.attr('id') : ''
);
}
}),
$text = Ox.Container()
.addClass('OxSerif OxSelectable text'),
$panel = Ox.SplitPanel({
elements: [ elements: [
{element: $list, size: 256}, {element: $list, size: 256},
{element: $text} {element: $text}
], ],
orientation: 'horizontal' orientation: 'horizontal'
}/*, self*/) })
.update(function(key, value) {
key == 'selected' && selectItem(value);
})
.addClass('readme'); .addClass('readme');
Ox.sortBy(app.data.readme, '-date').forEach(function(item, i) { Ox.sortBy(app.data.readme, '-date').forEach(function(item, i) {
var $item = $('<div>') var $item = $('<div>')
.addClass('item') .addClass('item')
.attr({id: 'readme_' + item.id}) .attr({id: item.id})
.css({width: 224 - Ox.UI.SCROLLBAR_SIZE + 'px'}) .css({width: 224 - Ox.UI.SCROLLBAR_SIZE + 'px'})
.on({
click: function(e) {
if (!$(this).is('.selected')) {
selectItem(item.id);
} else if (e.metaKey) {
selectItem();
}
}
})
.appendTo($list); .appendTo($list);
$('<div>') $('<div>')
.addClass('OxSerif title') .addClass('OxSerif title')
@ -579,9 +589,14 @@ Ox.load(function() {
}); });
selectItem(app.user.item.readme); selectItem(app.user.item.readme);
function selectItem(id) { function selectItem(id) {
$('.readme .item.selected').removeClass('selected'); if (id && !Ox.getObjectById(app.data.readme, id)) {
id && $('#readme_' + id).addClass('selected'); id = '';
Ox.get('readme/html/' + (id || '_readme') + '.html', function(html) { }
$panel.find('.item.selected').removeClass('selected');
id && $panel.find('.item#' + id).addClass('selected');
Ox.get('readme/' + (
id || 'index/readme'
) + '.html', function(html) {
$text.empty() $text.empty()
.append( .append(
id ? html id ? html
@ -607,14 +622,7 @@ Ox.load(function() {
app.db(app.user); app.db(app.user);
app.url.set(); app.url.set();
} }
/* return $panel;
self.setOption = function(key, value) {
if (key == 'selected') {
selectItem(value);
}
}
*/
return that;
}, },
screen: function() { screen: function() {
return Ox.$('<div>').addClass('screen animate'); return Ox.$('<div>').addClass('screen animate');