Commit f69e39dc authored by JC Brand's avatar JC Brand

Reuse code for submitting a message

parent cf1e8f29
...@@ -156,7 +156,7 @@ ...@@ -156,7 +156,7 @@
events: { events: {
'click .close-chatbox-button': 'close', 'click .close-chatbox-button': 'close',
'keypress .chat-textarea': 'keyPressed', 'keypress .chat-textarea': 'keyPressed',
'click .send-button': 'onSendButtonClicked', 'click .send-button': 'onFormSubmitted',
'click .toggle-smiley': 'toggleEmojiMenu', 'click .toggle-smiley': 'toggleEmojiMenu',
'click .toggle-smiley ul.emoji-picker li': 'insertEmoji', 'click .toggle-smiley ul.emoji-picker li': 'insertEmoji',
'click .toggle-clear': 'clearMessages', 'click .toggle-clear': 'clearMessages',
...@@ -636,13 +636,10 @@ ...@@ -636,13 +636,10 @@
return this; return this;
}, },
keyPressed (ev) { onFormSubmitted (ev) {
/* Event handler for when a key is pressed in a chat box textarea.
*/
if (ev.keyCode === KEY.ENTER) {
ev.preventDefault(); ev.preventDefault();
const textarea = ev.target; const textarea = this.el.querySelector('.chat-textarea'),
const message = textarea.value; message = textarea.value;
textarea.value = ''; textarea.value = '';
textarea.focus(); textarea.focus();
if (message !== '') { if (message !== '') {
...@@ -650,6 +647,13 @@ ...@@ -650,6 +647,13 @@
_converse.emit('messageSend', message); _converse.emit('messageSend', message);
} }
this.setChatState(_converse.ACTIVE); this.setChatState(_converse.ACTIVE);
},
keyPressed (ev) {
/* Event handler for when a key is pressed in a chat box textarea.
*/
if (ev.keyCode === KEY.ENTER) {
this.onFormSubmitted(ev);
} else { } else {
// Set chat state to composing if keyCode is not a forward-slash // Set chat state to composing if keyCode is not a forward-slash
// (which would imply an internal command and not a message). // (which would imply an internal command and not a message).
...@@ -657,22 +661,6 @@ ...@@ -657,22 +661,6 @@
} }
}, },
onSendButtonClicked(ev) {
/* Event handler for when a send button is clicked in a chat box textarea.
*/
ev.preventDefault();
const textarea = this.el.querySelector('.chat-textarea'),
message = textarea.value;
textarea.value = '';
textarea.focus();
if (message !== '') {
this.onMessageSubmitted(message);
_converse.emit('messageSend', message);
}
this.setChatState(_converse.ACTIVE);
},
clearMessages (ev) { clearMessages (ev) {
if (ev && ev.preventDefault) { ev.preventDefault(); } if (ev && ev.preventDefault) { ev.preventDefault(); }
const result = confirm(__("Are you sure you want to clear the messages from this chat box?")); const result = confirm(__("Are you sure you want to clear the messages from this chat box?"));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment