mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-05-05 20:51:49 +02:00
42 lines
No EOL
1.1 KiB
JavaScript
42 lines
No EOL
1.1 KiB
JavaScript
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;
|
|
}
|
|
}
|
|
} |