2016-03-29 12:34:10 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const config = require('../config.js');
|
2016-04-09 18:54:23 +02:00
|
|
|
const views = require('../util/views.js');
|
2016-03-29 12:34:10 +02:00
|
|
|
|
2016-04-09 18:54:23 +02:00
|
|
|
class HelpView {
|
2016-03-29 12:34:10 +02:00
|
|
|
constructor() {
|
2016-04-09 18:54:23 +02:00
|
|
|
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) {
|
2016-04-09 18:54:23 +02:00
|
|
|
const templateName = 'help-' + section;
|
|
|
|
this.sectionTemplates[section] = views.getTemplate(templateName);
|
2016-03-29 12:34:10 +02:00
|
|
|
}
|
2016-04-17 00:03:45 +02:00
|
|
|
this.subsectionTemplates = {
|
|
|
|
'search': {
|
|
|
|
'default': views.getTemplate('help-search-general'),
|
|
|
|
'posts': views.getTemplate('help-search-posts'),
|
|
|
|
'users': views.getTemplate('help-search-users'),
|
|
|
|
'tags': views.getTemplate('help-search-tags'),
|
|
|
|
}
|
|
|
|
}
|
2016-03-29 12:34:10 +02:00
|
|
|
}
|
|
|
|
|
2016-04-08 10:35:38 +02:00
|
|
|
render(ctx) {
|
2016-04-09 18:54:23 +02:00
|
|
|
const target = document.getElementById('content-holder');
|
2016-04-08 10:35:38 +02:00
|
|
|
const source = this.template();
|
|
|
|
|
|
|
|
ctx.section = ctx.section || 'about';
|
2016-04-09 22:35:09 +02:00
|
|
|
if (ctx.section in this.sectionTemplates) {
|
|
|
|
views.showView(
|
|
|
|
source.querySelector('.content'),
|
|
|
|
this.sectionTemplates[ctx.section]({
|
|
|
|
name: config.name,
|
|
|
|
}));
|
2016-03-29 12:34:10 +02:00
|
|
|
}
|
|
|
|
|
2016-04-17 00:03:45 +02:00
|
|
|
ctx.subsection = ctx.subsection || 'default';
|
|
|
|
if (ctx.section in this.subsectionTemplates &&
|
|
|
|
ctx.subsection in this.subsectionTemplates[ctx.section]) {
|
|
|
|
views.showView(
|
|
|
|
source.querySelector('.subcontent'),
|
|
|
|
this.subsectionTemplates[ctx.section][ctx.subsection]({
|
|
|
|
name: config.name,
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let item of source.querySelectorAll('.primary [data-name]')) {
|
2016-04-08 10:35:38 +02:00
|
|
|
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
|
|
|
|
2016-04-17 00:03:45 +02:00
|
|
|
for (let item of source.querySelectorAll('.secondary [data-name]')) {
|
|
|
|
if (item.getAttribute('data-name') === ctx.subsection) {
|
|
|
|
item.className = 'active';
|
|
|
|
} else {
|
|
|
|
item.className = '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-09 18:54:23 +02:00
|
|
|
views.listenToMessages(target);
|
|
|
|
views.showView(target, source);
|
2016-04-14 19:37:05 +02:00
|
|
|
|
|
|
|
views.scrollToHash();
|
2016-03-29 12:34:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = HelpView;
|