Skip to content

Commit

Permalink
Allow for Ctrl+Enter for chat messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
JanWielemaker committed Mar 4, 2024
1 parent 3fc2c2d commit ca451b0
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions web/js/chatroom.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,20 @@ define([ "jquery", "form", "cm/lib/codemirror", "utils", "config",
$.el.tr($.el.td({class:"chat-text"}, text),
$.el.td({class:"chat-send"}, btn)))));

function enable_btn()
{ $(send).prop('disabled', $(text).val().trim() == "" ? true : false);
function enable_btn() {
$(send).prop('disabled', $(text).val().trim() == "" ? true : false);
}
enable_btn();

$(send).on("click", function() {
function send_chat() {
$(send).prop('disabled', true);
elem.chatroom('send');
$(text).val("");
});
}

$(send).on("click", send_chat);
$(text).on("change", enable_btn);

/* event handling */
form.widgets.populateMenu($(btn), elem, {
"Include my query": function() {
Expand All @@ -140,15 +143,14 @@ define([ "jquery", "form", "cm/lib/codemirror", "utils", "config",
$(close).on("click", function() {
elem.tile('close');
});
if ( options.oneline ) {
$(text).keypress(function(ev) {
if ( ev.which == 13 ) {
elem.chatroom('send');
ev.preventDefault();
return false;
}
});
} else {
$(text).keypress(function(ev) {
if ( ev.key == "Enter" &&
options.oneline || ev.ctrlKey || ev.metaKey ) {
send_chat();
return false;
}
});
if ( !options.oneline) {
$(text).on('keyup', function() {
var that = $(this);
var h;
Expand Down

0 comments on commit ca451b0

Please sign in to comment.