Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
js: Convert static/js/hashchange.js to ES6 module.
Anders Kaseorge30df92944d8
diff --git a/.eslintrc.json b/.eslintrc.jsonindex 37f2002ba3d..f8be8ba297b 100644--- a/.eslintrc.json+++ b/.eslintrc.json@@ -144,7 +144,6 @@"emoji_picker": false,"favicon": false,"flatpickr": false,- "hashchange": false,"helpers": false,"history": false,"home_msg_list": false,diff --git a/frontend_tests/node_tests/hotkey.js b/frontend_tests/node_tests/hotkey.jsindex 0132b1fb927..7ce9d36b3bf 100644--- a/frontend_tests/node_tests/hotkey.js+++ b/frontend_tests/node_tests/hotkey.js@@ -78,9 +78,11 @@ const condense = {__esModule: true};rewiremock("../../static/js/condense").with(condense);const drafts = {__esModule: true};rewiremock("../../static/js/drafts").with(drafts);-const hashchange = set_global("hashchange", {+const hashchange = {+ __esModule: true,in_recent_topics_hash: () => false,-});+};+rewiremock("../../static/js/hashchange").with(hashchange);rewiremock("../../static/js/info_overlay").with({});const lightbox = {__esModule: true};rewiremock("../../static/js/lightbox").with(lightbox);diff --git a/frontend_tests/node_tests/narrow.js b/frontend_tests/node_tests/narrow.jsindex 4a7c9ac53b0..3e213ed5c45 100644--- a/frontend_tests/node_tests/narrow.js+++ b/frontend_tests/node_tests/narrow.js@@ -19,7 +19,6 @@ rewiremock("../../static/js/resize").with({rewiremock.enable();const hash_util = zrequire("hash_util");-zrequire("hashchange");const compose_state = zrequire("compose_state");const narrow_state = zrequire("narrow_state");const people = zrequire("people");diff --git a/frontend_tests/node_tests/narrow_activate.js b/frontend_tests/node_tests/narrow_activate.jsindex eaa67cd181a..61dc8b3e3c1 100644--- a/frontend_tests/node_tests/narrow_activate.js+++ b/frontend_tests/node_tests/narrow_activate.js@@ -17,7 +17,8 @@ const compose = {__esModule: true};rewiremock("../../static/js/compose").with(compose);const compose_actions = set_global("compose_actions", {});set_global("current_msg_list", {});-const hashchange = set_global("hashchange", {});+const hashchange = {__esModule: true};+rewiremock("../../static/js/hashchange").with(hashchange);set_global("home_msg_list", {});const message_fetch = set_global("message_fetch", {});const message_list = set_global("message_list", {diff --git a/frontend_tests/node_tests/stream_edit.js b/frontend_tests/node_tests/stream_edit.jsindex faadd8d16f7..0f07b837f09 100644--- a/frontend_tests/node_tests/stream_edit.js+++ b/frontend_tests/node_tests/stream_edit.js@@ -13,7 +13,7 @@ const noop = () => {};stub_templates(() => noop);rewiremock("../../static/js/channel").with({});-set_global("hashchange", {update_browser_history: noop});+rewiremock("../../static/js/hashchange").with({update_browser_history: noop});rewiremock("../../static/js/hash_util").with({stream_edit_uri: noop,by_stream_uri: noop,diff --git a/frontend_tests/node_tests/ui_init.js b/frontend_tests/node_tests/ui_init.jsindex d57034c8e8a..4c1e6d9697b 100644--- a/frontend_tests/node_tests/ui_init.js+++ b/frontend_tests/node_tests/ui_init.js@@ -73,7 +73,7 @@ rewiremock("../../static/js/compose_pm_pill").with({initialize() {}});rewiremock("../../static/js/drafts").with({initialize() {}});set_global("emoji_picker", {initialize() {}});rewiremock("../../static/js/gear_menu").with({initialize() {}});-set_global("hashchange", {initialize() {}});+rewiremock("../../static/js/hashchange").with({initialize() {}});set_global("hotspots", {initialize() {}});// Accesses home_msg_list, which is a lot of complexity to set upset_global("message_fetch", {initialize() {}});diff --git a/static/js/bundles/app.js b/static/js/bundles/app.jsindex 4c0886ae3c8..0d5ef047bde 100644--- a/static/js/bundles/app.js+++ b/static/js/bundles/app.js@@ -30,7 +30,6 @@ import "../ui";import "../composebox_typeahead";import "../hotkey";import "../notifications";-import "../hashchange";import "../message_flags";import "../starred_messages";import "../alert_words_ui";diff --git a/static/js/click_handlers.js b/static/js/click_handlers.jsindex 201c5134c81..253acdddf47 100644--- a/static/js/click_handlers.js+++ b/static/js/click_handlers.js@@ -10,6 +10,7 @@ import * as channel from "./channel";import * as compose from "./compose";import * as compose_state from "./compose_state";import * as hash_util from "./hash_util";+import * as hashchange from "./hashchange";import * as message_edit from "./message_edit";import * as message_edit_history from "./message_edit_history";import * as muting_ui from "./muting_ui";diff --git a/static/js/desktop_integration.js b/static/js/desktop_integration.jsindex cdd68150a53..9ec6ad2ff71 100644--- a/static/js/desktop_integration.js+++ b/static/js/desktop_integration.js@@ -1,3 +1,5 @@+import * as hashchange from "./hashchange";+if (window.electron_bridge !== undefined) {window.electron_bridge.on_event("logout", () => {$("#logout_form").trigger("submit");@@ -11,5 +13,3 @@ if (window.electron_bridge !== undefined) {hashchange.go_to_location("settings/notifications");});}--export {};diff --git a/static/js/drafts.js b/static/js/drafts.jsindex d860a2229f6..e30495e0869 100644--- a/static/js/drafts.js+++ b/static/js/drafts.js@@ -6,6 +6,7 @@ import render_draft_table_body from "../templates/draft_table_body.hbs";import * as compose from "./compose";import * as compose_fade from "./compose_fade";import * as compose_state from "./compose_state";+import * as hashchange from "./hashchange";import {localstorage} from "./localstorage";import * as markdown from "./markdown";import * as overlays from "./overlays";diff --git a/static/js/gear_menu.js b/static/js/gear_menu.jsindex c1eedd37505..4c589fb2e02 100644--- a/static/js/gear_menu.js+++ b/static/js/gear_menu.js@@ -1,3 +1,4 @@+import * as hashchange from "./hashchange";import * as message_viewport from "./message_viewport";import * as navigate from "./navigate";diff --git a/static/js/global.d.ts b/static/js/global.d.tsindex 7bf9177ba86..e13871ad680 100644--- a/static/js/global.d.ts+++ b/static/js/global.d.ts@@ -21,7 +21,6 @@ declare let current_msg_list: any;declare let emoji: any;declare let emoji_picker: any;declare let favicon: any;-declare let hashchange: any;declare let helpers: any;declare let home_msg_list: any;declare let hotspots: any;diff --git a/static/js/hashchange.js b/static/js/hashchange.jsindex fdab46a13b8..a356b35c470 100644--- a/static/js/hashchange.js+++ b/static/js/hashchange.js@@ -1,17 +1,15 @@-"use strict";--const drafts = require("./drafts");-const floating_recipient_bar = require("./floating_recipient_bar");-const hash_util = require("./hash_util");-const info_overlay = require("./info_overlay");-const invite = require("./invite");-const message_viewport = require("./message_viewport");-const navigate = require("./navigate");-const overlays = require("./overlays");-const search = require("./search");-const settings_panel_menu = require("./settings_panel_menu");-const top_left_corner = require("./top_left_corner");-const ui_util = require("./ui_util");+import * as drafts from "./drafts";+import * as floating_recipient_bar from "./floating_recipient_bar";+import * as hash_util from "./hash_util";+import * as info_overlay from "./info_overlay";+import * as invite from "./invite";+import * as message_viewport from "./message_viewport";+import * as navigate from "./navigate";+import * as overlays from "./overlays";+import * as search from "./search";+import * as settings_panel_menu from "./settings_panel_menu";+import * as top_left_corner from "./top_left_corner";+import * as ui_util from "./ui_util";// Read https://zulip.readthedocs.io/en/latest/subsystems/hashchange-system.html// or locally: docs/subsystems/hashchange-system.md@@ -55,26 +53,26 @@ function maybe_hide_recent_topics() {return false;}-exports.in_recent_topics_hash = function () {+export function in_recent_topics_hash() {return ["recent_topics", "#", ""].includes(window.location.hash);-};+}-exports.changehash = function (newhash) {+export function changehash(newhash) {if (changing_hash) {return;}maybe_hide_recent_topics();message_viewport.stop_auto_scrolling();set_hash(newhash);-};+}-exports.save_narrow = function (operators) {+export function save_narrow(operators) {if (changing_hash) {return;}const new_hash = hash_util.operators_to_hash(operators);- exports.changehash(new_hash);-};+ changehash(new_hash);+}function activate_home_tab() {const coming_from_recent_topics = maybe_hide_recent_topics();@@ -294,7 +292,7 @@ function hashchanged(from_reload, e) {return ret;}-exports.update_browser_history = function (new_hash) {+export function update_browser_history(new_hash) {const old_hash = window.location.hash;if (!new_hash.startsWith("#")) {@@ -314,9 +312,9 @@ exports.update_browser_history = function (new_hash) {state.old_hash = old_hash;state.is_internal_change = true;window.location.hash = new_hash;-};+}-exports.replace_hash = function (hash) {+export function replace_hash(hash) {if (!window.history.replaceState) {// We may have strange behavior with the back button.blueslip.warn("browser does not support replaceState");@@ -325,30 +323,28 @@ exports.replace_hash = function (hash) {const url = get_full_url(hash);window.history.replaceState(null, null, url);-};+}-exports.go_to_location = function (hash) {+export function go_to_location(hash) {// Call this function when you WANT the hashchanged// function to run.window.location.hash = hash;-};+}-exports.initialize = function () {+export function initialize() {$(window).on("hashchange", (e) => {hashchanged(false, e.originalEvent);});hashchanged(true);-};+}-exports.exit_overlay = function (callback) {+export function exit_overlay(callback) {if (is_overlay_hash(window.location.hash)) {ui_util.blur_active_element();const new_hash = state.hash_before_overlay || "#";- exports.update_browser_history(new_hash);+ update_browser_history(new_hash);if (typeof callback === "function") {callback();}}-};--window.hashchange = exports;+}diff --git a/static/js/hotkey.js b/static/js/hotkey.jsindex 26b133b6bcf..ab9d0667452 100644--- a/static/js/hotkey.js+++ b/static/js/hotkey.js@@ -8,6 +8,7 @@ import * as copy_and_paste from "./copy_and_paste";import * as drafts from "./drafts";import * as feedback_widget from "./feedback_widget";import * as gear_menu from "./gear_menu";+import * as hashchange from "./hashchange";import * as lightbox from "./lightbox";import * as list_util from "./list_util";import * as message_edit from "./message_edit";diff --git a/static/js/info_overlay.js b/static/js/info_overlay.jsindex 30390a0c6ec..0878f00fd95 100644--- a/static/js/info_overlay.js+++ b/static/js/info_overlay.js@@ -1,5 +1,6 @@import * as common from "./common";import * as components from "./components";+import * as hashchange from "./hashchange";import * as keydown_util from "./keydown_util";import * as overlays from "./overlays";import * as popovers from "./popovers";diff --git a/static/js/invite.js b/static/js/invite.jsindex 215ce14da19..e9caa7057f4 100644--- a/static/js/invite.js+++ b/static/js/invite.js@@ -8,6 +8,7 @@ import render_settings_dev_env_email_access from "../templates/settings/dev_env_import * as channel from "./channel";import * as common from "./common";+import * as hashchange from "./hashchange";import * as overlays from "./overlays";import * as stream_data from "./stream_data";import * as ui_report from "./ui_report";diff --git a/static/js/narrow.js b/static/js/narrow.jsindex e56a255e681..8e07e44010c 100644--- a/static/js/narrow.js+++ b/static/js/narrow.js@@ -6,6 +6,7 @@ const compose_fade = require("./compose_fade");const compose_state = require("./compose_state");const condense = require("./condense");const {Filter} = require("./filter");+const hashchange = require("./hashchange");const message_edit = require("./message_edit");const {MessageListData} = require("./message_list_data");const message_scroll = require("./message_scroll");diff --git a/static/js/overlays.js b/static/js/overlays.jsindex 20112c474b4..a13b3be1bdd 100644--- a/static/js/overlays.js+++ b/static/js/overlays.js@@ -1,3 +1,4 @@+import * as hashchange from "./hashchange";import * as popovers from "./popovers";let active_overlay;diff --git a/static/js/reload.js b/static/js/reload.jsindex 8b900ef0a1f..1353103e6f7 100644--- a/static/js/reload.js+++ b/static/js/reload.js@@ -1,5 +1,6 @@import * as compose from "./compose";import * as compose_state from "./compose_state";+import * as hashchange from "./hashchange";import {localstorage} from "./localstorage";import * as narrow_state from "./narrow_state";import * as reload_state from "./reload_state";diff --git a/static/js/search_pill_widget.js b/static/js/search_pill_widget.jsindex 794a145c0df..3865f28ed66 100644--- a/static/js/search_pill_widget.js+++ b/static/js/search_pill_widget.js@@ -1,5 +1,6 @@"use strict";+const hashchange = require("./hashchange");const search_pill = require("./search_pill");exports.initialize = function () {diff --git a/static/js/settings_panel_menu.js b/static/js/settings_panel_menu.jsindex 7c472ac6089..504d45a44e2 100644--- a/static/js/settings_panel_menu.js+++ b/static/js/settings_panel_menu.js@@ -1,3 +1,4 @@+import * as hashchange from "./hashchange";import * as keydown_util from "./keydown_util";import * as popovers from "./popovers";diff --git a/static/js/stream_edit.js b/static/js/stream_edit.jsindex 9257b225860..75d8ec4242d 100644--- a/static/js/stream_edit.js+++ b/static/js/stream_edit.js@@ -6,6 +6,7 @@ import render_subscription_stream_privacy_modal from "../templates/subscription_import * as channel from "./channel";import * as hash_util from "./hash_util";+import * as hashchange from "./hashchange";import * as ListWidget from "./list_widget";import * as narrow_state from "./narrow_state";import * as overlays from "./overlays";diff --git a/static/js/stream_popover.js b/static/js/stream_popover.jsindex c4592a830bf..0aac62b9330 100644--- a/static/js/stream_popover.js+++ b/static/js/stream_popover.js@@ -8,6 +8,7 @@ import render_unstar_messages_modal from "../templates/unstar_messages_modal.hbsimport * as channel from "./channel";import * as hash_util from "./hash_util";+import * as hashchange from "./hashchange";import * as message_edit from "./message_edit";import * as muting from "./muting";import * as muting_ui from "./muting_ui";diff --git a/static/js/subs.js b/static/js/subs.jsindex e29c546120d..807b01b10fb 100644--- a/static/js/subs.js+++ b/static/js/subs.js@@ -11,6 +11,7 @@ const channel = require("./channel");const components = require("./components");const compose_state = require("./compose_state");const hash_util = require("./hash_util");+const hashchange = require("./hashchange");const loading = require("./loading");const message_live_update = require("./message_live_update");const overlays = require("./overlays");diff --git a/static/js/ui_init.js b/static/js/ui_init.jsindex ced25f6a3d1..e61258225cb 100644--- a/static/js/ui_init.js+++ b/static/js/ui_init.js@@ -18,6 +18,7 @@ const drafts = require("./drafts");const echo = require("./echo");const emojisets = require("./emojisets");const gear_menu = require("./gear_menu");+const hashchange = require("./hashchange");const invite = require("./invite");const lightbox = require("./lightbox");const markdown = require("./markdown");diff --git a/static/js/zcommand.js b/static/js/zcommand.jsindex efa9f151377..dfbb22067a9 100644--- a/static/js/zcommand.js+++ b/static/js/zcommand.js@@ -3,6 +3,7 @@ import marked from "../third/marked/lib/marked";import * as channel from "./channel";import * as common from "./common";import * as feedback_widget from "./feedback_widget";+import * as hashchange from "./hashchange";import * as night_mode from "./night_mode";import * as scroll_bar from "./scroll_bar";