From b219c41a460a77fb8ae501ac1febaa834784927d Mon Sep 17 00:00:00 2001 From: xDashh Date: Mon, 8 Aug 2016 08:44:17 +0200 Subject: [PATCH] Mark nicks in the backlog as clickable (#114 #113) * Apply highlighting changes immediately * Mark nicks in the backlog as clickable * Fix scoping issues --- static/chat/js/chat.js | 10 ++++++---- static/chat/js/gui.js | 17 ++++++++++++++++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/static/chat/js/chat.js b/static/chat/js/chat.js index e960b543a..3bb3bcdb5 100644 --- a/static/chat/js/chat.js +++ b/static/chat/js/chat.js @@ -593,14 +593,16 @@ chat.prototype.handleCommand = function(str) { } nick = parts[1].toLowerCase(); - if (command == "unhighlight") { - delete(highlightnicks[nick]); - this.gui.push(new ChatInfoMessage("No longer highlighting: " + nick)); - } else { + var dohighlight = command == "highlight"; + if (dohighlight) { highlightnicks[nick] = true; this.gui.push(new ChatInfoMessage("Now highlighting: " + nick)); + } else { + delete(highlightnicks[nick]); + this.gui.push(new ChatInfoMessage("No longer highlighting: " + nick)); } + this.gui.renewHighlight(nick, dohighlight); this.gui.setPreference('highlightnicks', highlightnicks); break; diff --git a/static/chat/js/gui.js b/static/chat/js/gui.js index 95598b60d..95774e4b4 100644 --- a/static/chat/js/gui.js +++ b/static/chat/js/gui.js @@ -488,6 +488,13 @@ return; } + // parse backlog preliminarily to initialize nicks so the formatter will mark them as such (clickable) + for (var i = 0, j = this.backlog.length; i < j; i++){ + var obj = JSON.parse(this.backlog[i].substring(this.backlog[i].indexOf(' '))); + if(obj.nick) + this.engine.users[obj.nick] = ""; + } + for (var i = 0, j = this.backlog.length; i < j; i++) this.engine.parseAndDispatch({ data: this.backlog[i] @@ -708,6 +715,14 @@ } }, + renewHighlight: function(nick, dohighlight){ + if (dohighlight){ + this.lines.children('div[data-username="'+nick.toLowerCase()+'"]').addClass("highlight"); + } else { + this.lines.children('div[data-username="'+nick.toLowerCase()+'"]').removeClass("highlight"); + } + }, + handleHighlight: function(message){ if (!message.user || !message.user.username || message.user.username == this.engine.user.username || !this.getPreference('highlight')) return false; @@ -1099,4 +1114,4 @@ }; // END EMOTE COUNT -})(jQuery); \ No newline at end of file +})(jQuery);