From 0981605faed09c1cc52541edf0ef04f78b810791 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Astori?= Date: Sun, 30 Apr 2017 12:18:21 +0200 Subject: [PATCH] Add autocomplete strategy for background colors --- client/css/style.css | 4 ++++ client/js/lounge.js | 25 ++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/client/css/style.css b/client/css/style.css index af9b5605..9f731c39 100644 --- a/client/css/style.css +++ b/client/css/style.css @@ -1533,6 +1533,10 @@ kbd { display: inline-block; } +.textcomplete-item .irc-bg { + display: block; +} + /** * Tooltips v0.5.3 * See http://primercss.io/tooltips/ diff --git a/client/js/lounge.js b/client/js/lounge.js index 9b263931..8c512267 100644 --- a/client/js/lounge.js +++ b/client/js/lounge.js @@ -130,6 +130,26 @@ $(function() { index: 1 }; + const backgroundColorStrategy = { + id: "background-colors", + match: /\x03(\d{2}),(\d{0,2}|[A-Za-z ]{0,10})$/, + search(term, callback, match) { + term = term.toLowerCase(); + const matchingColorCodes = constants.colorCodeMap + .filter(i => i[0].startsWith(term) || i[1].toLowerCase().startsWith(term)) + .map(pair => pair.concat(match[1])); // Needed to pass fg color to `template`... + + callback(matchingColorCodes); + }, + template(value) { + return `${value[1]}`; + }, + replace(value) { + return "\x03$1," + value[0]; + }, + index: 2 + }; + socket.on("auth", function(data) { var login = $("#sign-in"); var token; @@ -743,7 +763,10 @@ $(function() { chat.find(".chan.active .chat").trigger("msg.sticky"); // fix growing }) .tab(completeNicks, {hint: false}) - .textcomplete([emojiStrategy, nicksStrategy, chanStrategy, commandStrategy, colorStrategy], { + .textcomplete([ + emojiStrategy, nicksStrategy, chanStrategy, commandStrategy, + foregroundColorStrategy, backgroundColorStrategy + ], { dropdownClassName: "textcomplete-menu", placement: "top" }).on({