diff --git a/static/js/tippyjs.js b/static/js/tippyjs.js index 209fde98f0..8eda03287a 100644 --- a/static/js/tippyjs.js +++ b/static/js/tippyjs.js @@ -169,20 +169,8 @@ export function initialize() { onShow(instance) { // Handle dynamic "starred messages" and "edit" widgets. const $elem = $(instance.reference); - let content = $elem.attr("data-tippy-content"); - if (content === undefined) { - // Tippy cannot get the content for message edit button - // as it is dynamically inserted based on editability. - // So, we have to manually get the i element to get the - // content from it. - // - // TODO: Change the template structure so logic is unnecessary. - const $edit_button = $elem.find("i.edit_message_button"); - content = $edit_button.attr("data-tippy-content"); - } - - instance.setContent(content); - return true; + const $template = $("#" + $elem.attr("data-tooltip-template-id")); + instance.setContent(parse_html($template.html())); }, }); diff --git a/static/js/ui.js b/static/js/ui.js index 45af5454f7..ae7d8cec30 100644 --- a/static/js/ui.js +++ b/static/js/ui.js @@ -1,7 +1,6 @@ import $ from "jquery"; import SimpleBar from "simplebar"; -import {$t} from "./i18n"; import * as message_lists from "./message_lists"; // What, if anything, obscures the home tab? @@ -74,14 +73,10 @@ export function update_starred_view(message_id, new_value) { $elt.removeClass("fa-star").addClass("fa-star-o"); $star_container.addClass("empty-star"); } - const title_state = starred ? $t({defaultMessage: "Unstar"}) : $t({defaultMessage: "Star"}); - $star_container.attr( - "data-tippy-content", - $t( - {defaultMessage: "{starred_status} this message (Ctrl + s)"}, - {starred_status: title_state}, - ), - ); + const data_template_id = starred + ? "unstar-message-tooltip-template" + : "star-message-tooltip-template"; + $star_container.attr("data-tooltip-template-id", data_template_id); }); } diff --git a/static/js/ui_init.js b/static/js/ui_init.js index 5ab5e7793a..36a27899e8 100644 --- a/static/js/ui_init.js +++ b/static/js/ui_init.js @@ -151,7 +151,16 @@ function message_hover($message_row) { can_move_message, msg_id: id, }; - $message_row.find(".edit_content").html(render_edit_content_button(args)); + const $edit_content = $message_row.find(".edit_content"); + $edit_content.html(render_edit_content_button(args)); + + let data_template_id = "view-source-tooltip-template"; + if (args.is_content_editable) { + data_template_id = "edit-content-tooltip-template"; + } else if (args.can_move_message) { + data_template_id = "move-message-tooltip-template"; + } + $edit_content.attr("data-tooltip-template-id", data_template_id); } function initialize_bottom_whitespace() { diff --git a/static/templates/edit_content_button.hbs b/static/templates/edit_content_button.hbs index 3a9af4556b..d449408536 100644 --- a/static/templates/edit_content_button.hbs +++ b/static/templates/edit_content_button.hbs @@ -1,7 +1,7 @@ {{#if is_content_editable}} - + {{else if can_move_message}} - + {{else}} - + {{/if}} diff --git a/static/templates/message_controls.hbs b/static/templates/message_controls.hbs index 6af17e288d..0b85125b9f 100644 --- a/static/templates/message_controls.hbs +++ b/static/templates/message_controls.hbs @@ -1,18 +1,38 @@
{{#if msg/sent_by_me}} -
+
+ + + {{/if}} {{#unless msg/sent_by_me}} -
+
+ {{/unless}} {{#unless msg/locally_echoed}} -
+
+ {{/unless}}
@@ -26,9 +46,17 @@
{{#unless msg/locally_echoed}} -
+
+ + {{/unless}}