click_handlers: Export convert_enter_to_click from ui_util.

This allows us to use this function in other places without
importing click_handlers which depends on a lot of other modules.
This commit is contained in:
Aman Agrawal 2021-03-31 03:36:08 +00:00 committed by Tim Abbott
parent 5e83965e80
commit 4593ca9ed7
2 changed files with 13 additions and 13 deletions

View File

@ -45,14 +45,6 @@ import * as unread_ops from "./unread_ops";
import * as user_status_ui from "./user_status_ui"; import * as user_status_ui from "./user_status_ui";
import * as util from "./util"; import * as util from "./util";
function convert_enter_to_click(e) {
const key = e.which;
if (key === 13) {
// Enter
$(e.currentTarget).trigger("click");
}
}
export function initialize() { export function initialize() {
// MESSAGE CLICKING // MESSAGE CLICKING
@ -426,7 +418,7 @@ export function initialize() {
// RECENT TOPICS // RECENT TOPICS
$("body").on("keydown", ".on_hover_topic_mute", convert_enter_to_click); $("body").on("keydown", ".on_hover_topic_mute", ui_util.convert_enter_to_click);
$("body").on("click", "#recent_topics_table .on_hover_topic_unmute", (e) => { $("body").on("click", "#recent_topics_table .on_hover_topic_unmute", (e) => {
e.stopPropagation(); e.stopPropagation();
@ -436,7 +428,7 @@ export function initialize() {
muting_ui.unmute_topic(stream_id, topic); muting_ui.unmute_topic(stream_id, topic);
}); });
$("body").on("keydown", ".on_hover_topic_unmute", convert_enter_to_click); $("body").on("keydown", ".on_hover_topic_unmute", ui_util.convert_enter_to_click);
$("body").on("click", "#recent_topics_table .on_hover_topic_mute", (e) => { $("body").on("click", "#recent_topics_table .on_hover_topic_mute", (e) => {
e.stopPropagation(); e.stopPropagation();
@ -458,7 +450,7 @@ export function initialize() {
unread_ops.mark_topic_as_read(stream_id, topic); unread_ops.mark_topic_as_read(stream_id, topic);
}); });
$("body").on("keydown", ".on_hover_topic_read", convert_enter_to_click); $("body").on("keydown", ".on_hover_topic_read", ui_util.convert_enter_to_click);
$("body").on("click", ".btn-recent-filters", (e) => { $("body").on("click", ".btn-recent-filters", (e) => {
e.stopPropagation(); e.stopPropagation();
@ -658,7 +650,7 @@ export function initialize() {
// COMPOSE // COMPOSE
// Allow inserting GIFs in compose box using enter keypress. // Allow inserting GIFs in compose box using enter keypress.
$("body").on("keydown", ".giphy-gif", convert_enter_to_click); $("body").on("keydown", ".giphy-gif", ui_util.convert_enter_to_click);
$("#compose_giphy_logo").on("click", (e) => { $("#compose_giphy_logo").on("click", (e) => {
e.preventDefault(); e.preventDefault();
@ -698,7 +690,7 @@ export function initialize() {
$("#giphy-search-query").trigger("focus"); $("#giphy-search-query").trigger("focus");
}); });
$("body").on("keydown", "#compose_giphy_logo", convert_enter_to_click); $("body").on("keydown", "#compose_giphy_logo", ui_util.convert_enter_to_click);
// NB: This just binds to current elements, and won't bind to elements // NB: This just binds to current elements, and won't bind to elements
// created after ready() is called. // created after ready() is called.

View File

@ -30,3 +30,11 @@ export function blur_active_element() {
// this blurs anything that may perhaps be actively focused on. // this blurs anything that may perhaps be actively focused on.
document.activeElement.blur(); document.activeElement.blur();
} }
export function convert_enter_to_click(e) {
const key = e.which;
if (key === 13) {
// Enter
$(e.currentTarget).trigger("click");
}
}