-
Notifications
You must be signed in to change notification settings - Fork 44
/
Chat.js
42 lines (36 loc) · 1.07 KB
/
Chat.js
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
class InteractiveChatbox {
constructor(a, b, c) {
this.args = {
button: a,
chatbox: b
}
this.icons = c;
this.state = false;
}
display() {
const {button, chatbox} = this.args;
button.addEventListener('click', () => this.toggleState(chatbox))
}
toggleState(chatbox) {
this.state = !this.state;
this.showOrHideChatBox(chatbox, this.args.button);
}
showOrHideChatBox(chatbox, button) {
if(this.state) {
chatbox.classList.add('chatbox--active')
this.toggleIcon(true, button);
} else if (!this.state) {
chatbox.classList.remove('chatbox--active')
this.toggleIcon(false, button);
}
}
toggleIcon(state, button) {
const { isClicked, isNotClicked } = this.icons;
let b = button.children[0].innerHTML;
if(state) {
button.children[0].innerHTML = isClicked;
} else if(!state) {
button.children[0].innerHTML = isNotClicked;
}
}
}