-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
43 lines (36 loc) · 1.38 KB
/
index.js
File metadata and controls
43 lines (36 loc) · 1.38 KB
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
const commentsContainer = document.getElementById('commentsContainer')
commentsContainer.addEventListener('click', (e) => {
if(e.target.classList[0] == 'action__btn') {
selectActionBtn({
actionBtn: e.target.classList[1],
commentElement: e.target.parentElement.parentElement.parentElement.lastElementChild
})
}
if(e.target.parentElement.classList[0] == 'action__btn') {
selectActionBtn({
actionBtn: e.target.parentElement.classList[1],
commentElement: e.target.parentElement.parentElement.parentElement.parentElement.lastElementChild
})
}
})
const selectActionBtn = ({ actionBtn, commentElement }) => {
const actionBtns = {
'action-up': (commentElement) => actionUpBtn(commentElement),
'action-down': (commentElement) => actionDownBtn(commentElement)
}
Object.entries(actionBtns).forEach(([actionBtnName, actionBtnFunction]) => {
if(actionBtnName == actionBtn) {
actionBtnFunction(commentElement)
}
})
}
const actionUpBtn = (commentElement) => {
if(commentElement.nodeName == 'UL') {
commentElement.classList.remove('comment__list--hide')
}
}
const actionDownBtn = (commentElement) => {
if(commentElement.nodeName == 'UL') {
commentElement.classList.add('comment__list--hide')
}
}