From 0c7c2db875e41610bffaa8dfc63253c7fa60694a Mon Sep 17 00:00:00 2001 From: Guangcong Luo Date: Tue, 30 Apr 2013 13:03:02 -0700 Subject: [PATCH] Focus text area by clicking anywhere in the chat area --- js/client-chat.js | 13 ++++++++++++- js/client-mainmenu.js | 16 +++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/js/client-chat.js b/js/client-chat.js index 86ea002f1..6422cdfb8 100644 --- a/js/client-chat.js +++ b/js/client-chat.js @@ -7,7 +7,8 @@ events: { 'keypress textarea': 'keyPress', 'submit form': 'submit', - 'click .username': 'clickUsername' + 'click .username': 'clickUsername', + 'click': 'clickBackground' }, initialize: function() { var buf = '
Connecting...
'; @@ -74,9 +75,19 @@ }, clickUsername: function(e) { e.stopPropagation(); + e.preventDefault(); var name = $(e.currentTarget).data('name'); app.addPopup('user', UserPopup, {name: name, sourceEl: e.currentTarget}); }, + clickBackground: function(e) { + if (!e.shiftKey && !e.cmdKey && !e.ctrlKey) { + if (window.getSelection && !window.getSelection().isCollapsed) { + return; + } + app.dismissPopups(); + this.$chatbox.focus(); + } + }, updateUser: function() { var name = app.user.get('name'); var userid = app.user.get('userid'); diff --git a/js/client-mainmenu.js b/js/client-mainmenu.js index 471ef972c..d26f2da4c 100644 --- a/js/client-mainmenu.js +++ b/js/client-mainmenu.js @@ -7,7 +7,8 @@ 'click .button': 'clickButton', 'keydown textarea': 'keyPress', 'click .username': 'clickUsername', - 'click .closebutton': 'closePM' + 'click .closebutton': 'closePM', + 'click .pm-window': 'clickPMBackground' }, initialize: function() { // left menu @@ -54,7 +55,7 @@ var $pmWindow = this.$pmBox.find('.pm-window-'+userid); if (!$pmWindow.length) { var buf = '

'+Tools.escapeHTML(name)+'

'; - buf += '
'; + buf += '
'; $pmWindow = $(buf).prependTo(this.$pmBox); $pmWindow.find('textarea').autoResize({ animateDuration: 100, @@ -77,7 +78,7 @@ this.$pmBox.find('.pm-window-'+userid).hide(); }, focusPM: function(name) { - this.openPM(name).find('textarea').focus(); + this.openPM(name).find('textarea[name=message]').focus(); }, keyPress: function(e) { if (e.keyCode === 13 && !e.shiftKey) { // Enter @@ -102,6 +103,15 @@ var name = $(e.currentTarget).data('name'); app.addPopup('user', UserPopup, {name: name, sourceEl: e.currentTarget}); }, + clickPMBackground: function(e) { + if (!e.shiftKey && !e.cmdKey && !e.ctrlKey) { + if (window.getSelection && !window.getSelection().isCollapsed) { + return; + } + app.dismissPopups(); + $(e.currentTarget).find('textarea[name=message]').focus(); + } + }, updateSearch: function() { if (window.BattleFormats) { this.$('.mainmenu button.big').html('Look for a battle').removeClass('disabled');