mirror of https://github.com/zulip/zulip.git
overlays: Fix dependency cycle between popover.js and overlays.js.
This is a Prep PR for #24426. Removes direct dependency cycle between 'popover.js' and overlays.js by creating popover.initialize method called from 'ui_init.js' that calls overlays.register_pre_open_hook(hide_all) and overlays.register_pre_close_hook(hide_all). Created a function call_hook that loop call all registered hooks at the start of 'open_overlay' and 'close_overlay'.
This commit is contained in:
parent
3bfbfb014a
commit
570c9e260b
|
@ -3,18 +3,34 @@ import Micromodal from "micromodal";
|
|||
|
||||
import * as blueslip from "./blueslip";
|
||||
import * as browser_history from "./browser_history";
|
||||
import * as popovers from "./popovers";
|
||||
|
||||
let $active_overlay;
|
||||
let close_handler;
|
||||
let open_overlay_name;
|
||||
|
||||
const pre_open_hooks = [];
|
||||
const pre_close_hooks = [];
|
||||
|
||||
function reset_state() {
|
||||
$active_overlay = undefined;
|
||||
close_handler = undefined;
|
||||
open_overlay_name = undefined;
|
||||
}
|
||||
|
||||
export function register_pre_open_hook(func) {
|
||||
pre_open_hooks.push(func);
|
||||
}
|
||||
|
||||
export function register_pre_close_hook(func) {
|
||||
pre_close_hooks.push(func);
|
||||
}
|
||||
|
||||
function call_hooks(func_list) {
|
||||
for (const element of func_list) {
|
||||
element();
|
||||
}
|
||||
}
|
||||
|
||||
export function is_active() {
|
||||
return Boolean(open_overlay_name);
|
||||
}
|
||||
|
@ -62,7 +78,7 @@ export function active_modal() {
|
|||
}
|
||||
|
||||
export function open_overlay(opts) {
|
||||
popovers.hide_all();
|
||||
call_hooks(pre_open_hooks);
|
||||
|
||||
if (!opts.name || !opts.$overlay || !opts.on_close) {
|
||||
blueslip.error("Programming error in open_overlay");
|
||||
|
@ -210,7 +226,7 @@ export function open_modal(selector, conf = {}) {
|
|||
}
|
||||
|
||||
export function close_overlay(name) {
|
||||
popovers.hide_all();
|
||||
call_hooks(pre_close_hooks);
|
||||
|
||||
if (name !== open_overlay_name) {
|
||||
blueslip.error("Trying to close " + name + " when " + open_overlay_name + " is open.");
|
||||
|
|
|
@ -56,6 +56,11 @@ let userlist_placement = "right";
|
|||
|
||||
let list_of_popovers = [];
|
||||
|
||||
export function initialize() {
|
||||
overlays.register_pre_open_hook(hide_all);
|
||||
overlays.register_pre_close_hook(hide_all);
|
||||
}
|
||||
|
||||
export function clear_for_testing() {
|
||||
$current_message_info_popover_elem = undefined;
|
||||
$current_user_info_popover_elem = undefined;
|
||||
|
|
|
@ -62,6 +62,7 @@ import * as people from "./people";
|
|||
import * as pm_conversations from "./pm_conversations";
|
||||
import * as pm_list from "./pm_list";
|
||||
import * as popover_menus from "./popover_menus";
|
||||
import * as popovers from "./popovers";
|
||||
import * as presence from "./presence";
|
||||
import * as realm_logo from "./realm_logo";
|
||||
import * as realm_playground from "./realm_playground";
|
||||
|
@ -578,6 +579,7 @@ export function initialize_everything() {
|
|||
|
||||
i18n.initialize(i18n_params);
|
||||
tippyjs.initialize();
|
||||
popovers.initialize();
|
||||
popover_menus.initialize();
|
||||
|
||||
initialize_user_settings(user_settings_params);
|
||||
|
|
Loading…
Reference in New Issue