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

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2021-02-27 16:00:36 -08:00 committed by Tim Abbott
parent 8a07ec5365
commit f59133db42
19 changed files with 35 additions and 23 deletions

View File

@ -213,7 +213,6 @@
"typing_events": false,
"ui": false,
"ui_init": false,
"ui_util": false,
"unread": false,
"unread_ops": false,
"upload_widget": false,

View File

@ -75,7 +75,9 @@ const page_params = set_global("page_params", {});
const resize = {__esModule: true};
rewiremock("../../static/js/resize").with(resize);
const subs = set_global("subs", {});
const ui_util = set_global("ui_util", {});
const ui_util = {__esModule: true};
rewiremock("../../static/js/ui_util").with(ui_util);
// Setting these up so that we can test that links to uploads within messages are
// automatically converted to server relative links.

View File

@ -35,7 +35,8 @@ const narrow = set_global("narrow", {});
const overlays = set_global("overlays", {});
const settings = set_global("settings", {});
const subs = set_global("subs", {});
const ui_util = set_global("ui_util", {});
const ui_util = {__esModule: true};
rewiremock("../../static/js/ui_util").with(ui_util);
rewiremock("../../static/js/top_left_corner").with({
handle_narrow_deactivated: () => {},
});

View File

@ -2,6 +2,8 @@
const {strict: assert} = require("assert");
const rewiremock = require("rewiremock/node");
const {set_global, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery");
@ -11,7 +13,7 @@ set_global("document", {});
const noop = () => {};
const example_img_link = "http://example.com/example.png";
set_global("ui_util", {
rewiremock("../../static/js/ui_util").with({
place_caret_at_end: noop,
});
@ -19,6 +21,8 @@ set_global("getSelection", () => ({
anchorOffset: 0,
}));
rewiremock.enable();
zrequire("templates");
const input_pill = zrequire("input_pill");
@ -595,3 +599,4 @@ run_test("clear", () => {
assert.deepEqual(removed_colors, ["blue", "yellow", "red"]);
assert.equal(pill_input[0].textContent, "");
});
rewiremock.disable();

View File

@ -36,7 +36,8 @@ const message_view_header = set_global("message_view_header", {});
const top_left_corner = {__esModule: true};
rewiremock("../../static/js/top_left_corner").with(top_left_corner);
const typing_events = set_global("typing_events", {});
const ui_util = set_global("ui_util", {});
const ui_util = {__esModule: true};
rewiremock("../../static/js/ui_util").with(ui_util);
const unread_ops = set_global("unread_ops", {});
set_global("search_pill_widget", {
widget: {

View File

@ -20,7 +20,7 @@ const narrow_state = {
};
rewiremock("../../static/js/narrow_state").with(narrow_state);
const search_suggestion = set_global("search_suggestion", {});
set_global("ui_util", {
rewiremock("../../static/js/ui_util").with({
change_tab_to: noop,
place_caret_at_end: noop,
});

View File

@ -17,7 +17,7 @@ const noop = () => {};
const narrow_state = {__esModule: true};
rewiremock("../../static/js/narrow_state").with(narrow_state);
const search_suggestion = set_global("search_suggestion", {});
set_global("ui_util", {
rewiremock("../../static/js/ui_util").with({
change_tab_to: noop,
});
const narrow = set_global("narrow", {});

View File

@ -27,7 +27,6 @@ import "../reload";
import "../compose_actions";
import "../subs";
import "../ui";
import "../ui_util";
import "../click_handlers";
import "../settings_panel_menu";
import "../settings_toggle";

View File

@ -17,6 +17,7 @@ const muting_ui = require("./muting_ui");
const rows = require("./rows");
const settings_panel_menu = require("./settings_panel_menu");
const stream_edit = require("./stream_edit");
const ui_util = require("./ui_util");
const user_status_ui = require("./user_status_ui");
const util = require("./util");

View File

@ -16,6 +16,7 @@ const narrow_state = require("./narrow_state");
const people = require("./people");
const reload_state = require("./reload_state");
const stream_data = require("./stream_data");
const ui_util = require("./ui_util");
exports.blur_compose_inputs = function () {
$(".message_comp").find("input, textarea, button, #private_message_recipient").trigger("blur");

View File

@ -84,7 +84,6 @@ declare let timerender: any;
declare let typeahead_helper: any;
declare let typing_events: any;
declare let ui: any;
declare let ui_util: any;
declare let unread: any;
declare let unread_ops: any;
declare let upload_widget: any;

View File

@ -6,6 +6,7 @@ const info_overlay = require("./info_overlay");
const invite = require("./invite");
const message_viewport = require("./message_viewport");
const top_left_corner = require("./top_left_corner");
const ui_util = require("./ui_util");
// Read https://zulip.readthedocs.io/en/latest/subsystems/hashchange-system.html
// or locally: docs/subsystems/hashchange-system.md

View File

@ -2,6 +2,8 @@
const render_input_pill = require("../templates/input_pill.hbs");
const ui_util = require("./ui_util");
// See https://zulip.readthedocs.io/en/latest/subsystems/input-pills.html
exports.random_id = function () {
return Math.random().toString(16);

View File

@ -14,6 +14,7 @@ import * as resize from "./resize";
import * as rows from "./rows";
import * as stream_data from "./stream_data";
import * as ui_report from "./ui_report";
import * as ui_util from "./ui_util";
import * as upload from "./upload";
const currently_editing_messages = new Map();

View File

@ -17,6 +17,7 @@ const stream_data = require("./stream_data");
const stream_topic_history = require("./stream_topic_history");
const top_left_corner = require("./top_left_corner");
const topic_generator = require("./topic_generator");
const ui_util = require("./ui_util");
const util = require("./util");
let unnarrow_times;

View File

@ -3,6 +3,7 @@
const {Filter} = require("./filter");
const narrow_state = require("./narrow_state");
const search_pill = require("./search_pill");
const ui_util = require("./ui_util");
// Exported for unit testing
exports.is_using_input_method = false;

View File

@ -15,6 +15,7 @@ const muting_ui = require("./muting_ui");
const resize = require("./resize");
const stream_color = require("./stream_color");
const stream_data = require("./stream_data");
const ui_util = require("./ui_util");
// We handle stream popovers and topic popovers in this
// module. Both are popped up from the left sidebar.

View File

@ -39,6 +39,7 @@ const topic_list = require("./topic_list");
const topic_zoom = require("./topic_zoom");
const tutorial = require("./tutorial");
const typing = require("./typing");
const ui_util = require("./ui_util");
const unread_ui = require("./unread_ui");
const user_groups = require("./user_groups");
const user_status = require("./user_status");

View File

@ -1,17 +1,15 @@
"use strict";
const stream_color = require("./stream_color");
const stream_data = require("./stream_data");
import * as stream_color from "./stream_color";
import * as stream_data from "./stream_data";
// Add functions to this that have no non-trivial
// dependencies other than jQuery.
exports.change_tab_to = function (tabname) {
export function change_tab_to(tabname) {
$(`#gear-menu a[href="${CSS.escape(tabname)}"]`).tab("show");
};
}
// https://stackoverflow.com/questions/4233265/contenteditable-set-caret-at-the-end-of-the-text-cross-browser
exports.place_caret_at_end = function (el) {
export function place_caret_at_end(el) {
el.focus();
if (typeof window.getSelection !== "undefined" && typeof document.createRange !== "undefined") {
@ -27,12 +25,12 @@ exports.place_caret_at_end = function (el) {
textRange.collapse(false);
textRange.select();
}
};
}
exports.blur_active_element = function () {
export function blur_active_element() {
// this blurs anything that may perhaps be actively focused on.
document.activeElement.blur();
};
}
function update_lock_icon_for_stream(stream_name) {
const icon = $("#compose-lock-icon");
@ -50,7 +48,7 @@ function update_lock_icon_for_stream(stream_name) {
// color look like the stream being used.
// (In particular, if there's a color associated with it,
// have that color be reflected here too.)
exports.decorate_stream_bar = function (stream_name, element, is_compose) {
export function decorate_stream_bar(stream_name, element, is_compose) {
if (stream_name === undefined) {
return;
}
@ -62,6 +60,4 @@ exports.decorate_stream_bar = function (stream_name, element, is_compose) {
.css("background-color", color)
.removeClass(stream_color.color_classes)
.addClass(stream_color.get_color_class(color));
};
window.ui_util = exports;
}