szurubooru/client/js/views/help_view.js

72 lines
2.3 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');
this._sectionTemplates = {};
2016-03-29 12:34:10 +02:00
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
}
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-05-10 14:13:24 +02:00
};
2016-03-29 12:34:10 +02:00
}
2016-04-08 10:35:38 +02:00
render(ctx) {
const target = document.getElementById('content-holder');
const source = this._template();
2016-04-08 10:35:38 +02:00
ctx.section = ctx.section || 'about';
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
}
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
for (let item of source.querySelectorAll('.secondary [data-name]')) {
if (item.getAttribute('data-name') === ctx.subsection) {
item.className = 'active';
} else {
item.className = '';
}
}
views.listenToMessages(source);
views.showView(target, source);
views.scrollToHash();
2016-03-29 12:34:10 +02:00
}
}
module.exports = HelpView;