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 views = require('../util/views.js');
2016-03-29 12:34:10 +02:00
class HelpView {
2016-03-29 12:34:10 +02:00
constructor() {
this.template = views.getTemplate('help');
2016-03-29 12:34:10 +02:00
this.sectionTemplates = {};
const sectionKeys = ['about', 'keyboard', 'search', 'comments', 'tos'];
for (let section of sectionKeys) {
const templateName = 'help-' + section;
this.sectionTemplates[section] = views.getTemplate(templateName);
2016-03-29 12:34:10 +02:00
}
}
2016-04-08 10:35:38 +02:00
render(ctx) {
const target = document.getElementById('content-holder');
2016-04-08 10:35:38 +02:00
const source = this.template();
ctx.section = ctx.section || 'about';
if (!(ctx.section in this.sectionTemplates)) {
views.emptyView(target);
2016-03-29 12:34:10 +02:00
return;
}
views.showView(
2016-04-08 10:35:38 +02:00
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
views.listenToMessages(target);
views.showView(target, source);
2016-03-29 12:34:10 +02:00
}
}
module.exports = HelpView;