2020-06-06 00:03:37 +02:00
|
|
|
"use strict";
|
2016-03-29 12:34:10 +02:00
|
|
|
|
2020-06-06 00:03:37 +02:00
|
|
|
const api = require("../api.js");
|
|
|
|
const views = require("../util/views.js");
|
2016-03-29 12:34:10 +02:00
|
|
|
|
2020-06-06 00:03:37 +02:00
|
|
|
const template = views.getTemplate("help");
|
2016-06-14 10:31:48 +02:00
|
|
|
const sectionTemplates = {
|
2020-06-06 00:03:37 +02:00
|
|
|
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"),
|
2016-06-14 10:31:48 +02:00
|
|
|
};
|
|
|
|
const subsectionTemplates = {
|
2020-06-06 00:03:37 +02:00
|
|
|
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"),
|
|
|
|
pools: views.getTemplate("help-search-pools"),
|
2016-06-14 10:31:48 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2016-04-09 18:54:23 +02:00
|
|
|
class HelpView {
|
2016-06-14 10:31:48 +02:00
|
|
|
constructor(section, subsection) {
|
2020-06-06 00:03:37 +02:00
|
|
|
this._hostNode = document.getElementById("content-holder");
|
2016-03-29 12:34:10 +02:00
|
|
|
|
2016-06-14 10:31:48 +02:00
|
|
|
const sourceNode = template();
|
|
|
|
const ctx = {
|
2018-06-25 16:47:20 +02:00
|
|
|
name: api.getName(),
|
2016-06-14 10:31:48 +02:00
|
|
|
};
|
2016-04-08 10:35:38 +02:00
|
|
|
|
2020-06-06 00:03:37 +02:00
|
|
|
section = section || "about";
|
2016-06-14 10:31:48 +02:00
|
|
|
if (section in sectionTemplates) {
|
|
|
|
views.replaceContent(
|
2020-06-06 00:03:37 +02:00
|
|
|
sourceNode.querySelector(".content"),
|
|
|
|
sectionTemplates[section](ctx)
|
|
|
|
);
|
2016-03-29 12:34:10 +02:00
|
|
|
}
|
|
|
|
|
2020-06-06 00:03:37 +02:00
|
|
|
subsection = subsection || "default";
|
|
|
|
if (
|
|
|
|
section in subsectionTemplates &&
|
|
|
|
subsection in subsectionTemplates[section]
|
|
|
|
) {
|
2016-06-14 10:31:48 +02:00
|
|
|
views.replaceContent(
|
2020-06-06 00:03:37 +02:00
|
|
|
sourceNode.querySelector(".subcontent"),
|
|
|
|
subsectionTemplates[section][subsection](ctx)
|
|
|
|
);
|
2016-04-17 00:03:45 +02:00
|
|
|
}
|
|
|
|
|
2017-12-18 19:41:53 +01:00
|
|
|
views.replaceContent(this._hostNode, sourceNode);
|
|
|
|
|
2020-06-06 00:03:37 +02:00
|
|
|
for (let itemNode of sourceNode.querySelectorAll(
|
|
|
|
".primary [data-name]"
|
|
|
|
)) {
|
2016-06-14 10:31:48 +02:00
|
|
|
itemNode.classList.toggle(
|
2020-06-06 00:03:37 +02:00
|
|
|
"active",
|
|
|
|
itemNode.getAttribute("data-name") === section
|
|
|
|
);
|
|
|
|
if (itemNode.getAttribute("data-name") === section) {
|
2017-12-18 19:41:53 +01:00
|
|
|
itemNode.parentNode.scrollLeft =
|
|
|
|
itemNode.getBoundingClientRect().left -
|
2020-06-06 00:03:37 +02:00
|
|
|
itemNode.parentNode.getBoundingClientRect().left;
|
2017-12-18 19:41:53 +01:00
|
|
|
}
|
2016-03-29 12:34:10 +02:00
|
|
|
}
|
2016-04-08 10:35:38 +02:00
|
|
|
|
2020-06-06 00:03:37 +02:00
|
|
|
for (let itemNode of sourceNode.querySelectorAll(
|
|
|
|
".secondary [data-name]"
|
|
|
|
)) {
|
2016-06-14 10:31:48 +02:00
|
|
|
itemNode.classList.toggle(
|
2020-06-06 00:03:37 +02:00
|
|
|
"active",
|
|
|
|
itemNode.getAttribute("data-name") === subsection
|
|
|
|
);
|
|
|
|
if (itemNode.getAttribute("data-name") === subsection) {
|
2017-12-18 19:41:53 +01:00
|
|
|
itemNode.parentNode.scrollLeft =
|
|
|
|
itemNode.getBoundingClientRect().left -
|
2020-06-06 00:03:37 +02:00
|
|
|
itemNode.parentNode.getBoundingClientRect().left;
|
2017-12-18 19:41:53 +01:00
|
|
|
}
|
2016-04-17 00:03:45 +02:00
|
|
|
}
|
|
|
|
|
2016-07-13 17:18:28 +02:00
|
|
|
views.syncScrollPosition();
|
2016-03-29 12:34:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = HelpView;
|