2023-06-07 14:18:18 +02:00
|
|
|
import $ from "jquery";
|
|
|
|
import _ from "lodash";
|
2024-04-06 11:55:37 +02:00
|
|
|
import assert from "minimalistic-assert";
|
2023-06-07 14:18:18 +02:00
|
|
|
import {delegate} from "tippy.js";
|
|
|
|
|
2024-02-07 08:14:58 +01:00
|
|
|
import render_drafts_tooltip from "../templates/drafts_tooltip.hbs";
|
2023-06-07 14:18:18 +02:00
|
|
|
import render_narrow_to_compose_recipients_tooltip from "../templates/narrow_to_compose_recipients_tooltip.hbs";
|
|
|
|
|
|
|
|
import * as compose_recipient from "./compose_recipient";
|
|
|
|
import * as compose_state from "./compose_state";
|
2023-11-10 21:00:25 +01:00
|
|
|
import * as compose_validate from "./compose_validate";
|
2023-06-07 14:18:18 +02:00
|
|
|
import {$t} from "./i18n";
|
|
|
|
import * as narrow_state from "./narrow_state";
|
2023-11-14 17:54:10 +01:00
|
|
|
import * as popover_menus from "./popover_menus";
|
2023-11-25 08:03:08 +01:00
|
|
|
import {EXTRA_LONG_HOVER_DELAY, INSTANT_HOVER_DELAY, LONG_HOVER_DELAY} from "./tippyjs";
|
2023-06-07 14:18:18 +02:00
|
|
|
import {parse_html} from "./ui_util";
|
|
|
|
import {user_settings} from "./user_settings";
|
|
|
|
|
2024-04-06 11:55:37 +02:00
|
|
|
export function initialize(): void {
|
2023-06-07 14:18:18 +02:00
|
|
|
delegate("body", {
|
|
|
|
target: [
|
|
|
|
// Ideally this would be `#compose_buttons .button`, but the
|
|
|
|
// reply button's actual area is its containing span.
|
|
|
|
"#left_bar_compose_mobile_button_big",
|
2023-10-04 21:06:27 +02:00
|
|
|
"#new_direct_message_button",
|
2024-04-06 11:55:37 +02:00
|
|
|
].join(","),
|
2023-06-07 14:18:18 +02:00
|
|
|
delay: EXTRA_LONG_HOVER_DELAY,
|
2023-11-03 15:52:16 +01:00
|
|
|
// Only show on mouseenter since for spectators, clicking on these
|
|
|
|
// buttons opens login modal, and Micromodal returns focus to the
|
|
|
|
// trigger after it closes, which results in tooltip being displayed.
|
|
|
|
trigger: "mouseenter",
|
2023-06-07 14:18:18 +02:00
|
|
|
appendTo: () => document.body,
|
|
|
|
onHidden(instance) {
|
2024-04-09 07:56:36 +02:00
|
|
|
instance.destroy();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
delegate("body", {
|
|
|
|
target: "#compose_buttons .compose-reply-button-wrapper",
|
|
|
|
delay: EXTRA_LONG_HOVER_DELAY,
|
|
|
|
// Only show on mouseenter since for spectators, clicking on these
|
|
|
|
// buttons opens login modal, and Micromodal returns focus to the
|
|
|
|
// trigger after it closes, which results in tooltip being displayed.
|
|
|
|
trigger: "mouseenter",
|
|
|
|
appendTo: () => document.body,
|
|
|
|
onShow(instance) {
|
|
|
|
const $elem = $(instance.reference);
|
|
|
|
const button_type = $elem.attr("data-reply-button-type");
|
|
|
|
switch (button_type) {
|
|
|
|
case "direct_disabled": {
|
|
|
|
instance.setContent(
|
|
|
|
parse_html(
|
|
|
|
$("#compose_reply_direct_disabled_button_tooltip_template").html(),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case "selected_message": {
|
|
|
|
instance.setContent(
|
|
|
|
parse_html($("#compose_reply_message_button_tooltip_template").html()),
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case "selected_conversation": {
|
|
|
|
instance.setContent(
|
|
|
|
parse_html(
|
|
|
|
$("#compose_reply_selected_topic_button_tooltip_template").html(),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
instance.setContent(
|
|
|
|
parse_html($("#compose_reply_message_button_tooltip_template").html()),
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onHidden(instance) {
|
2023-06-07 14:18:18 +02:00
|
|
|
instance.destroy();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2023-12-16 03:32:31 +01:00
|
|
|
delegate("body", {
|
|
|
|
target: "#new_conversation_button",
|
|
|
|
delay: EXTRA_LONG_HOVER_DELAY,
|
|
|
|
// Only show on mouseenter since for spectators, clicking on these
|
|
|
|
// buttons opens login modal, and Micromodal returns focus to the
|
|
|
|
// trigger after it closes, which results in tooltip being displayed.
|
|
|
|
trigger: "mouseenter",
|
|
|
|
appendTo: () => document.body,
|
|
|
|
onShow(instance) {
|
|
|
|
const $elem = $(instance.reference);
|
|
|
|
const conversation_type = $elem.attr("data-conversation-type");
|
|
|
|
if (conversation_type === "direct") {
|
|
|
|
instance.setContent(
|
|
|
|
parse_html($("#new_direct_message_button_tooltip_template").html()),
|
|
|
|
);
|
2024-04-06 11:55:37 +02:00
|
|
|
return undefined;
|
2023-12-16 03:32:31 +01:00
|
|
|
} else if (conversation_type === "stream") {
|
|
|
|
instance.setContent(
|
|
|
|
parse_html($("#new_topic_message_button_tooltip_template").html()),
|
|
|
|
);
|
2024-04-06 11:55:37 +02:00
|
|
|
return undefined;
|
2023-12-16 03:32:31 +01:00
|
|
|
}
|
|
|
|
// Use new_stream_message_button_tooltip_template when the
|
2024-02-25 21:54:42 +01:00
|
|
|
// conversation_type is equal to "non-specific" and also as a default fallback.
|
2023-12-16 03:32:31 +01:00
|
|
|
instance.setContent(
|
|
|
|
parse_html($("#new_stream_message_button_tooltip_template").html()),
|
|
|
|
);
|
2024-04-06 11:55:37 +02:00
|
|
|
return undefined;
|
2023-12-16 03:32:31 +01:00
|
|
|
},
|
|
|
|
onHidden(instance) {
|
|
|
|
instance.destroy();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2023-06-07 14:18:18 +02:00
|
|
|
delegate("body", {
|
2023-06-22 17:31:32 +02:00
|
|
|
// Only display Tippy content on classes accompanied by a `data-` attribute.
|
|
|
|
target: `
|
|
|
|
.compose_control_button[data-tooltip-template-id],
|
|
|
|
.compose_control_button[data-tippy-content],
|
|
|
|
.compose_control_button_container
|
|
|
|
`,
|
2023-06-07 14:18:18 +02:00
|
|
|
// Add some additional delay when they open
|
|
|
|
// so that regular users don't have to see
|
|
|
|
// them unless they want to.
|
|
|
|
delay: LONG_HOVER_DELAY,
|
|
|
|
// By default, tippyjs uses a trigger value of "mouseenter focus",
|
|
|
|
// which means the tooltips can appear either when the element is
|
|
|
|
// hovered over or when it receives focus (e.g. by being clicked).
|
|
|
|
// However, we only want the tooltips to appear on hover, not on click.
|
|
|
|
// Therefore, we need to remove the "focus" trigger from the buttons,
|
|
|
|
// so that the tooltips don't appear when the buttons are clicked.
|
|
|
|
trigger: "mouseenter",
|
|
|
|
// This ensures that the upload files tooltip
|
|
|
|
// doesn't hide behind the left sidebar.
|
|
|
|
appendTo: () => document.body,
|
2023-11-25 08:03:08 +01:00
|
|
|
// If the button is `.disabled-on-hover`, then we want to show the
|
|
|
|
// tooltip instantly, to make it clear to the user that the button
|
|
|
|
// is disabled, and why.
|
|
|
|
onTrigger(instance, event) {
|
2024-04-06 11:55:37 +02:00
|
|
|
assert(event.currentTarget instanceof HTMLElement);
|
2023-11-25 08:03:08 +01:00
|
|
|
if (event.currentTarget.classList.contains("disabled-on-hover")) {
|
|
|
|
instance.setProps({delay: INSTANT_HOVER_DELAY});
|
|
|
|
} else {
|
|
|
|
instance.setProps({delay: LONG_HOVER_DELAY});
|
|
|
|
}
|
|
|
|
},
|
2023-06-07 14:18:18 +02:00
|
|
|
});
|
|
|
|
|
2023-11-14 20:36:01 +01:00
|
|
|
delegate("body", {
|
|
|
|
target: ".send-control-button",
|
|
|
|
delay: LONG_HOVER_DELAY,
|
|
|
|
placement: "top",
|
2024-02-07 08:14:58 +01:00
|
|
|
onShow(instance) {
|
2023-11-14 17:54:10 +01:00
|
|
|
// Don't show send-area tooltips if the popover is displayed.
|
|
|
|
if (popover_menus.is_scheduled_messages_popover_displayed()) {
|
|
|
|
return false;
|
|
|
|
}
|
2024-02-07 08:14:58 +01:00
|
|
|
if (instance.reference.id === "compose-drafts-button") {
|
|
|
|
const count =
|
2024-04-06 11:55:37 +02:00
|
|
|
instance.reference.querySelector(".compose-drafts-count")!.textContent ?? 0;
|
2024-02-07 08:14:58 +01:00
|
|
|
// Explain that the number in brackets is the number of drafts for this conversation.
|
|
|
|
const draft_count_msg = $t(
|
|
|
|
{
|
|
|
|
defaultMessage:
|
|
|
|
"{count, plural, one {# draft} other {# drafts}} for this conversation",
|
|
|
|
},
|
|
|
|
{count},
|
|
|
|
);
|
|
|
|
instance.setContent(parse_html(render_drafts_tooltip({draft_count_msg})));
|
|
|
|
}
|
2024-04-06 11:55:37 +02:00
|
|
|
return undefined;
|
2023-11-14 17:54:10 +01:00
|
|
|
},
|
2023-11-14 20:36:01 +01:00
|
|
|
appendTo: () => document.body,
|
|
|
|
});
|
|
|
|
|
2023-06-07 14:18:18 +02:00
|
|
|
delegate("body", {
|
|
|
|
target: "#compose-send-button",
|
|
|
|
delay: EXTRA_LONG_HOVER_DELAY,
|
|
|
|
// By default, tippyjs uses a trigger value of "mouseenter focus",
|
|
|
|
// but by specifying "mouseenter", this will prevent showing the
|
|
|
|
// Send tooltip when tabbing to the Send button.
|
|
|
|
trigger: "mouseenter",
|
|
|
|
appendTo: () => document.body,
|
|
|
|
onShow(instance) {
|
2023-11-14 17:54:10 +01:00
|
|
|
// Don't show Send button tooltip if the popover is displayed.
|
|
|
|
if (popover_menus.is_scheduled_messages_popover_displayed()) {
|
|
|
|
return false;
|
|
|
|
}
|
2023-06-07 14:18:18 +02:00
|
|
|
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()));
|
|
|
|
}
|
2024-04-06 11:55:37 +02:00
|
|
|
return undefined;
|
2023-06-07 14:18:18 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
delegate("body", {
|
|
|
|
target: ".narrow_to_compose_recipients",
|
|
|
|
delay: LONG_HOVER_DELAY,
|
|
|
|
appendTo: () => document.body,
|
|
|
|
content() {
|
|
|
|
const narrow_filter = narrow_state.filter();
|
|
|
|
let display_current_view;
|
|
|
|
if (narrow_state.is_message_feed_visible()) {
|
2024-04-21 05:31:35 +02:00
|
|
|
assert(narrow_filter !== undefined);
|
|
|
|
if (narrow_filter.is_in_home()) {
|
2024-04-02 13:10:48 +02:00
|
|
|
display_current_view = $t({
|
|
|
|
defaultMessage: "Currently viewing your combined feed.",
|
|
|
|
});
|
2023-06-07 14:18:18 +02:00
|
|
|
} else if (
|
2024-04-05 19:41:15 +02:00
|
|
|
_.isEqual(narrow_filter.sorted_term_types(), ["channel"]) &&
|
2023-06-07 14:18:18 +02:00
|
|
|
compose_state.get_message_type() === "stream" &&
|
2024-04-05 19:41:15 +02:00
|
|
|
narrow_filter.operands("channel")[0] === compose_state.stream_name()
|
2023-06-07 14:18:18 +02:00
|
|
|
) {
|
|
|
|
display_current_view = $t({
|
2024-04-18 15:20:36 +02:00
|
|
|
defaultMessage: "Currently viewing the entire channel.",
|
2023-06-07 14:18:18 +02:00
|
|
|
});
|
|
|
|
} else if (
|
|
|
|
_.isEqual(narrow_filter.sorted_term_types(), ["is-dm"]) &&
|
|
|
|
compose_state.get_message_type() === "private"
|
|
|
|
) {
|
|
|
|
display_current_view = $t({
|
|
|
|
defaultMessage: "Currently viewing all direct messages.",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return parse_html(render_narrow_to_compose_recipients_tooltip({display_current_view}));
|
|
|
|
},
|
|
|
|
onHidden(instance) {
|
|
|
|
instance.destroy();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
delegate("body", {
|
2023-11-01 18:16:47 +01:00
|
|
|
// TODO: Might need to target just the Send button itself
|
|
|
|
// in the new design
|
2024-04-06 11:55:37 +02:00
|
|
|
target: ".disabled-message-send-controls",
|
2023-06-07 14:18:18 +02:00
|
|
|
maxWidth: 350,
|
2023-11-10 21:00:25 +01:00
|
|
|
content: () =>
|
|
|
|
compose_recipient.get_posting_policy_error_message() ||
|
|
|
|
compose_validate.get_disabled_send_tooltip(),
|
2023-06-07 14:18:18 +02:00
|
|
|
appendTo: () => document.body,
|
|
|
|
onHidden(instance) {
|
|
|
|
instance.destroy();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|