mirror of
https://github.com/zulip/zulip.git
synced 2025-11-10 00:46:03 +00:00
resize: Move handler to new resize_handler module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
89f824c769
commit
ac8436d46c
@@ -163,6 +163,7 @@ EXEMPT_FILES = make_set(
|
|||||||
"web/src/reload.js",
|
"web/src/reload.js",
|
||||||
"web/src/reminder.js",
|
"web/src/reminder.js",
|
||||||
"web/src/resize.js",
|
"web/src/resize.js",
|
||||||
|
"web/src/resize_handler.js",
|
||||||
"web/src/rows.js",
|
"web/src/rows.js",
|
||||||
"web/src/scheduled_messages.js",
|
"web/src/scheduled_messages.js",
|
||||||
"web/src/scheduled_messages_overlay_ui.js",
|
"web/src/scheduled_messages_overlay_ui.js",
|
||||||
|
|||||||
@@ -3,16 +3,8 @@ import $ from "jquery";
|
|||||||
|
|
||||||
import * as blueslip from "./blueslip";
|
import * as blueslip from "./blueslip";
|
||||||
import * as compose_state from "./compose_state";
|
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 message_viewport from "./message_viewport";
|
||||||
import * as navbar_alerts from "./navbar_alerts";
|
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() {
|
function get_bottom_whitespace_height() {
|
||||||
return message_viewport.height() * 0.4;
|
return message_viewport.height() * 0.4;
|
||||||
@@ -157,39 +149,3 @@ export function resize_page_components() {
|
|||||||
const h = resize_sidebars();
|
const h = resize_sidebars();
|
||||||
resize_bottom_whitespace(h);
|
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
47
web/src/resize_handler.js
Normal file
47
web/src/resize_handler.js
Normal file
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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 recent_view_ui from "./recent_view_ui";
|
||||||
import * as reload from "./reload";
|
import * as reload from "./reload";
|
||||||
import * as rendered_markdown from "./rendered_markdown";
|
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 from "./scheduled_messages";
|
||||||
import * as scheduled_messages_overlay_ui from "./scheduled_messages_overlay_ui";
|
import * as scheduled_messages_overlay_ui from "./scheduled_messages_overlay_ui";
|
||||||
import * as scheduled_messages_popover from "./scheduled_messages_popover";
|
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.
|
// 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
|
// Scrolling in overlays. input boxes, and other elements that
|
||||||
// explicitly scroll should not scroll the main view. Stop
|
// 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
|
// 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.
|
// exact right width for the compose box, but, close enough for now.
|
||||||
resize.handler();
|
resize_handler.handler();
|
||||||
|
|
||||||
if (page_params.is_spectator) {
|
if (page_params.is_spectator) {
|
||||||
$("body").addClass("spectator-view");
|
$("body").addClass("spectator-view");
|
||||||
|
|||||||
Reference in New Issue
Block a user