2021-06-19 02:25:13 +02:00
|
|
|
/* Module for popovers that have been ported to the modern
|
|
|
|
TippyJS/Popper popover library from the legacy Bootstrap
|
|
|
|
popovers system in popovers.js. */
|
|
|
|
|
2021-06-17 19:05:34 +02:00
|
|
|
import $ from "jquery";
|
|
|
|
import {delegate} from "tippy.js";
|
|
|
|
|
|
|
|
import render_left_sidebar_stream_setting_popover from "../templates/left_sidebar_stream_setting_popover.hbs";
|
|
|
|
import render_mobile_message_buttons_popover_content from "../templates/mobile_message_buttons_popover_content.hbs";
|
|
|
|
|
|
|
|
import * as compose_actions from "./compose_actions";
|
|
|
|
import * as narrow_state from "./narrow_state";
|
|
|
|
import * as popovers from "./popovers";
|
|
|
|
import * as settings_data from "./settings_data";
|
|
|
|
|
|
|
|
let left_sidebar_stream_setting_popover_displayed = false;
|
|
|
|
let compose_mobile_button_popover_displayed = false;
|
|
|
|
|
2021-06-17 19:11:47 +02:00
|
|
|
const default_popover_props = {
|
|
|
|
delay: 0,
|
|
|
|
appendTo: () => document.body,
|
|
|
|
trigger: "click",
|
|
|
|
allowHTML: true,
|
|
|
|
interactive: true,
|
|
|
|
hideOnClick: true,
|
2021-06-19 02:25:13 +02:00
|
|
|
/* The light-border TippyJS theme is a bit of a misnomer; it
|
|
|
|
is a popover styling similar to Bootstrap. We've also customized
|
|
|
|
its CSS to support Zulip's night theme. */
|
2021-06-17 19:11:47 +02:00
|
|
|
theme: "light-border",
|
|
|
|
touch: true,
|
|
|
|
};
|
|
|
|
|
2021-11-10 14:27:27 +01:00
|
|
|
export function any_active() {
|
|
|
|
return left_sidebar_stream_setting_popover_displayed || compose_mobile_button_popover_displayed;
|
2021-06-17 19:05:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function initialize() {
|
|
|
|
delegate("body", {
|
2021-06-17 19:11:47 +02:00
|
|
|
...default_popover_props,
|
2021-06-17 19:05:34 +02:00
|
|
|
target: "#streams_inline_cog",
|
|
|
|
onShow(instance) {
|
|
|
|
popovers.hide_all_except_sidebars(instance);
|
|
|
|
instance.setContent(
|
|
|
|
render_left_sidebar_stream_setting_popover({
|
2021-03-27 05:48:37 +01:00
|
|
|
can_create_streams:
|
|
|
|
settings_data.user_can_create_private_streams() ||
|
|
|
|
settings_data.user_can_create_public_streams(),
|
2021-06-17 19:05:34 +02:00
|
|
|
}),
|
|
|
|
);
|
|
|
|
left_sidebar_stream_setting_popover_displayed = true;
|
|
|
|
$(instance.popper).one("click", instance.hide);
|
|
|
|
},
|
|
|
|
onHidden() {
|
|
|
|
left_sidebar_stream_setting_popover_displayed = false;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
// compose box buttons popover shown on mobile widths.
|
|
|
|
delegate("body", {
|
2021-06-17 19:11:47 +02:00
|
|
|
...default_popover_props,
|
2021-06-17 19:05:34 +02:00
|
|
|
target: ".compose_mobile_button",
|
|
|
|
placement: "top",
|
|
|
|
onShow(instance) {
|
|
|
|
popovers.hide_all_except_sidebars(instance);
|
|
|
|
instance.setContent(
|
|
|
|
render_mobile_message_buttons_popover_content({
|
|
|
|
is_in_private_narrow: narrow_state.narrowed_to_pms(),
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
compose_mobile_button_popover_displayed = true;
|
|
|
|
|
|
|
|
const $popper = $(instance.popper);
|
|
|
|
$popper.one("click", instance.hide);
|
|
|
|
$popper.one("click", ".compose_mobile_stream_button", () => {
|
|
|
|
compose_actions.start("stream", {trigger: "new topic button"});
|
|
|
|
});
|
|
|
|
$popper.one("click", ".compose_mobile_private_button", () => {
|
|
|
|
compose_actions.start("private");
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onHidden(instance) {
|
|
|
|
// Destroy instance so that event handlers
|
|
|
|
// are destroyed too.
|
|
|
|
instance.destroy();
|
|
|
|
compose_mobile_button_popover_displayed = false;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|