From f3af16db3f6e664b5901f6abea8033e0dfd0ece0 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Wed, 10 Feb 2021 08:00:58 -0800 Subject: [PATCH] js: Convert static/js/invite.js to ES6 module. Signed-off-by: Anders Kaseorg --- .eslintrc.json | 1 - frontend_tests/node_tests/ui_init.js | 1 - static/js/bundles/app.js | 1 - static/js/global.d.ts | 1 - static/js/hashchange.js | 2 ++ static/js/invite.js | 30 ++++++++++++---------------- static/js/ui_init.js | 1 + 7 files changed, 16 insertions(+), 21 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 9899939c6f..857e1e216d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -179,7 +179,6 @@ "i18n": false, "info_overlay": false, "input_pill": false, - "invite": false, "jQuery": false, "keydown_util": false, "lightbox": false, diff --git a/frontend_tests/node_tests/ui_init.js b/frontend_tests/node_tests/ui_init.js index 980dd69fb1..ea477c8ba8 100644 --- a/frontend_tests/node_tests/ui_init.js +++ b/frontend_tests/node_tests/ui_init.js @@ -93,7 +93,6 @@ zrequire("condense"); zrequire("spoilers"); zrequire("lightbox"); zrequire("overlays"); -zrequire("invite"); zrequire("message_view_header"); zrequire("narrow_state"); zrequire("presence"); diff --git a/static/js/bundles/app.js b/static/js/bundles/app.js index 1fbeb72aa3..9e6177791a 100644 --- a/static/js/bundles/app.js +++ b/static/js/bundles/app.js @@ -101,7 +101,6 @@ import "../hotkey"; import "../notifications"; import "../hash_util"; import "../hashchange"; -import "../invite"; import "../message_flags"; import "../starred_messages"; import "../alert_words"; diff --git a/static/js/global.d.ts b/static/js/global.d.ts index d01cf00bca..38a3e4b776 100644 --- a/static/js/global.d.ts +++ b/static/js/global.d.ts @@ -51,7 +51,6 @@ declare let hotspots: any; declare let i18n: any; declare let info_overlay: any; declare let input_pill: any; -declare let invite: any; declare let keydown_util: any; declare let lightbox: any; declare let list_util: any; diff --git a/static/js/hashchange.js b/static/js/hashchange.js index 52b6112360..393d78abbd 100644 --- a/static/js/hashchange.js +++ b/static/js/hashchange.js @@ -1,5 +1,7 @@ "use strict"; +const invite = require("./invite"); + // Read https://zulip.readthedocs.io/en/latest/subsystems/hashchange-system.html // or locally: docs/subsystems/hashchange-system.md let changing_hash = false; diff --git a/static/js/invite.js b/static/js/invite.js index 7c1f92001b..4d2a62eb3b 100644 --- a/static/js/invite.js +++ b/static/js/invite.js @@ -1,12 +1,10 @@ -"use strict"; +import autosize from "autosize"; +import ClipboardJS from "clipboard"; -const autosize = require("autosize"); -const ClipboardJS = require("clipboard"); - -const copy_invite_link = require("../templates/copy_invite_link.hbs"); -const render_invitation_failed_error = require("../templates/invitation_failed_error.hbs"); -const render_invite_subscription = require("../templates/invite_subscription.hbs"); -const render_settings_dev_env_email_access = require("../templates/settings/dev_env_email_access.hbs"); +import copy_invite_link from "../templates/copy_invite_link.hbs"; +import render_invitation_failed_error from "../templates/invitation_failed_error.hbs"; +import render_invite_subscription from "../templates/invite_subscription.hbs"; +import render_settings_dev_env_email_access from "../templates/settings/dev_env_email_access.hbs"; function reset_error_messages() { $("#invite_status").hide().text("").removeClass(common.status_classes); @@ -130,7 +128,7 @@ function generate_multiuse_invite() { }); } -exports.get_invite_streams = function () { +export function get_invite_streams() { const streams = stream_data.get_invite_stream_data(); function compare_streams(a, b) { @@ -138,11 +136,11 @@ exports.get_invite_streams = function () { } streams.sort(compare_streams); return streams; -}; +} function update_subscription_checkboxes() { const data = { - streams: exports.get_invite_streams(), + streams: get_invite_streams(), notifications_stream: stream_data.get_notifications_stream(), }; const html = render_invite_subscription(data); @@ -154,7 +152,7 @@ function prepare_form_to_be_shown() { reset_error_messages(); } -exports.launch = function () { +export function launch() { $("#submit-invitation").button(); prepare_form_to_be_shown(); @@ -174,9 +172,9 @@ exports.launch = function () { submit_invitation_form(); } }); -}; +} -exports.initialize = function () { +export function initialize() { $(document).on("click", "#invite_check_all_button", () => { $("#streams_to_add :checkbox").prop("checked", true); }); @@ -212,6 +210,4 @@ exports.initialize = function () { $("#invite-method-choice").show(); reset_error_messages(); }); -}; - -window.invite = exports; +} diff --git a/static/js/ui_init.js b/static/js/ui_init.js index 01af6d1109..759389c1f4 100644 --- a/static/js/ui_init.js +++ b/static/js/ui_init.js @@ -11,6 +11,7 @@ const render_edit_content_button = require("../templates/edit_content_button.hbs const copy_and_paste = require("./copy_and_paste"); const echo = require("./echo"); const emojisets = require("./emojisets"); +const invite = require("./invite"); const markdown_config = require("./markdown_config"); const people = require("./people"); const pm_conversations = require("./pm_conversations");