-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
31 lines (25 loc) · 870 Bytes
/
main.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
const conversationBadge = document.querySelector("#conversation-badge");
const unreadIndicator = document.querySelector("#unread-indicator");
const populateUnreadIndicator = (count) => {
if (!count) return resetUnreadIndicator();
unreadIndicator.style.background = "#CC3333";
unreadIndicator.innerHTML = count;
conversationBadge.setAttribute("class", "tilt-animation");
};
const resetUnreadIndicator = () => {
unreadIndicator.style.background = "black";
unreadIndicator.innerHTML = 0;
conversationBadge.setAttribute("class", "");
};
// unread Message on listener
zE("messenger:on", "unreadMessages", (count) => {
populateUnreadIndicator(count);
});
// on page load always close widget
zE("messenger", "close");
conversationBadge.onclick = () => {
// open widget
zE("messenger", "open");
// reset unread indicator
resetUnreadIndicator();
};