From ac8436d46c2dd1deb7a86c71ed9b19bed2064257 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Thu, 5 Oct 2023 08:54:50 -0700 Subject: [PATCH] resize: Move handler to new resize_handler module. Signed-off-by: Anders Kaseorg --- tools/test-js-with-node | 1 + web/src/resize.js | 44 ------------------------------------ web/src/resize_handler.js | 47 +++++++++++++++++++++++++++++++++++++++ web/src/ui_init.js | 6 ++--- 4 files changed, 51 insertions(+), 47 deletions(-) create mode 100644 web/src/resize_handler.js diff --git a/tools/test-js-with-node b/tools/test-js-with-node index edf762bfd6..2274a4d74e 100755 --- a/tools/test-js-with-node +++ b/tools/test-js-with-node @@ -163,6 +163,7 @@ EXEMPT_FILES = make_set( "web/src/reload.js", "web/src/reminder.js", "web/src/resize.js", + "web/src/resize_handler.js", "web/src/rows.js", "web/src/scheduled_messages.js", "web/src/scheduled_messages_overlay_ui.js", diff --git a/web/src/resize.js b/web/src/resize.js index be6c375548..42b0996e51 100644 --- a/web/src/resize.js +++ b/web/src/resize.js @@ -3,16 +3,8 @@ import $ from "jquery"; import * as blueslip from "./blueslip"; import * as compose_state from "./compose_state"; -import * as compose_ui from "./compose_ui"; -import * as condense from "./condense"; -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 sidebar_ui from "./sidebar_ui"; -import * as util from "./util"; function get_bottom_whitespace_height() { return message_viewport.height() * 0.4; @@ -157,39 +149,3 @@ export function resize_page_components() { const h = resize_sidebars(); resize_bottom_whitespace(h); } - -let _old_width = $(window).width(); - -export function handler() { - const new_width = $(window).width(); - - // On mobile web, we want to avoid hiding a popover here on height change, - // especially if this resize was triggered by a virtual keyboard - // popping up when the user opened that very popover. - const mobile = util.is_mobile(); - if (!mobile || new_width !== _old_width) { - sidebar_ui.hide_all(); - popovers.hide_all(); - } - - if (new_width !== _old_width) { - _old_width = new_width; - } - resize_page_components(); - compose_ui.autosize_textarea($("#compose-textarea")); - update_recent_view_filters_height(); - - // Re-compute and display/remove 'Show more' buttons to messages - condense.condense_and_collapse(message_lists.all_current_message_rows()); - - // This function might run onReady (if we're in a narrow window), - // but before we've loaded in the messages; in that case, don't - // try to scroll to one. - if (message_lists.current.selected_id() !== -1) { - if (mobile) { - popover_menus.set_suppress_scroll_hide(); - } - - navigate.scroll_to_selected(); - } -} diff --git a/web/src/resize_handler.js b/web/src/resize_handler.js new file mode 100644 index 0000000000..6f03754042 --- /dev/null +++ b/web/src/resize_handler.js @@ -0,0 +1,47 @@ +import $ from "jquery"; + +import * as compose_ui from "./compose_ui"; +import * as condense from "./condense"; +import * as message_lists from "./message_lists"; +import * as navigate from "./navigate"; +import * as popover_menus from "./popover_menus"; +import * as popovers from "./popovers"; +import * as resize from "./resize"; +import * as sidebar_ui from "./sidebar_ui"; +import * as util from "./util"; + +export let _old_width = $(window).width(); + +export function handler() { + const new_width = $(window).width(); + + // On mobile web, we want to avoid hiding a popover here on height change, + // especially if this resize was triggered by a virtual keyboard + // popping up when the user opened that very popover. + const mobile = util.is_mobile(); + if (!mobile || new_width !== _old_width) { + sidebar_ui.hide_all(); + popovers.hide_all(); + } + + if (new_width !== _old_width) { + _old_width = new_width; + } + resize.resize_page_components(); + compose_ui.autosize_textarea($("#compose-textarea")); + resize.update_recent_view_filters_height(); + + // Re-compute and display/remove 'Show more' buttons to messages + condense.condense_and_collapse(message_lists.all_current_message_rows()); + + // This function might run onReady (if we're in a narrow window), + // but before we've loaded in the messages; in that case, don't + // try to scroll to one. + if (message_lists.current.selected_id() !== -1) { + if (mobile) { + popover_menus.set_suppress_scroll_hide(); + } + + navigate.scroll_to_selected(); + } +} diff --git a/web/src/ui_init.js b/web/src/ui_init.js index 62c59c46e6..9e90ccef40 100644 --- a/web/src/ui_init.js +++ b/web/src/ui_init.js @@ -84,7 +84,7 @@ import * as realm_user_settings_defaults from "./realm_user_settings_defaults"; import * as recent_view_ui from "./recent_view_ui"; import * as reload from "./reload"; import * as rendered_markdown from "./rendered_markdown"; -import * as resize from "./resize"; +import * as resize_handler from "./resize_handler"; import * as scheduled_messages from "./scheduled_messages"; import * as scheduled_messages_overlay_ui from "./scheduled_messages_overlay_ui"; import * as scheduled_messages_popover from "./scheduled_messages_popover"; @@ -251,7 +251,7 @@ export function initialize_kitchen_sink_stuff() { // preventDefault, allowing the modal to scroll normally. }); - $(window).on("resize", _.throttle(resize.handler, 50)); + $(window).on("resize", _.throttle(resize_handler.handler, 50)); // Scrolling in overlays. input boxes, and other elements that // explicitly scroll should not scroll the main view. Stop @@ -285,7 +285,7 @@ export function initialize_kitchen_sink_stuff() { // A little hackish, because it doesn't seem to totally get us the // exact right width for the compose box, but, close enough for now. - resize.handler(); + resize_handler.handler(); if (page_params.is_spectator) { $("body").addClass("spectator-view");