Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

popovers: Move scroll handler to popover_menus module.

Tim Abbott573c77a9ebac
diff --git a/web/src/click_handlers.js b/web/src/click_handlers.js
index 918991d83e5..aa3fe370dc4 100644
--- a/web/src/click_handlers.js
+++ b/web/src/click_handlers.js
@@ -669,7 +669,6 @@ export function initialize() {
});
}
- popovers.register_click_handlers();
user_profile.register_click_handlers();
stream_popover.register_click_handlers();
diff --git a/web/src/message_viewport.js b/web/src/message_viewport.js
index f3a11186bbc..e5dce5930ac 100644
--- a/web/src/message_viewport.js
+++ b/web/src/message_viewport.js
@@ -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();
}
}
diff --git a/web/src/popover_menus.js b/web/src/popover_menus.js
index 58ec00ed510..2a9d26ca969 100644
--- a/web/src/popover_menus.js
+++ b/web/src/popover_menus.js
@@ -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;
+ });
}
diff --git a/web/src/popovers.js b/web/src/popovers.js
index d5ad086e4b0..8868c08c2d8 100644
--- a/web/src/popovers.js
+++ b/web/src/popovers.js
@@ -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.
diff --git a/web/src/resize.js b/web/src/resize.js
index 8ac0d944009..cdc73665b65 100644
--- a/web/src/resize.js
+++ b/web/src/resize.js
@@ -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();