js: Convert static/js/scroll_util.js to ES6 module.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2021-02-27 15:37:30 -08:00 committed by Tim Abbott
parent 6477b7631c
commit 98c4ffa700
10 changed files with 12 additions and 15 deletions

View File

@ -212,7 +212,6 @@
"resize": false, "resize": false,
"rows": false, "rows": false,
"scroll_bar": false, "scroll_bar": false,
"scroll_util": false,
"search": false, "search": false,
"search_pill_widget": false, "search_pill_widget": false,
"search_suggestion": false, "search_suggestion": false,

View File

@ -42,6 +42,7 @@ const _keydown_util = {
const compose_state = {}; const compose_state = {};
const _scroll_util = { const _scroll_util = {
__esModule: true,
scroll_element_into_container: () => {}, scroll_element_into_container: () => {},
}; };
@ -74,7 +75,7 @@ rewiremock("../../static/js/keydown_util").with(_keydown_util);
set_global("pm_list", _pm_list); set_global("pm_list", _pm_list);
set_global("popovers", _popovers); set_global("popovers", _popovers);
set_global("resize", _resize); set_global("resize", _resize);
set_global("scroll_util", _scroll_util); rewiremock("../../static/js/scroll_util").with(_scroll_util);
set_global("stream_popover", _stream_popover); set_global("stream_popover", _stream_popover);
set_global("ui", _ui); set_global("ui", _ui);
set_global("server_events", { set_global("server_events", {

View File

@ -13,7 +13,6 @@ const _ListWidget = {
set_global("ListWidget", _ListWidget); set_global("ListWidget", _ListWidget);
const dropdown_list_widget = zrequire("dropdown_list_widget"); const dropdown_list_widget = zrequire("dropdown_list_widget");
zrequire("scroll_util");
const setup_zjquery_data = (name) => { const setup_zjquery_data = (name) => {
const input_group = $(".input_group"); const input_group = $(".input_group");

View File

@ -394,7 +394,7 @@ test_ui("narrowing", () => {
topic_list.rebuild = noop; topic_list.rebuild = noop;
topic_list.active_stream_id = noop; topic_list.active_stream_id = noop;
topic_list.get_stream_li = noop; topic_list.get_stream_li = noop;
scroll_util.scroll_element_into_container = noop; scroll_util.__Rewire__("scroll_element_into_container", noop);
set_global("ui", { set_global("ui", {
get_scroll_element: (element) => element, get_scroll_element: (element) => element,

View File

@ -15,7 +15,6 @@ import "flatpickr/dist/plugins/confirmDate/confirmDate";
// Import app JS // Import app JS
import "../i18n"; import "../i18n";
import "../fold_dict"; import "../fold_dict";
import "../scroll_util";
import "../drafts"; import "../drafts";
import "../input_pill"; import "../input_pill";
import "../user_pill"; import "../user_pill";

View File

@ -85,7 +85,6 @@ declare let reminder: any;
declare let resize: any; declare let resize: any;
declare let rows: any; declare let rows: any;
declare let scroll_bar: any; declare let scroll_bar: any;
declare let scroll_util: any;
declare let search: any; declare let search: any;
declare let search_pill_widget: any; declare let search_pill_widget: any;
declare let search_suggestion: any; declare let search_suggestion: any;

View File

@ -1,3 +1,5 @@
import * as scroll_util from "./scroll_util";
export class ListCursor { export class ListCursor {
constructor({highlight_class, list}) { constructor({highlight_class, list}) {
const config_ok = const config_ok =

View File

@ -1,6 +1,4 @@
"use strict"; export function scroll_delta(opts) {
exports.scroll_delta = function (opts) {
const elem_top = opts.elem_top; const elem_top = opts.elem_top;
const container_height = opts.container_height; const container_height = opts.container_height;
const elem_bottom = opts.elem_bottom; const elem_bottom = opts.elem_bottom;
@ -18,9 +16,9 @@ exports.scroll_delta = function (opts) {
} }
return delta; return delta;
}; }
exports.scroll_element_into_container = function (elem, container) { export function scroll_element_into_container(elem, container) {
// This does the minimum amount of scrolling that is needed to make // This does the minimum amount of scrolling that is needed to make
// the element visible. It doesn't try to center the element, so // the element visible. It doesn't try to center the element, so
// this will be non-intrusive to users when they already have // this will be non-intrusive to users when they already have
@ -36,13 +34,11 @@ exports.scroll_element_into_container = function (elem, container) {
container_height: container.height(), container_height: container.height(),
}; };
const delta = exports.scroll_delta(opts); const delta = scroll_delta(opts);
if (delta === 0) { if (delta === 0) {
return; return;
} }
container.scrollTop(container.scrollTop() + delta); container.scrollTop(container.scrollTop() + delta);
}; }
window.scroll_util = exports;

View File

@ -7,6 +7,7 @@ const render_stream_sidebar_row = require("../templates/stream_sidebar_row.hbs")
const keydown_util = require("./keydown_util"); const keydown_util = require("./keydown_util");
const {ListCursor} = require("./list_cursor"); const {ListCursor} = require("./list_cursor");
const scroll_util = require("./scroll_util");
const stream_sort = require("./stream_sort"); const stream_sort = require("./stream_sort");
const topic_zoom = require("./topic_zoom"); const topic_zoom = require("./topic_zoom");

View File

@ -10,6 +10,7 @@ const render_subscriptions = require("../templates/subscriptions.hbs");
const components = require("./components"); const components = require("./components");
const loading = require("./loading"); const loading = require("./loading");
const people = require("./people"); const people = require("./people");
const scroll_util = require("./scroll_util");
const search_util = require("./search_util"); const search_util = require("./search_util");
const stream_create = require("./stream_create"); const stream_create = require("./stream_create");
const stream_ui_updates = require("./stream_ui_updates"); const stream_ui_updates = require("./stream_ui_updates");