compose: Extract compose.toggle_entry_sends_ui function.

This commit extracts the code for hiding and showing the
send button according to 'enter_sends' setting value in
a separate function.
This commit is contained in:
Sahil Batra
2021-07-27 13:12:31 +05:30
committed by Tim Abbott
parent 7af789c48f
commit dafd32bd09
3 changed files with 11 additions and 8 deletions

View File

@@ -1096,8 +1096,7 @@ test("initialize", ({override, mock_template}) => {
// select_on_focus()
$("#compose-send-button").fadeOut = noop;
$("#compose-send-button").fadeIn = noop;
override(compose, "toggle_enter_sends_ui", noop);
let channel_patch_called = false;
override(channel, "patch", (params) => {
assert.equal(params.url, "/json/settings");

View File

@@ -124,6 +124,15 @@ export function empty_topic_placeholder() {
return $t({defaultMessage: "(no topic)"});
}
export function toggle_enter_sends_ui() {
const send_button = $("#compose-send-button");
if (page_params.enter_sends) {
send_button.fadeOut();
} else {
send_button.fadeIn();
}
}
export function create_message_object() {
// Topics are optional, and we provide a placeholder if one isn't given.
let topic = compose_state.topic();

View File

@@ -1085,13 +1085,8 @@ export function initialize() {
$("form#send_message_form").on("keyup", handle_keyup);
$("#enter_sends").on("click", () => {
const send_button = $("#compose-send-button");
page_params.enter_sends = $("#enter_sends").is(":checked");
if (page_params.enter_sends) {
send_button.fadeOut();
} else {
send_button.fadeIn();
}
compose.toggle_enter_sends_ui();
// Refocus in the content box so you can continue typing or
// press Enter to send.