szurubooru/client/js/views/help_view.js

48 lines
1.4 KiB
JavaScript
Raw Normal View History

2016-03-29 12:34:10 +02:00
'use strict';
const config = require('../config.js');
const BaseView = require('./base_view.js');
class HelpView extends BaseView {
constructor() {
super();
this.template = this.getTemplate('help-template');
this.sectionTemplates = {};
const sectionKeys = ['about', 'keyboard', 'search', 'comments', 'tos'];
for (let section of sectionKeys) {
const templateName = 'help-' + section + '-template';
this.sectionTemplates[section] = this.getTemplate(templateName);
}
}
2016-04-08 10:35:38 +02:00
render(ctx) {
const target = this.contentHolder;
const source = this.template();
ctx.section = ctx.section || 'about';
if (!(ctx.section in this.sectionTemplates)) {
this.emptyView(this.contentHolder);
2016-03-29 12:34:10 +02:00
return;
}
2016-04-08 10:35:38 +02:00
this.showView(
source.querySelector('.content'),
this.sectionTemplates[ctx.section]({
name: config.name,
}));
2016-03-29 12:34:10 +02:00
2016-04-08 10:35:38 +02:00
const allItemsSelector = '[data-name]';
for (let item of source.querySelectorAll(allItemsSelector)) {
if (item.getAttribute('data-name') === ctx.section) {
2016-03-29 12:34:10 +02:00
item.className = 'active';
} else {
item.className = '';
}
}
2016-04-08 10:35:38 +02:00
this.showView(target, source);
2016-03-29 12:34:10 +02:00
}
}
module.exports = HelpView;