message_edit_history: Move click handlers to message_edit_history.js.

This commit is contained in:
Ganesh Pawar 2021-06-16 12:50:53 +05:30 committed by Tim Abbott
parent 72b1d3b5a6
commit e73644593c
2 changed files with 31 additions and 29 deletions

View File

@ -21,7 +21,6 @@ import * as hash_util from "./hash_util";
import * as hotspots from "./hotspots";
import {$t} from "./i18n";
import * as message_edit from "./message_edit";
import * as message_edit_history from "./message_edit_history";
import * as message_flags from "./message_flags";
import * as message_lists from "./message_lists";
import * as message_store from "./message_store";
@ -29,7 +28,6 @@ import * as muting_ui from "./muting_ui";
import * as narrow from "./narrow";
import * as notifications from "./notifications";
import * as overlays from "./overlays";
import {page_params} from "./page_params";
import * as popovers from "./popovers";
import * as reactions from "./reactions";
import * as recent_topics_ui from "./recent_topics_ui";
@ -216,33 +214,6 @@ export function initialize() {
$(".tooltip").remove();
});
$("body").on("mouseenter", ".message_edit_notice", (e) => {
if (page_params.realm_allow_edit_history) {
$(e.currentTarget).addClass("message_edit_notice_hover");
}
});
$("body").on("mouseleave", ".message_edit_notice", (e) => {
if (page_params.realm_allow_edit_history) {
$(e.currentTarget).removeClass("message_edit_notice_hover");
}
});
$("body").on("click", ".message_edit_notice", (e) => {
popovers.hide_all();
const message_id = rows.id($(e.currentTarget).closest(".message_row"));
const row = message_lists.current.get_row(message_id);
const message = message_lists.current.get(rows.id(row));
const message_history_cancel_btn = $("#message-history-cancel");
if (page_params.realm_allow_edit_history) {
message_edit_history.show_history(message);
message_history_cancel_btn.trigger("focus");
}
e.stopPropagation();
e.preventDefault();
});
$("body").on("click", ".reveal_hidden_message", (e) => {
// Hide actions popover to keep its options
// in sync with revealed/hidden state of

View File

@ -6,8 +6,12 @@ import render_message_history from "../templates/message_history.hbs";
import * as channel from "./channel";
import {$t_html} from "./i18n";
import * as message_lists from "./message_lists";
import * as overlays from "./overlays";
import {page_params} from "./page_params";
import * as people from "./people";
import * as popovers from "./popovers";
import * as rows from "./rows";
import * as timerender from "./timerender";
import * as ui_report from "./ui_report";
@ -81,6 +85,33 @@ export function show_history(message) {
}
export function initialize() {
$("body").on("mouseenter", ".message_edit_notice", (e) => {
if (page_params.realm_allow_edit_history) {
$(e.currentTarget).addClass("message_edit_notice_hover");
}
});
$("body").on("mouseleave", ".message_edit_notice", (e) => {
if (page_params.realm_allow_edit_history) {
$(e.currentTarget).removeClass("message_edit_notice_hover");
}
});
$("body").on("click", ".message_edit_notice", (e) => {
popovers.hide_all();
const message_id = rows.id($(e.currentTarget).closest(".message_row"));
const row = message_lists.current.get_row(message_id);
const message = message_lists.current.get(rows.id(row));
const message_history_cancel_btn = $("#message-history-cancel");
if (page_params.realm_allow_edit_history) {
show_history(message);
message_history_cancel_btn.trigger("focus");
}
e.stopPropagation();
e.preventDefault();
});
// TODO: Migrate this modal to be rendered when
// opened rather than once at startup.
const rendered_message_history = render_message_history();