Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
tooltips: Change compose-send-button tooltip dynamically.
Hardik Dharmaniab70df5f44f2
diff --git a/web/src/tippyjs.js b/web/src/tippyjs.jsindex d307da07590..d04f922c14a 100644--- a/web/src/tippyjs.js+++ b/web/src/tippyjs.js@@ -14,6 +14,7 @@ import * as reactions from "./reactions";import * as rows from "./rows";import * as timerender from "./timerender";import {parse_html} from "./ui_util";+import {user_settings} from "./user_settings";// For tooltips without data-tippy-content, we use the HTML content of// a <template> whose id is given by data-tooltip-template-id.@@ -63,13 +64,19 @@ function hide_tooltip_if_reference_removed(observer.observe(target_node, config);}-// We use two delay settings for tooltips. The default "instant"+// We use three delay settings for tooltips. The default "instant"// version has just a tiny bit of delay to create a natural feeling// transition, while the "long" version is intended for elements where// we want to avoid distracting the user with the tooltip// unnecessarily.const INSTANT_HOVER_DELAY = [100, 20];const LONG_HOVER_DELAY = [750, 20];+// EXTRA_LONG_HOVER_DELAY is for elements like the compose box send+// button where the tooltip content is almost exactly the same as the+// text in the button, and the tooltip exists just to advertise a+// keyboard shortcut. For these tooltips, it's very important to avoid+// distracting users unnecessarily.+const EXTRA_LONG_HOVER_DELAY = [1500, 20];// We override the defaults set by tippy library here,// so make sure to check this too after checking tippyjs@@ -163,6 +170,19 @@ export function initialize() {appendTo: () => document.body,});+ delegate("body", {+ target: "#compose-send-button",+ delay: EXTRA_LONG_HOVER_DELAY,+ appendTo: () => document.body,+ onShow(instance) {+ if (user_settings.enter_sends) {+ instance.setContent(parse_html($("#send-enter-tooltip-template").html()));+ } else {+ instance.setContent(parse_html($("#send-ctrl-enter-tooltip-template").html()));+ }+ },+ });+delegate("body", {target: ".message_control_button",// This ensures that the tooltip doesn'tdiff --git a/web/templates/compose.hbs b/web/templates/compose.hbsindex 56f9448b646..18eb6a389d3 100644--- a/web/templates/compose.hbs+++ b/web/templates/compose.hbs@@ -108,7 +108,7 @@<div id="below-compose-content"><div class="compose_bottom_top_container"><div class="compose_right_float_container order-3">- <button type="submit" id="compose-send-button" class="button small send_message animated-purple-button" title="{{t 'Send' }} (Ctrl + Enter)" tabindex=0>+ <button type="submit" id="compose-send-button" class="button small send_message animated-purple-button"><img class="loader" alt="" src="" /><span>{{t 'Send' }}</span></button>@@ -118,6 +118,14 @@<button class="animated-purple-button message-control-button" id="send_later" tabindex=0 type="button" data-tippy-content="{{t 'Send later' }}"><i class="fa fa-chevron-up"></i></button>+ <template id="send-enter-tooltip-template">+ {{t 'Send' }}+ {{tooltip_hotkey_hints "Enter"}}+ </template>+ <template id="send-ctrl-enter-tooltip-template">+ {{t 'Send' }}+ {{tooltip_hotkey_hints "Ctrl" "Enter"}}+ </template></div>{{> compose_control_buttons }}</div>