popovers: Move scroll handler to popover_menus module.

Part of cleaning out the original legacy popovers system.
This commit is contained in:
Tim Abbott 2023-09-24 21:54:14 -07:00
parent eb26dc6ecd
commit 573c77a9eb
5 changed files with 36 additions and 40 deletions

View File

@ -669,7 +669,6 @@ export function initialize() {
});
}
popovers.register_click_handlers();
user_profile.register_click_handlers();
stream_popover.register_click_handlers();

View File

@ -3,7 +3,7 @@ import $ from "jquery";
import * as blueslip from "./blueslip";
import * as message_lists from "./message_lists";
import * as message_scroll from "./message_scroll";
import * as popovers from "./popovers";
import * as popover_menus from "./popover_menus";
import * as rows from "./rows";
import * as util from "./util";
@ -403,7 +403,7 @@ export function maybe_scroll_to_show_message_top() {
const message_height = $selected_message.outerHeight(true) ?? 0;
if (message_top < viewport_info.visible_top) {
set_message_position(message_top, message_height, viewport_info, 0);
popovers.set_suppress_scroll_hide();
popover_menus.set_suppress_scroll_hide();
}
}

View File

@ -58,6 +58,17 @@ import * as user_topics from "./user_topics";
let message_actions_popover_keyboard_toggle = false;
let selected_send_later_timestamp;
// On mobile web, opening the keyboard can trigger a resize event
// (which in turn can trigger a scroll event). This will have the
// side effect of closing popovers, which we don't want. So we
// suppress the first hide from scrolling after a resize using this
// variable.
let suppress_scroll_hide = false;
export function set_suppress_scroll_hide() {
suppress_scroll_hide = true;
}
const popover_instances = {
compose_control_buttons: null,
starred_messages: null,
@ -1112,4 +1123,25 @@ export function initialize() {
popover_instances.send_later = undefined;
},
});
let last_scroll = 0;
$(document).on("scroll", () => {
if (suppress_scroll_hide) {
suppress_scroll_hide = false;
return;
}
const date = Date.now();
// only run `popovers.hide_all()` if the last scroll was more
// than 250ms ago.
if (date - last_scroll > 250) {
popovers.hide_all();
}
// update the scroll time on every event to make sure it doesn't
// retrigger `hide_all` while still scrolling.
last_scroll = date;
});
}

View File

@ -28,42 +28,6 @@ $.fn.popover = Object.assign(function (...args) {
}
}, old_popover);
// On mobile web, opening the keyboard can trigger a resize event
// (which in turn can trigger a scroll event). This will have the
// side effect of closing popovers, which we don't want. So we
// suppress the first hide from scrolling after a resize using this
// variable.
let suppress_scroll_hide = false;
export function set_suppress_scroll_hide() {
suppress_scroll_hide = true;
}
export function register_click_handlers() {
{
let last_scroll = 0;
$(document).on("scroll", () => {
if (suppress_scroll_hide) {
suppress_scroll_hide = false;
return;
}
const date = Date.now();
// only run `popovers.hide_all()` if the last scroll was more
// than 250ms ago.
if (date - last_scroll > 250) {
hide_all();
}
// update the scroll time on every event to make sure it doesn't
// retrigger `hide_all` while still scrolling.
last_scroll = date;
});
}
}
export function any_active() {
// True if any popover (that this module manages) is currently shown.
// Expanded sidebars on mobile view count as popovers as well.

View File

@ -9,6 +9,7 @@ import * as message_lists from "./message_lists";
import * as message_viewport from "./message_viewport";
import * as navbar_alerts from "./navbar_alerts";
import * as navigate from "./navigate";
import * as popover_menus from "./popover_menus";
import * as popovers from "./popovers";
import * as util from "./util";
@ -184,7 +185,7 @@ export function handler() {
// try to scroll to one.
if (message_lists.current.selected_id() !== -1) {
if (mobile) {
popovers.set_suppress_scroll_hide();
popover_menus.set_suppress_scroll_hide();
}
navigate.scroll_to_selected();