2016-03-29 10:34:10 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const config = require('../config.js');
|
2016-04-09 16:54:23 +00:00
|
|
|
const views = require('../util/views.js');
|
2016-03-29 10:34:10 +00:00
|
|
|
|
2016-06-14 08:31:48 +00:00
|
|
|
const template = views.getTemplate('help');
|
|
|
|
const sectionTemplates = {
|
|
|
|
'about': views.getTemplate('help-about'),
|
|
|
|
'keyboard': views.getTemplate('help-keyboard'),
|
|
|
|
'search': views.getTemplate('help-search'),
|
|
|
|
'comments': views.getTemplate('help-comments'),
|
|
|
|
'tos': views.getTemplate('help-tos'),
|
|
|
|
};
|
|
|
|
const 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-04-09 16:54:23 +00:00
|
|
|
class HelpView {
|
2016-06-14 08:31:48 +00:00
|
|
|
constructor(section, subsection) {
|
|
|
|
this._hostNode = document.getElementById('content-holder');
|
2016-03-29 10:34:10 +00:00
|
|
|
|
2016-06-14 08:31:48 +00:00
|
|
|
const sourceNode = template();
|
|
|
|
const ctx = {
|
|
|
|
name: config.name,
|
|
|
|
};
|
2016-04-08 08:35:38 +00:00
|
|
|
|
2016-06-14 08:31:48 +00:00
|
|
|
section = section || 'about';
|
|
|
|
if (section in sectionTemplates) {
|
|
|
|
views.replaceContent(
|
|
|
|
sourceNode.querySelector('.content'),
|
|
|
|
sectionTemplates[section](ctx));
|
2016-03-29 10:34:10 +00:00
|
|
|
}
|
|
|
|
|
2016-06-14 08:31:48 +00:00
|
|
|
subsection = subsection || 'default';
|
|
|
|
if (section in subsectionTemplates &&
|
|
|
|
subsection in subsectionTemplates[section]) {
|
|
|
|
views.replaceContent(
|
|
|
|
sourceNode.querySelector('.subcontent'),
|
|
|
|
subsectionTemplates[section][subsection](ctx));
|
2016-04-16 22:03:45 +00:00
|
|
|
}
|
|
|
|
|
2016-06-14 08:31:48 +00:00
|
|
|
for (let itemNode of
|
|
|
|
sourceNode.querySelectorAll('.primary [data-name]')) {
|
|
|
|
itemNode.classList.toggle(
|
|
|
|
'active',
|
|
|
|
itemNode.getAttribute('data-name') === section);
|
2016-03-29 10:34:10 +00:00
|
|
|
}
|
2016-04-08 08:35:38 +00:00
|
|
|
|
2016-06-14 08:31:48 +00:00
|
|
|
for (let itemNode of
|
|
|
|
sourceNode.querySelectorAll('.secondary [data-name]')) {
|
|
|
|
itemNode.classList.toggle(
|
|
|
|
'active',
|
|
|
|
itemNode.getAttribute('data-name') === subsection);
|
2016-04-16 22:03:45 +00:00
|
|
|
}
|
|
|
|
|
2016-06-14 08:31:48 +00:00
|
|
|
views.replaceContent(this._hostNode, sourceNode);
|
2016-04-14 17:37:05 +00:00
|
|
|
views.scrollToHash();
|
2016-03-29 10:34:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = HelpView;
|