mirror of https://github.com/zulip/zulip.git
js: Convert static/js/ui_util.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
8a07ec5365
commit
f59133db42
|
@ -213,7 +213,6 @@
|
||||||
"typing_events": false,
|
"typing_events": false,
|
||||||
"ui": false,
|
"ui": false,
|
||||||
"ui_init": false,
|
"ui_init": false,
|
||||||
"ui_util": false,
|
|
||||||
"unread": false,
|
"unread": false,
|
||||||
"unread_ops": false,
|
"unread_ops": false,
|
||||||
"upload_widget": false,
|
"upload_widget": false,
|
||||||
|
|
|
@ -75,7 +75,9 @@ const page_params = set_global("page_params", {});
|
||||||
const resize = {__esModule: true};
|
const resize = {__esModule: true};
|
||||||
rewiremock("../../static/js/resize").with(resize);
|
rewiremock("../../static/js/resize").with(resize);
|
||||||
const subs = set_global("subs", {});
|
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
|
// Setting these up so that we can test that links to uploads within messages are
|
||||||
// automatically converted to server relative links.
|
// automatically converted to server relative links.
|
||||||
|
|
|
@ -35,7 +35,8 @@ const narrow = set_global("narrow", {});
|
||||||
const overlays = set_global("overlays", {});
|
const overlays = set_global("overlays", {});
|
||||||
const settings = set_global("settings", {});
|
const settings = set_global("settings", {});
|
||||||
const subs = set_global("subs", {});
|
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({
|
rewiremock("../../static/js/top_left_corner").with({
|
||||||
handle_narrow_deactivated: () => {},
|
handle_narrow_deactivated: () => {},
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
const {strict: assert} = require("assert");
|
const {strict: assert} = require("assert");
|
||||||
|
|
||||||
|
const rewiremock = require("rewiremock/node");
|
||||||
|
|
||||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||||
const {run_test} = require("../zjsunit/test");
|
const {run_test} = require("../zjsunit/test");
|
||||||
const $ = require("../zjsunit/zjquery");
|
const $ = require("../zjsunit/zjquery");
|
||||||
|
@ -11,7 +13,7 @@ set_global("document", {});
|
||||||
const noop = () => {};
|
const noop = () => {};
|
||||||
const example_img_link = "http://example.com/example.png";
|
const example_img_link = "http://example.com/example.png";
|
||||||
|
|
||||||
set_global("ui_util", {
|
rewiremock("../../static/js/ui_util").with({
|
||||||
place_caret_at_end: noop,
|
place_caret_at_end: noop,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -19,6 +21,8 @@ set_global("getSelection", () => ({
|
||||||
anchorOffset: 0,
|
anchorOffset: 0,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
rewiremock.enable();
|
||||||
|
|
||||||
zrequire("templates");
|
zrequire("templates");
|
||||||
const input_pill = zrequire("input_pill");
|
const input_pill = zrequire("input_pill");
|
||||||
|
|
||||||
|
@ -595,3 +599,4 @@ run_test("clear", () => {
|
||||||
assert.deepEqual(removed_colors, ["blue", "yellow", "red"]);
|
assert.deepEqual(removed_colors, ["blue", "yellow", "red"]);
|
||||||
assert.equal(pill_input[0].textContent, "");
|
assert.equal(pill_input[0].textContent, "");
|
||||||
});
|
});
|
||||||
|
rewiremock.disable();
|
||||||
|
|
|
@ -36,7 +36,8 @@ const message_view_header = set_global("message_view_header", {});
|
||||||
const top_left_corner = {__esModule: true};
|
const top_left_corner = {__esModule: true};
|
||||||
rewiremock("../../static/js/top_left_corner").with(top_left_corner);
|
rewiremock("../../static/js/top_left_corner").with(top_left_corner);
|
||||||
const typing_events = set_global("typing_events", {});
|
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", {});
|
const unread_ops = set_global("unread_ops", {});
|
||||||
set_global("search_pill_widget", {
|
set_global("search_pill_widget", {
|
||||||
widget: {
|
widget: {
|
||||||
|
|
|
@ -20,7 +20,7 @@ const narrow_state = {
|
||||||
};
|
};
|
||||||
rewiremock("../../static/js/narrow_state").with(narrow_state);
|
rewiremock("../../static/js/narrow_state").with(narrow_state);
|
||||||
const search_suggestion = set_global("search_suggestion", {});
|
const search_suggestion = set_global("search_suggestion", {});
|
||||||
set_global("ui_util", {
|
rewiremock("../../static/js/ui_util").with({
|
||||||
change_tab_to: noop,
|
change_tab_to: noop,
|
||||||
place_caret_at_end: noop,
|
place_caret_at_end: noop,
|
||||||
});
|
});
|
||||||
|
|
|
@ -17,7 +17,7 @@ const noop = () => {};
|
||||||
const narrow_state = {__esModule: true};
|
const narrow_state = {__esModule: true};
|
||||||
rewiremock("../../static/js/narrow_state").with(narrow_state);
|
rewiremock("../../static/js/narrow_state").with(narrow_state);
|
||||||
const search_suggestion = set_global("search_suggestion", {});
|
const search_suggestion = set_global("search_suggestion", {});
|
||||||
set_global("ui_util", {
|
rewiremock("../../static/js/ui_util").with({
|
||||||
change_tab_to: noop,
|
change_tab_to: noop,
|
||||||
});
|
});
|
||||||
const narrow = set_global("narrow", {});
|
const narrow = set_global("narrow", {});
|
||||||
|
|
|
@ -27,7 +27,6 @@ import "../reload";
|
||||||
import "../compose_actions";
|
import "../compose_actions";
|
||||||
import "../subs";
|
import "../subs";
|
||||||
import "../ui";
|
import "../ui";
|
||||||
import "../ui_util";
|
|
||||||
import "../click_handlers";
|
import "../click_handlers";
|
||||||
import "../settings_panel_menu";
|
import "../settings_panel_menu";
|
||||||
import "../settings_toggle";
|
import "../settings_toggle";
|
||||||
|
|
|
@ -17,6 +17,7 @@ const muting_ui = require("./muting_ui");
|
||||||
const rows = require("./rows");
|
const rows = require("./rows");
|
||||||
const settings_panel_menu = require("./settings_panel_menu");
|
const settings_panel_menu = require("./settings_panel_menu");
|
||||||
const stream_edit = require("./stream_edit");
|
const stream_edit = require("./stream_edit");
|
||||||
|
const ui_util = require("./ui_util");
|
||||||
const user_status_ui = require("./user_status_ui");
|
const user_status_ui = require("./user_status_ui");
|
||||||
const util = require("./util");
|
const util = require("./util");
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ const narrow_state = require("./narrow_state");
|
||||||
const people = require("./people");
|
const people = require("./people");
|
||||||
const reload_state = require("./reload_state");
|
const reload_state = require("./reload_state");
|
||||||
const stream_data = require("./stream_data");
|
const stream_data = require("./stream_data");
|
||||||
|
const ui_util = require("./ui_util");
|
||||||
|
|
||||||
exports.blur_compose_inputs = function () {
|
exports.blur_compose_inputs = function () {
|
||||||
$(".message_comp").find("input, textarea, button, #private_message_recipient").trigger("blur");
|
$(".message_comp").find("input, textarea, button, #private_message_recipient").trigger("blur");
|
||||||
|
|
|
@ -84,7 +84,6 @@ declare let timerender: any;
|
||||||
declare let typeahead_helper: any;
|
declare let typeahead_helper: any;
|
||||||
declare let typing_events: any;
|
declare let typing_events: any;
|
||||||
declare let ui: any;
|
declare let ui: any;
|
||||||
declare let ui_util: any;
|
|
||||||
declare let unread: any;
|
declare let unread: any;
|
||||||
declare let unread_ops: any;
|
declare let unread_ops: any;
|
||||||
declare let upload_widget: any;
|
declare let upload_widget: any;
|
||||||
|
|
|
@ -6,6 +6,7 @@ const info_overlay = require("./info_overlay");
|
||||||
const invite = require("./invite");
|
const invite = require("./invite");
|
||||||
const message_viewport = require("./message_viewport");
|
const message_viewport = require("./message_viewport");
|
||||||
const top_left_corner = require("./top_left_corner");
|
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
|
// Read https://zulip.readthedocs.io/en/latest/subsystems/hashchange-system.html
|
||||||
// or locally: docs/subsystems/hashchange-system.md
|
// or locally: docs/subsystems/hashchange-system.md
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
const render_input_pill = require("../templates/input_pill.hbs");
|
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
|
// See https://zulip.readthedocs.io/en/latest/subsystems/input-pills.html
|
||||||
exports.random_id = function () {
|
exports.random_id = function () {
|
||||||
return Math.random().toString(16);
|
return Math.random().toString(16);
|
||||||
|
|
|
@ -14,6 +14,7 @@ import * as resize from "./resize";
|
||||||
import * as rows from "./rows";
|
import * as rows from "./rows";
|
||||||
import * as stream_data from "./stream_data";
|
import * as stream_data from "./stream_data";
|
||||||
import * as ui_report from "./ui_report";
|
import * as ui_report from "./ui_report";
|
||||||
|
import * as ui_util from "./ui_util";
|
||||||
import * as upload from "./upload";
|
import * as upload from "./upload";
|
||||||
|
|
||||||
const currently_editing_messages = new Map();
|
const currently_editing_messages = new Map();
|
||||||
|
|
|
@ -17,6 +17,7 @@ const stream_data = require("./stream_data");
|
||||||
const stream_topic_history = require("./stream_topic_history");
|
const stream_topic_history = require("./stream_topic_history");
|
||||||
const top_left_corner = require("./top_left_corner");
|
const top_left_corner = require("./top_left_corner");
|
||||||
const topic_generator = require("./topic_generator");
|
const topic_generator = require("./topic_generator");
|
||||||
|
const ui_util = require("./ui_util");
|
||||||
const util = require("./util");
|
const util = require("./util");
|
||||||
|
|
||||||
let unnarrow_times;
|
let unnarrow_times;
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
const {Filter} = require("./filter");
|
const {Filter} = require("./filter");
|
||||||
const narrow_state = require("./narrow_state");
|
const narrow_state = require("./narrow_state");
|
||||||
const search_pill = require("./search_pill");
|
const search_pill = require("./search_pill");
|
||||||
|
const ui_util = require("./ui_util");
|
||||||
|
|
||||||
// Exported for unit testing
|
// Exported for unit testing
|
||||||
exports.is_using_input_method = false;
|
exports.is_using_input_method = false;
|
||||||
|
|
|
@ -15,6 +15,7 @@ const muting_ui = require("./muting_ui");
|
||||||
const resize = require("./resize");
|
const resize = require("./resize");
|
||||||
const stream_color = require("./stream_color");
|
const stream_color = require("./stream_color");
|
||||||
const stream_data = require("./stream_data");
|
const stream_data = require("./stream_data");
|
||||||
|
const ui_util = require("./ui_util");
|
||||||
|
|
||||||
// We handle stream popovers and topic popovers in this
|
// We handle stream popovers and topic popovers in this
|
||||||
// module. Both are popped up from the left sidebar.
|
// module. Both are popped up from the left sidebar.
|
||||||
|
|
|
@ -39,6 +39,7 @@ const topic_list = require("./topic_list");
|
||||||
const topic_zoom = require("./topic_zoom");
|
const topic_zoom = require("./topic_zoom");
|
||||||
const tutorial = require("./tutorial");
|
const tutorial = require("./tutorial");
|
||||||
const typing = require("./typing");
|
const typing = require("./typing");
|
||||||
|
const ui_util = require("./ui_util");
|
||||||
const unread_ui = require("./unread_ui");
|
const unread_ui = require("./unread_ui");
|
||||||
const user_groups = require("./user_groups");
|
const user_groups = require("./user_groups");
|
||||||
const user_status = require("./user_status");
|
const user_status = require("./user_status");
|
||||||
|
|
|
@ -1,17 +1,15 @@
|
||||||
"use strict";
|
import * as stream_color from "./stream_color";
|
||||||
|
import * as stream_data from "./stream_data";
|
||||||
const stream_color = require("./stream_color");
|
|
||||||
const stream_data = require("./stream_data");
|
|
||||||
|
|
||||||
// Add functions to this that have no non-trivial
|
// Add functions to this that have no non-trivial
|
||||||
// dependencies other than jQuery.
|
// 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");
|
$(`#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
|
// 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();
|
el.focus();
|
||||||
|
|
||||||
if (typeof window.getSelection !== "undefined" && typeof document.createRange !== "undefined") {
|
if (typeof window.getSelection !== "undefined" && typeof document.createRange !== "undefined") {
|
||||||
|
@ -27,12 +25,12 @@ exports.place_caret_at_end = function (el) {
|
||||||
textRange.collapse(false);
|
textRange.collapse(false);
|
||||||
textRange.select();
|
textRange.select();
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.blur_active_element = function () {
|
export function blur_active_element() {
|
||||||
// this blurs anything that may perhaps be actively focused on.
|
// this blurs anything that may perhaps be actively focused on.
|
||||||
document.activeElement.blur();
|
document.activeElement.blur();
|
||||||
};
|
}
|
||||||
|
|
||||||
function update_lock_icon_for_stream(stream_name) {
|
function update_lock_icon_for_stream(stream_name) {
|
||||||
const icon = $("#compose-lock-icon");
|
const icon = $("#compose-lock-icon");
|
||||||
|
@ -50,7 +48,7 @@ function update_lock_icon_for_stream(stream_name) {
|
||||||
// color look like the stream being used.
|
// color look like the stream being used.
|
||||||
// (In particular, if there's a color associated with it,
|
// (In particular, if there's a color associated with it,
|
||||||
// have that color be reflected here too.)
|
// 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) {
|
if (stream_name === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -62,6 +60,4 @@ exports.decorate_stream_bar = function (stream_name, element, is_compose) {
|
||||||
.css("background-color", color)
|
.css("background-color", color)
|
||||||
.removeClass(stream_color.color_classes)
|
.removeClass(stream_color.color_classes)
|
||||||
.addClass(stream_color.get_color_class(color));
|
.addClass(stream_color.get_color_class(color));
|
||||||
};
|
}
|
||||||
|
|
||||||
window.ui_util = exports;
|
|
||||||
|
|
Loading…
Reference in New Issue