From a67087b6dec12ee794e6b16d4d2f840cf085260a Mon Sep 17 00:00:00 2001 From: Konstantyn Pahsura Date: Tue, 15 Nov 2016 20:18:40 +0200 Subject: [PATCH 1/2] focus for chat changes --- modules/UI/side_pannels/chat/Chat.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/modules/UI/side_pannels/chat/Chat.js b/modules/UI/side_pannels/chat/Chat.js index a0056e2cd..1c4b29be5 100644 --- a/modules/UI/side_pannels/chat/Chat.js +++ b/modules/UI/side_pannels/chat/Chat.js @@ -157,6 +157,11 @@ function resizeChatConversation() { chat.height(window.innerHeight - 15 - msgareaHeight); } +function deferredFocus(id){ + setTimeout(function (){ + $(`#${id}`).focus(); + }, 400); +} /** * Chat related user interface. */ @@ -180,6 +185,7 @@ var Chat = { let val = this.value; this.value = ''; eventEmitter.emit(UIEvents.NICKNAME_CHANGED, val); + deferredFocus('usermsg'); } }); @@ -223,9 +229,9 @@ var Chat = { // if we are in conversation mode focus on the text input // if we are not, focus on the display name input if (APP.settings.getDisplayName()) - $('#usermsg').focus(); + deferredFocus('usermsg'); else - $('#nickinput').focus(); + deferredFocus('nickinput'); }); addSmileys(); @@ -318,13 +324,6 @@ var Chat = { setChatConversationMode (isConversationMode) { $('#' + CHAT_CONTAINER_ID) .toggleClass('is-conversation-mode', isConversationMode); - - // this is needed when we transition from no conversation mode to - // conversation mode. When user enters his nickname and hits enter, - // to focus on the write area. - if (isConversationMode) { - $('#usermsg').focus(); - } }, /** From 00aee89709b3469915257365164df18447ac0083 Mon Sep 17 00:00:00 2001 From: Konstantyn Pahsura Date: Wed, 16 Nov 2016 14:09:22 +0200 Subject: [PATCH 2/2] doc added --- modules/UI/side_pannels/chat/Chat.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/UI/side_pannels/chat/Chat.js b/modules/UI/side_pannels/chat/Chat.js index 1c4b29be5..f83aa5b7a 100644 --- a/modules/UI/side_pannels/chat/Chat.js +++ b/modules/UI/side_pannels/chat/Chat.js @@ -157,6 +157,12 @@ function resizeChatConversation() { chat.height(window.innerHeight - 15 - msgareaHeight); } +/** + * Focus input after 400 ms + * Found input by id + * + * @param id {string} input id + */ function deferredFocus(id){ setTimeout(function (){ $(`#${id}`).focus();