From 6fe480d8c6991edfcc6512fecf0da92931ef5e97 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Fri, 25 Sep 2015 11:07:41 -0400 Subject: [PATCH] Adding some snazzy hotkeys to chat page --- public/src/client/chats.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/public/src/client/chats.js b/public/src/client/chats.js index 8c767a4548..511a81ca15 100644 --- a/public/src/client/chats.js +++ b/public/src/client/chats.js @@ -21,6 +21,7 @@ define('forum/chats', ['components', 'string', 'sounds', 'forum/infinitescroll', if (env === 'md' || env === 'lg') { Chats.resizeMainWindow(); + Chats.addHotkeys(); } Chats.scrollToBottom($('.expanded-chat ul')); @@ -78,6 +79,29 @@ define('forum/chats', ['components', 'string', 'sounds', 'forum/infinitescroll', Chats.addSinceHandler(Chats.getRecipientUid(), $('.expanded-chat .chat-content'), $('.expanded-chat [data-since]')); }; + Chats.addHotkeys = function() { + Mousetrap.bind('ctrl+up', function() { + var activeContact = $('.chats-list .bg-primary'), + prev = activeContact.prev(); + + if (prev.length) { + Chats.switchChat(parseInt(prev.attr('data-uid'), 10), prev.attr('data-username')); + } + + $('[component="chat/input"]').focus(); + }); + Mousetrap.bind('ctrl+down', function() { + var activeContact = $('.chats-list .bg-primary'), + next = activeContact.next(); + + if (next.length) { + Chats.switchChat(parseInt(next.attr('data-uid'), 10), next.attr('data-username')); + } + + $('[component="chat/input"]').focus(); + }); + }; + Chats.addSinceHandler = function(toUid, chatContentEl, sinceEl) { sinceEl.on('click', function() { var since = $(this).attr('data-since');