// vim: et:ts=4:sw=4:sts=4:ft=javascript 'use strict'; pandora.ui.helpDialog = function() { var text = {}, $panel, $list, $text, $image, that = Ox.Dialog({ buttons: [ Ox.Button({ id: 'switch', title: Ox._('API Documentation...') }).bindEvent({ click: function() { pandora.UI.set({page: 'api'}); } }), {}, Ox.Button({ id: 'close', title: Ox._('Close') }).bindEvent({ click: function() { that.close(); } }) ], closeButton: true, content: Ox.LoadingScreen(), height: 384, keys: {escape: 'close'}, maximizeButton: true, minHeight: 256, minWidth: 544 + 2 * Ox.UI.SCROLLBAR_SIZE, removeOnClose: true, title: Ox._('Help'), width: 672 + 2 * Ox.UI.SCROLLBAR_SIZE }) .bindEvent({ close: function() { pandora.user.ui.page == 'help' && pandora.UI.set({page: ''}); }, resize: resize, 'pandora_part.help': function(data) { if (pandora.user.ui.page == 'help') { that.select(data.value == '' ? 'help' : data.value); } } }); Ox.get('/static/html/help.html', function(html) { var $html = $('
'), strings = Ox.clone(pandora.site, true); strings.addAnnotationShortcuts = strings.layers.map(function(layer, index) { return '' + index + '' + Ox._('Add {0}', [layer.item.toLowerCase()]) + ''; }).join('\n'); strings.itemName = Ox.map(strings.itemName, function(v) { return v.toLowerCase(); }); strings.signup = pandora.user.level == 'guest' ? '' + Ox._('sign up') + '' : Ox._('sign up'); $html.html(Ox.formatString(html, strings)); pandora.site.help.forEach(function(section) { var html = $html.find('#' + section.id).html(); text[section.id] = '

' + Ox._(section.title) + '

\n' + html; }); $list = Ox.TableList({ // fixme: silly _tree: true, columns: [ { id: 'title', visible: true, width: 128 - Ox.UI.SCROLLBAR_SIZE } ], items: pandora.site.help.map(function(value, index) { return Ox.extend({index: index}, value); }), max: 1, min: 1, scrollbarVisible: true, selected: [pandora.user.ui.part.help || 'help'], sort: [{key: 'index', operator: '+'}], unique: 'id' }) .bindEvent({ select: function(data) { var id = data.ids[0] == 'help' ? '' : data.ids[0]; pandora.UI.set({'part.help': id}); } }); $text = Ox.Element() .addClass('OxTextPage') .css({ padding: '16px', overflowY: 'scroll', MozUserSelect: 'text', WebkitUserSelect: 'text' }); $panel = Ox.SplitPanel({ elements: [ {element: $list, size: 128 + Ox.UI.SCROLLBAR_SIZE}, {element: $text} ], orientation: 'horizontal' }); that.select(pandora.user.ui.help).options({content: $panel}); $list.gainFocus(); }); function getImageSize() { var width = that.options('width') - 160 - 2 * Ox.UI.SCROLLBAR_SIZE, height = Math.round(width * 5/8); return {width: width, height: height}; } function resize(data) { $list.size(); $image && $image.options(getImageSize()); } that.select = function(id) { var img, $img; $text.html(text[id || 'help']).scrollTop(0); img = $text.find('img'); if (img) { $img = $(img); $img.replaceWith( $image = Ox.ImageElement( Ox.extend(getImageSize(), {src: $img.attr('src')}) ) .css({borderRadius: '8px'}) ); } $text.find('td:first-child') .css({ height: '16px', paddingRight: '8px', textAlign: 'right', whiteSpace: 'nowrap' }); pandora.createLinks($text); return that; } return that; };