From 6b7994442d2a8dab3e6a0ae742a498bf67729ef7 Mon Sep 17 00:00:00 2001 From: Dan Seripap Date: Thu, 25 Feb 2016 23:37:45 -0500 Subject: [PATCH 1/2] CMD+K clears chat, or /clear, or CTRL+K --- src/js/chat.js | 14 ++++++++++++++ src/js/main.js | 11 +++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/js/chat.js b/src/js/chat.js index 4b6881a..c05bb19 100644 --- a/src/js/chat.js +++ b/src/js/chat.js @@ -17,6 +17,11 @@ export default class Chat { this.bindEvents(); } + clear() { + let chatArea = $('.messages'); + return chatArea.fadeOut(200, () => { chatArea.empty().show(); }); + } + // Log a message log(message, options) { let html = options && options.html === true || false; @@ -226,6 +231,15 @@ export default class Chat { console.log(err); }); } + }, { + command: 'clear', + description: 'Clears the chat screen', + paramaters: [], + multiple: true, + usage: '/clear', + action: () => { + this.clear(); + } }]; const color = () => { diff --git a/src/js/main.js b/src/js/main.js index fc7f8d0..16cadc8 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -15,6 +15,7 @@ $(function() { let $window = $(window); let $participants = $('#participants'); + let keyMapping = []; let roomId = window.location.pathname.length ? window.location.pathname : null; @@ -68,16 +69,22 @@ $(function() { } // Keyboard events - - $window.keydown(function(event) { + $window.keydown((event) => { // When the client hits ENTER on their keyboard and chat message input is focused if (event.which === 13 && !event.shiftKey && $('.inputMessage').is(':focus')) { handleMessageSending(); socket.emit('stop typing'); chat.typing = false; event.preventDefault(); + } else { + keyMapping[event.keyCode] = event.type === 'keydown'; } + }).keyup((event) => { + if ((keyMapping[17] || keyMapping[91] || keyMapping[93]) && keyMapping[75]) { + chat.clear(); + } + keyMapping = []; }); // Select message input when closing modal From 87802963f95df08bd51ac715def74351931ae4f3 Mon Sep 17 00:00:00 2001 From: Dan Seripap Date: Sat, 27 Feb 2016 10:12:57 -0500 Subject: [PATCH 2/2] Key definitions. Moving window to window handler --- src/js/main.js | 25 ++----------------------- src/js/window.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/src/js/main.js b/src/js/main.js index 5c9d0c9..dcef7a3 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -13,9 +13,7 @@ $(function() { const darkwire = new Darkwire(); const cryptoUtil = new CryptoUtil(); - let $window = $(window); let $participants = $('#participants'); - let keyMapping = []; let roomId = window.location.pathname.length ? window.location.pathname : null; @@ -68,25 +66,6 @@ $(function() { return sanitized; } - // Keyboard events - $window.keydown((event) => { - // When the client hits ENTER on their keyboard and chat message input is focused - if (event.which === 13 && !event.shiftKey && $('.inputMessage').is(':focus')) { - handleMessageSending(); - socket.emit('stop typing'); - chat.typing = false; - event.preventDefault(); - } else { - keyMapping[event.keyCode] = event.type === 'keydown'; - } - - }).keyup((event) => { - if ((keyMapping[17] || keyMapping[91] || keyMapping[93]) && keyMapping[75]) { - chat.clear(); - } - keyMapping = []; - }); - // Select message input when closing modal $('.modal').on('hidden.bs.modal', function(e) { chat.inputMessage.focus(); @@ -205,7 +184,7 @@ $(function() { darkwire.audio.soundEnabled = state; }); - function handleMessageSending() { + window.handleMessageSending = function() { let message = chat.inputMessage; let cleanedMessage = cleanInput(message.val()); let slashCommand = chat.parseCommand(cleanedMessage); @@ -227,7 +206,7 @@ $(function() { }).catch((err) => { console.log(err); }); - } + }; window.triggerFileTransfer = function(context) { const fileId = context.getAttribute('data-file'); diff --git a/src/js/window.js b/src/js/window.js index 02c0854..99992d6 100644 --- a/src/js/window.js +++ b/src/js/window.js @@ -4,6 +4,9 @@ export default class WindowHandler { constructor(darkwire, socket, chat) { this._isActive = false; this.fileHandler = new FileHandler(darkwire, socket, chat); + this.socket = socket; + this.chat = chat; + this.keyMapping = []; this.newMessages = 0; this.favicon = new Favico({ @@ -52,6 +55,32 @@ export default class WindowHandler { this._isActive = false; }; + // Keyboard events + window.onkeydown = (event) => { + // When the client hits ENTER on their keyboard and chat message input is focused + if (event.which === 13 && !event.shiftKey && $('.inputMessage').is(':focus')) { + handleMessageSending(); + this.socket.emit('stop typing'); + this.chat.typing = false; + event.preventDefault(); + } else { + this.keyMapping[event.keyCode] = event.type === 'keydown'; + } + }; + + window.onkeyup = (event) => { + /** + * 17: CTRL + * 91: Left CMD + * 93: Right CMD + * 75: K + */ + if ((this.keyMapping[17] || this.keyMapping[91] || this.keyMapping[93]) && this.keyMapping[75]) { + this.chat.clear(); + } + this.keyMapping = []; + }; + } }