blob: efe75a91569be45827a7fbd8304ee0ed7b3de08c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
"use strict";
const views = require("../util/views.js");
const template = views.getTemplate("top-navigation");
class TopNavigationView {
constructor() {
this._hostNode = document.getElementById("top-navigation-holder");
}
get _mobileNavigationToggleNode() {
return this._hostNode.querySelector("#mobile-navigation-toggle");
}
get _navigationListNode() {
return this._hostNode.querySelector("nav > ul");
}
get _navigationLinkNodes() {
return this._navigationListNode.querySelectorAll("li > a");
}
render(ctx) {
views.replaceContent(this._hostNode, template(ctx));
this._bindMobileNavigationEvents();
}
activate(key) {
for (let itemNode of this._hostNode.querySelectorAll("[data-name]")) {
itemNode.classList.toggle(
"active",
itemNode.getAttribute("data-name") === key
);
}
}
_bindMobileNavigationEvents() {
this._mobileNavigationToggleNode.addEventListener("click", (e) =>
this._mobileNavigationToggleClick(e)
);
for (let navigationLinkNode of this._navigationLinkNodes) {
navigationLinkNode.addEventListener("click", (e) =>
this._navigationLinkClick(e)
);
}
}
_mobileNavigationToggleClick(e) {
this._navigationListNode.classList.toggle("opened");
}
_navigationLinkClick(e) {
this._navigationListNode.classList.remove("opened");
}
}
module.exports = TopNavigationView;
|