From a4326b65e578b270b495eccac70745dbd083a76e Mon Sep 17 00:00:00 2001 From: Alan Friedman Date: Fri, 8 Jan 2016 17:58:25 -0500 Subject: [PATCH] Take out autofocus on any key press and fix enter bug --- src/public/main.js | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/public/main.js b/src/public/main.js index 71838e8..0a08ba5 100644 --- a/src/public/main.js +++ b/src/public/main.js @@ -216,19 +216,16 @@ $(function() { // Keyboard events $window.keydown(function (event) { - // Auto-focus the current input when a key is typed - if (!(event.ctrlKey || event.metaKey || event.altKey)) { - $currentInput.focus(); + // When the client hits ENTER on their keyboard and chat message input is focused + if (event.which === 13 && $('.inputMessage').is(':focus')) { + sendMessage(); + socket.emit('stop typing'); + typing = false; } - // When the client hits ENTER on their keyboard - if (event.which === 13) { - if (username) { - sendMessage(); - socket.emit('stop typing'); - typing = false; - } else { - setUsername(); - } + + // If enter is pressed on key input then close key modal + if (event.which === 13 && $('input#key').is(':focus')) { + $('#key-modal').modal('hide'); } });