-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathSubLink.js
More file actions
36 lines (29 loc) · 1004 Bytes
/
SubLink.js
File metadata and controls
36 lines (29 loc) · 1004 Bytes
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
import { validation } from "../../validation.js";
export default function SubLink({ $target, initialState, clickLink }) {
validation(new.target, "SubLink");
const $subLink = document.createElement("footer");
$subLink.className = "linkContainer";
$target.appendChild($subLink);
this.state = initialState;
this.setState = (nextState) => {
this.state = nextState;
this.render();
};
this.render = () => {
const { doc } = this.state;
$subLink.innerHTML =
doc.documents.length > 0
? doc.documents.map((el) => `<div class="link" data-id=${el.id}>${el.title}</div>`).join("")
: ``;
};
$subLink.addEventListener("click", (e) => {
const { id } = e.target.closest("div").dataset;
if (id) {
const $curLi = document.getElementById(id);
const $parentUl = $curLi.closest("ul");
$parentUl.closest("li").querySelector(".toggleFold").innerText = "▼";
$parentUl.className = "child--show";
clickLink(id);
}
});
}