2023-10-03 19:32:19 +02:00
|
|
|
import $ from "jquery";
|
2024-05-30 21:51:29 +02:00
|
|
|
import * as tippy from "tippy.js";
|
2023-10-03 19:32:19 +02:00
|
|
|
|
2023-10-05 06:31:40 +02:00
|
|
|
import render_compose_control_buttons_popover from "../templates/popovers/compose_control_buttons/compose_control_buttons_popover.hbs";
|
|
|
|
import render_mobile_message_buttons_popover from "../templates/popovers/mobile_message_buttons_popover.hbs";
|
2023-10-03 19:32:19 +02:00
|
|
|
|
|
|
|
import * as compose_actions from "./compose_actions";
|
|
|
|
import * as giphy from "./giphy";
|
|
|
|
import * as narrow_state from "./narrow_state";
|
|
|
|
import * as popover_menus from "./popover_menus";
|
|
|
|
import * as popovers from "./popovers";
|
|
|
|
import * as rows from "./rows";
|
|
|
|
import {parse_html} from "./ui_util";
|
|
|
|
|
|
|
|
export function initialize() {
|
|
|
|
// compose box buttons popover shown on mobile widths.
|
|
|
|
// We want this click event to propagate and hide other popovers
|
|
|
|
// that could possibly obstruct user from using this popover.
|
2024-05-30 21:51:29 +02:00
|
|
|
tippy.delegate("body", {
|
2023-10-03 19:32:19 +02:00
|
|
|
...popover_menus.default_popover_props,
|
|
|
|
// Attach the click event to `.mobile_button_container`, since
|
|
|
|
// the button (`.compose_mobile_button`) already has a hover
|
|
|
|
// action attached, for showing the keyboard shortcut,
|
|
|
|
// and Tippy cannot handle events that trigger two different
|
|
|
|
// actions
|
|
|
|
target: ".mobile_button_container",
|
|
|
|
placement: "top",
|
|
|
|
onShow(instance) {
|
|
|
|
popover_menus.popover_instances.compose_mobile_button = instance;
|
|
|
|
popover_menus.on_show_prep(instance);
|
|
|
|
instance.setContent(
|
|
|
|
parse_html(
|
2023-10-04 08:20:38 +02:00
|
|
|
render_mobile_message_buttons_popover({
|
2023-10-03 19:32:19 +02:00
|
|
|
is_in_private_narrow: narrow_state.narrowed_to_pms(),
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
onMount(instance) {
|
|
|
|
const $popper = $(instance.popper);
|
|
|
|
$popper.one("click", ".compose_mobile_stream_button", (e) => {
|
2024-04-04 02:38:16 +02:00
|
|
|
compose_actions.start({
|
2024-05-20 22:08:30 +02:00
|
|
|
message_type: "stream",
|
2024-04-04 02:38:16 +02:00
|
|
|
trigger: "clear topic button",
|
|
|
|
});
|
2023-10-03 19:32:19 +02:00
|
|
|
e.stopPropagation();
|
2024-04-02 09:29:56 +02:00
|
|
|
popover_menus.hide_current_popover_if_visible(instance);
|
2023-10-03 19:32:19 +02:00
|
|
|
});
|
2023-10-04 21:06:27 +02:00
|
|
|
$popper.one("click", ".compose_mobile_direct_message_button", (e) => {
|
2024-04-04 02:38:16 +02:00
|
|
|
compose_actions.start({
|
|
|
|
message_type: "private",
|
|
|
|
});
|
2023-10-03 19:32:19 +02:00
|
|
|
e.stopPropagation();
|
2024-04-02 09:29:56 +02:00
|
|
|
popover_menus.hide_current_popover_if_visible(instance);
|
2023-10-03 19:32:19 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
onHidden(instance) {
|
|
|
|
// Destroy instance so that event handlers
|
|
|
|
// are destroyed too.
|
|
|
|
instance.destroy();
|
|
|
|
popover_menus.popover_instances.compose_mobile_button = undefined;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
// Click event handlers for it are handled in `compose_ui` and
|
|
|
|
// we don't want to close this popover on click inside it but
|
|
|
|
// only if user clicked outside it.
|
|
|
|
popover_menus.register_popover_menu(".compose_control_menu_wrapper", {
|
|
|
|
placement: "top",
|
|
|
|
onShow(instance) {
|
|
|
|
const parent_row = rows.get_closest_row(instance.reference);
|
|
|
|
let preview_mode_on;
|
|
|
|
// If the popover is opened from a message edit form, we want to
|
|
|
|
// infer the preview mode from that row, else from the compose box.
|
|
|
|
if (parent_row.length) {
|
|
|
|
preview_mode_on = parent_row.hasClass("preview_mode");
|
|
|
|
} else {
|
|
|
|
preview_mode_on = $("#compose").hasClass("preview_mode");
|
|
|
|
}
|
|
|
|
instance.setContent(
|
|
|
|
parse_html(
|
|
|
|
render_compose_control_buttons_popover({
|
|
|
|
giphy_enabled: giphy.is_giphy_enabled(),
|
|
|
|
preview_mode_on,
|
2023-11-22 01:38:46 +01:00
|
|
|
inside_popover: true,
|
2023-10-03 19:32:19 +02:00
|
|
|
}),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
popover_menus.popover_instances.compose_control_buttons = instance;
|
|
|
|
popovers.hide_all();
|
|
|
|
},
|
|
|
|
onHidden(instance) {
|
|
|
|
instance.destroy();
|
|
|
|
popover_menus.popover_instances.compose_control_buttons = undefined;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|