From 34ab8f09b92e3d299019377adf21ad7e51e0b360 Mon Sep 17 00:00:00 2001 From: Evert Date: Fri, 23 Sep 2016 10:56:34 +0300 Subject: [PATCH] implement black magic --- public/js/main.js | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/public/js/main.js b/public/js/main.js index 13ccec1..1f608a2 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -75,11 +75,10 @@ class Tab { frame.appendChild(ttt); this.element = ttt; - let instance = this; - ttt.addEventListener('click', function() { - if(instance.buffer.active) + ttt.addEventListener('click', () => { + if(this.buffer.active) return; - irc.chat.render(instance.buffer); + irc.chat.render(this.buffer); }, false); } @@ -114,6 +113,7 @@ class Buffer { this.topic = null; this.input = ""; this.lastscroll = 0; + this.unreadCount = 0; this.server = servername; this.name = buffername; @@ -136,6 +136,8 @@ class Buffer { render() { this.active = true; this.tab.setActive(true); + this.unreadCount = 0; + this.tab.setUnreadCount(0); let chat = this.frame.querySelector('.chatarea'); let topicbar = chat.querySelector('.topicbar'); @@ -162,10 +164,9 @@ class Buffer { this.letterbox.innerHTML = ""; - let instance = this; for(let t in this.messages) { - let mesg = instance.messages[t]; - instance.appendMessage({message: mesg.message, sender: mesg.sender, type: mesg.type, time: mesg.time}); + let mesg = this.messages[t]; + this.appendMessage({message: mesg.message, sender: mesg.sender, type: mesg.type, time: mesg.time}); } } @@ -194,6 +195,10 @@ class Buffer { if(this.active) this.appendMessage(mesg); + else + this.unreadCount += 1; + + this.tab.setUnreadCount(this.unreadCount); } close() { @@ -203,8 +208,6 @@ class Buffer { class IRCConnector { constructor(frame) { - let instance = this; - this.frame = frame; this.messenger = frame.querySelector('#connmsg'); this.f_form = frame.querySelector('#IRCConnector'); @@ -215,18 +218,18 @@ class IRCConnector { this.f_port = this.f_form.querySelector('#port'); this.formLocked = false; - this.f_form.onsubmit = function(e) { - if(instance.formLocked) { + this.f_form.onsubmit = (e) => { + if(this.formLocked) { e.preventDefault(); return false; } - instance.formLocked = true; + this.formLocked = true; - let success = instance.validateForm(e); + let success = this.validateForm(e); if(!success) - instance.formLocked = false; + this.formLocked = false; } } @@ -397,7 +400,6 @@ class IRCChatWindow { } render(buffer) { - let instance = this; let activeNow = this.getActiveBuffer(); if(activeNow) {