From 75f16499ff558eb58fc89fb468b381b1e2df9fcf Mon Sep 17 00:00:00 2001 From: Guangcong Luo Date: Tue, 30 Apr 2013 15:38:00 -0700 Subject: [PATCH] Open PMs when clicking on PM line --- js/client-chat.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/js/client-chat.js b/js/client-chat.js index 22bd698ba..38b0196ab 100644 --- a/js/client-chat.js +++ b/js/client-chat.js @@ -8,6 +8,7 @@ 'keypress textarea': 'keyPress', 'submit form': 'submit', 'click .username': 'clickUsername', + 'click .message-pm i': 'openPM', 'click': 'clickBackground' }, initialize: function() { @@ -79,13 +80,19 @@ var name = $(e.currentTarget).data('name'); app.addPopup('user', UserPopup, {name: name, sourceEl: e.currentTarget}); }, + openPM: function(e) { + e.preventDefault(); + e.stopPropagation(); + app.focusRoom(''); + app.rooms[''].focusPM($(e.currentTarget).data('name')); + }, clickBackground: function(e) { if (!e.shiftKey && !e.cmdKey && !e.ctrlKey) { if (window.getSelection && !window.getSelection().isCollapsed) { return; } app.dismissPopups(); - this.$chatbox.focus(); + if (this.$chatbox) this.$chatbox.focus(); } }, updateUser: function() { @@ -184,7 +191,7 @@ battletype = format + ' battle'; if (format === 'Random Battle') battletype = 'Random Battle'; } - this.$chat.append('
' + battletype + ' started between ' + Tools.escapeHTML(name) + ' and ' + Tools.escapeHTML(name2) + '.
'); + this.$chat.append('
' + battletype + ' started between ' + Tools.escapeHTML(name) + ' and ' + Tools.escapeHTML(name2) + '.
'); break; case 'j': @@ -401,10 +408,12 @@ var highlight = isHighlighted ? ' style="background-color:#FDA;"' : ''; var chatDiv = '
'; var timestamp = ChatRoom.getTimestamp('lobby'); - if (name.substr(0, 1) !== ' ') clickableName = '' + Tools.escapeHTML(name.substr(0, 1)) + ''+clickableName; + if (name.charAt(0) !== ' ') clickableName = '' + Tools.escapeHTML(name.charAt(0)) + ''+clickableName; if (pm) { var pmuserid = toUserid(pm); - this.$chat.append('
' + timestamp + '' + clickableName + ': (Private to ' + Tools.escapeHTML(pm) + ') ' + messageSanitize(message) + '
'); + var oName = pm; + if (pmuserid === app.user.get('userid')) oName = name; + this.$chat.append('
' + timestamp + '' + clickableName + ': (Private to ' + Tools.escapeHTML(pm) + ') ' + messageSanitize(message) + '
'); } else if (message.substr(0,4).toLowerCase() === '/me ') { this.$chat.append(chatDiv + timestamp + ' ' + clickableName + ' ' + messageSanitize(message.substr(4)) + '
'); } else if (message.substr(0,5).toLowerCase() === '/mee ') {