Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
js: Convert static/js/common.js to ES6 module.
Anders Kaseorga3e6ebb04c05
diff --git a/.eslintrc.json b/.eslintrc.jsonindex 4d292591179..03a09183f3f 100644--- a/.eslintrc.json+++ b/.eslintrc.json@@ -139,7 +139,6 @@"channel": false,"click_handlers": false,"color_data": false,- "common": false,"compose": false,"compose_actions": false,"compose_fade": false,diff --git a/frontend_tests/node_tests/common.js b/frontend_tests/node_tests/common.jsindex e5234e1033f..b4fd5ba8fd9 100644--- a/frontend_tests/node_tests/common.js+++ b/frontend_tests/node_tests/common.js@@ -71,7 +71,7 @@ run_test("copy_data_attribute_value", (override) => {});run_test("adjust_mac_shortcuts non-mac", () => {- common.has_mac_keyboard = () => false;+ common.__Rewire__("has_mac_keyboard", () => false);// The adjust_mac_shortcuts has a really simple guard// at the top, and we just test the early-return behavior@@ -95,7 +95,7 @@ run_test("adjust_mac_shortcuts mac", () => {["Ctrl + Backspace + End", "⌘ + Delete + Fn + →"],]);- common.has_mac_keyboard = () => true;+ common.__Rewire__("has_mac_keyboard", () => true);const test_items = [];let key_no = 1;diff --git a/frontend_tests/node_tests/compose.js b/frontend_tests/node_tests/compose.jsindex e77f52e4c6b..1fae9a05090 100644--- a/frontend_tests/node_tests/compose.js+++ b/frontend_tests/node_tests/compose.js@@ -82,7 +82,6 @@ const compose_ui = zrequire("compose_ui");const peer_data = zrequire("peer_data");const util = zrequire("util");const rtl = zrequire("rtl");-zrequire("common");const stream_data = zrequire("stream_data");const compose_state = zrequire("compose_state");const people = zrequire("people");diff --git a/frontend_tests/node_tests/compose_actions.js b/frontend_tests/node_tests/compose_actions.jsindex 669e3a90852..ca85ef09443 100644--- a/frontend_tests/node_tests/compose_actions.js+++ b/frontend_tests/node_tests/compose_actions.js@@ -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");@@ -43,7 +45,7 @@ set_global("unread_ops", {notify_server_message_read: noop,});-set_global("common", {+rewiremock("../../static/js/common").with({status_classes: "status_classes",});@@ -55,6 +57,8 @@ set_global("current_msg_list", {const channel = set_global("channel", {});+rewiremock.enable();+const people = zrequire("people");const compose_ui = zrequire("compose_ui");const compose = zrequire("compose");@@ -485,3 +489,4 @@ run_test("on_narrow", (override) => {});assert(cancel_called);});+rewiremock.disable();diff --git a/frontend_tests/node_tests/hotkey.js b/frontend_tests/node_tests/hotkey.jsindex c8363aca70c..9011221c717 100644--- a/frontend_tests/node_tests/hotkey.js+++ b/frontend_tests/node_tests/hotkey.js@@ -107,7 +107,6 @@ const emoji_codes = zrequire("emoji_codes", "generated/emoji/emoji_codes.json");const emoji = zrequire("emoji", "shared/js/emoji");const activity = zrequire("activity");const hotkey = zrequire("hotkey");-zrequire("common");emoji.initialize({realm_emoji: {},diff --git a/frontend_tests/node_tests/search_suggestion.js b/frontend_tests/node_tests/search_suggestion.jsindex 0df2c08ed47..40e6a584a56 100644--- a/frontend_tests/node_tests/search_suggestion.js+++ b/frontend_tests/node_tests/search_suggestion.js@@ -28,7 +28,6 @@ const stream_data = zrequire("stream_data");const stream_topic_history = zrequire("stream_topic_history");const people = zrequire("people");zrequire("unread");-zrequire("common");const search = zrequire("search_suggestion");search.max_num_of_search_results = 15;diff --git a/frontend_tests/node_tests/search_suggestion_legacy.js b/frontend_tests/node_tests/search_suggestion_legacy.jsindex 614ff0c5598..0c4f15e2d91 100644--- a/frontend_tests/node_tests/search_suggestion_legacy.js+++ b/frontend_tests/node_tests/search_suggestion_legacy.js@@ -26,7 +26,6 @@ const stream_data = zrequire("stream_data");const stream_topic_history = zrequire("stream_topic_history");const people = zrequire("people");zrequire("unread");-zrequire("common");const search = zrequire("search_suggestion");search.max_num_of_search_results = 15;diff --git a/static/js/analytics/activity.js b/static/js/analytics/activity.jsindex 7b0347c3e09..a73a51bce52 100644--- a/static/js/analytics/activity.js+++ b/static/js/analytics/activity.js@@ -1,6 +1,7 @@+import * as common from "../common";+$(() => {$("a.envelope-link").on("click", function () {common.copy_data_attribute_value($(this), "admin-emails");});});-export {};diff --git a/static/js/analytics/support.js b/static/js/analytics/support.jsindex c3eb30ace41..2a8a98c160e 100644--- a/static/js/analytics/support.js+++ b/static/js/analytics/support.js@@ -1,3 +1,5 @@+import * as common from "../common";+$(() => {$("body").on("click", ".scrub-realm-button", function (e) {e.preventDefault();@@ -18,4 +20,3 @@ $(() => {common.copy_data_attribute_value($(this), "copytext");});});-export {};diff --git a/static/js/bundles/common.js b/static/js/bundles/common.jsindex efdede353ae..92f33598b15 100644--- a/static/js/bundles/common.js+++ b/static/js/bundles/common.js@@ -7,7 +7,6 @@ import "../page_params";import "../csrf";import "../blueslip";import "../../third/bootstrap/js/bootstrap";-import "../common";import "../../third/bootstrap/css/bootstrap.css";import "../../third/bootstrap/css/bootstrap-btn.css";import "simplebar/dist/simplebar.css";diff --git a/static/js/common.js b/static/js/common.jsindex b6593d10775..6569045a191 100644--- a/static/js/common.js+++ b/static/js/common.js@@ -1,17 +1,15 @@-"use strict";-// This reloads the module in development rather than refreshing the pageif (module.hot) {module.hot.accept();}-exports.status_classes = "alert-error alert-success alert-info alert-warning";+export const status_classes = "alert-error alert-success alert-info alert-warning";-exports.autofocus = function (selector) {+export function autofocus(selector) {$(() => {$(selector).trigger("focus");});-};+}// Return a boolean indicating whether the password is acceptable.// Also updates a Bootstrap progress bar control (a jQuery object)@@ -21,7 +19,7 @@ exports.autofocus = function (selector) {//// This is in common.js because we want to use it from the signup page// and also from the in-app password change interface.-exports.password_quality = function (password, bar, password_field) {+export function password_quality(password, bar, password_field) {// We load zxcvbn.js asynchronously, so the variable might not be set.if (typeof zxcvbn === "undefined") {return undefined;@@ -51,9 +49,9 @@ exports.password_quality = function (password, bar, password_field) {}return acceptable;-};+}-exports.password_warning = function (password, password_field) {+export function password_warning(password, password_field) {if (typeof zxcvbn === "undefined") {return undefined;}@@ -66,9 +64,9 @@ exports.password_warning = function (password, password_field) {});}return zxcvbn(password).feedback.warning || i18n.t("Password is too weak");-};+}-exports.phrase_match = function (query, phrase) {+export function phrase_match(query, phrase) {// match "tes" to "test" and "stream test" but not "hostess"let i;query = query.toLowerCase();@@ -85,9 +83,9 @@ exports.phrase_match = function (query, phrase) {}}return false;-};+}-exports.copy_data_attribute_value = function (elem, key) {+export function copy_data_attribute_value(elem, key) {// function to copy the value of data-key// attribute of the element to clipboardconst temp = $(document.createElement("input"));@@ -97,14 +95,14 @@ exports.copy_data_attribute_value = function (elem, key) {temp.remove();elem.fadeOut(250);elem.fadeIn(1000);-};+}-exports.has_mac_keyboard = function () {+export function has_mac_keyboard() {return /mac/i.test(navigator.platform);-};+}-exports.adjust_mac_shortcuts = function (key_elem_class, require_cmd_style) {- if (!exports.has_mac_keyboard()) {+export function adjust_mac_shortcuts(key_elem_class, require_cmd_style) {+ if (!has_mac_keyboard()) {return;}@@ -134,6 +132,4 @@ exports.adjust_mac_shortcuts = function (key_elem_class, require_cmd_style) {$(this).text(key_text);});-};--window.common = exports;+}diff --git a/static/js/compose.js b/static/js/compose.jsindex e42c52ccba1..9b25b6be00c 100644--- a/static/js/compose.js+++ b/static/js/compose.js@@ -9,6 +9,7 @@ const render_compose_invite_users = require("../templates/compose_invite_users.hconst render_compose_not_subscribed = require("../templates/compose_not_subscribed.hbs");const render_compose_private_stream_alert = require("../templates/compose_private_stream_alert.hbs");+const common = require("./common");const echo = require("./echo");const peer_data = require("./peer_data");const people = require("./people");diff --git a/static/js/compose_actions.js b/static/js/compose_actions.jsindex 4be6b914ca0..640fcb8afeb 100644--- a/static/js/compose_actions.js+++ b/static/js/compose_actions.js@@ -4,6 +4,7 @@ const autosize = require("autosize");const fenced_code = require("../shared/js/fenced_code");+const common = require("./common");const people = require("./people");exports.blur_compose_inputs = function () {diff --git a/static/js/global.d.ts b/static/js/global.d.tsindex a80ae8bdacb..ff36dea3e0e 100644--- a/static/js/global.d.ts+++ b/static/js/global.d.ts@@ -17,7 +17,6 @@ declare let buddy_list: any;declare let channel: any;declare let click_handlers: any;declare let color_data: any;-declare let common: any;declare let compose: any;declare let compose_actions: any;declare let composebox_typeahead: any;diff --git a/static/js/hotkey.js b/static/js/hotkey.jsindex 81eec563036..23150779dd4 100644--- a/static/js/hotkey.js+++ b/static/js/hotkey.js@@ -2,6 +2,7 @@const emoji = require("../shared/js/emoji");+const common = require("./common");const copy_and_paste = require("./copy_and_paste");const feedback_widget = require("./feedback_widget");const topic_zoom = require("./topic_zoom");diff --git a/static/js/info_overlay.js b/static/js/info_overlay.jsindex 09c54c9c030..7ad50b1db57 100644--- a/static/js/info_overlay.js+++ b/static/js/info_overlay.js@@ -1,5 +1,6 @@"use strict";+const common = require("./common");const components = require("./components");// Make it explicit that our toggler is undefined untildiff --git a/static/js/invite.js b/static/js/invite.jsindex 4d2a62eb3b7..7513d6a0b5a 100644--- a/static/js/invite.js+++ b/static/js/invite.js@@ -6,6 +6,8 @@ import render_invitation_failed_error from "../templates/invitation_failed_errorimport render_invite_subscription from "../templates/invite_subscription.hbs";import render_settings_dev_env_email_access from "../templates/settings/dev_env_email_access.hbs";+import * as common from "./common";+function reset_error_messages() {$("#invite_status").hide().text("").removeClass(common.status_classes);$("#multiuse_invite_status").hide().text("").removeClass(common.status_classes);diff --git a/static/js/portico/help.js b/static/js/portico/help.jsindex 1cd1f7bf675..1a0359a52e0 100644--- a/static/js/portico/help.js+++ b/static/js/portico/help.js@@ -1,5 +1,7 @@import SimpleBar from "simplebar/dist/simplebar";+import * as common from "../common";+import * as google_analytics from "./google-analytics";import {activate_correct_tab} from "./tabbed-instructions";diff --git a/static/js/portico/integrations.js b/static/js/portico/integrations.jsindex ef7e802dbb3..3c60c6c3c4b 100644--- a/static/js/portico/integrations.js+++ b/static/js/portico/integrations.js@@ -1,6 +1,7 @@import _ from "lodash";import * as blueslip from "../blueslip";+import * as common from "../common";import * as google_analytics from "./google-analytics";import {path_parts} from "./landing-page";diff --git a/static/js/portico/signup.js b/static/js/portico/signup.jsindex bdd9eb3e057..250c4b5c27a 100644--- a/static/js/portico/signup.js+++ b/static/js/portico/signup.js@@ -1,3 +1,5 @@+import * as common from "../common";+$(() => {// NB: this file is included on multiple pages. In each context,// some of the jQuery selectors below will return empty lists.@@ -210,4 +212,3 @@ $(() => {this.parentNode.submit();});});-export {};diff --git a/static/js/portico/tabbed-instructions.js b/static/js/portico/tabbed-instructions.jsindex 4649a272613..744bc9dda77 100644--- a/static/js/portico/tabbed-instructions.js+++ b/static/js/portico/tabbed-instructions.js@@ -1,3 +1,5 @@+import * as common from "../common";+export function detect_user_os() {if (/android/i.test(navigator.userAgent)) {return "android";diff --git a/static/js/search_suggestion.js b/static/js/search_suggestion.jsindex 3eed811f9ff..aa4716d9c96 100644--- a/static/js/search_suggestion.js+++ b/static/js/search_suggestion.js@@ -2,6 +2,7 @@const Handlebars = require("handlebars/runtime");+const common = require("./common");const huddle_data = require("./huddle_data");const people = require("./people");const settings_data = require("./settings_data");diff --git a/static/js/settings_account.js b/static/js/settings_account.jsindex ffd55134f3a..0d165d0ae78 100644--- a/static/js/settings_account.js+++ b/static/js/settings_account.js@@ -6,6 +6,7 @@ const render_settings_api_key_modal = require("../templates/settings/api_key_modconst render_settings_custom_user_profile_field = require("../templates/settings/custom_user_profile_field.hbs");const render_settings_dev_env_email_access = require("../templates/settings/dev_env_email_access.hbs");+const common = require("./common");const people = require("./people");const pill_typeahead = require("./pill_typeahead");const settings_ui = require("./settings_ui");diff --git a/static/js/ui.js b/static/js/ui.jsindex 2ffb0ede595..e36bac58d05 100644--- a/static/js/ui.js+++ b/static/js/ui.js@@ -2,6 +2,7 @@const SimpleBar = require("simplebar/dist/simplebar");+const common = require("./common");const {localstorage} = require("./localstorage");// What, if anything, obscures the home tab?diff --git a/static/js/ui_report.js b/static/js/ui_report.jsindex 206c0760c01..3a380b8b246 100644--- a/static/js/ui_report.js+++ b/static/js/ui_report.js@@ -1,6 +1,8 @@"use strict";const _ = require("lodash");++const common = require("./common");/* Arguments used in the report_* functions are,response- response that we want to displaystatus_box- element being used to display the responsediff --git a/static/js/zcommand.js b/static/js/zcommand.jsindex 29c09ad287b..d451f1b8fc6 100644--- a/static/js/zcommand.js+++ b/static/js/zcommand.js@@ -1,5 +1,6 @@import marked from "../third/marked/lib/marked";+import * as common from "./common";import * as feedback_widget from "./feedback_widget";/*