Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
js: Convert static/js/condense.js to ES6 module.
Anders Kaseorg5ba7153a3b35
diff --git a/.eslintrc.json b/.eslintrc.jsonindex 62142acbe4b..82e841ed82b 100644--- a/.eslintrc.json+++ b/.eslintrc.json@@ -138,7 +138,6 @@"compose_actions": false,"compose_ui": false,"composebox_typeahead": false,- "condense": false,"confirm_dialog": false,"csrf_token": false,"current_msg_list": true,diff --git a/frontend_tests/node_tests/hotkey.js b/frontend_tests/node_tests/hotkey.jsindex bda5374b04c..39f5102abb4 100644--- a/frontend_tests/node_tests/hotkey.js+++ b/frontend_tests/node_tests/hotkey.js@@ -66,7 +66,8 @@ const page_params = set_global("page_params", {});set_global("document", "document-stub");const compose_actions = set_global("compose_actions", {});-const condense = set_global("condense", {});+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", {diff --git a/frontend_tests/node_tests/message_events.js b/frontend_tests/node_tests/message_events.jsindex 91f5b3a47a3..a16706c91dd 100644--- a/frontend_tests/node_tests/message_events.js+++ b/frontend_tests/node_tests/message_events.js@@ -7,7 +7,8 @@ const rewiremock = require("rewiremock/node");const {set_global, zrequire} = require("../zjsunit/namespace");const {run_test} = require("../zjsunit/test");-const condense = set_global("condense", {});+const condense = {__esModule: true};+rewiremock("../../static/js/condense").with(condense);set_global("current_msg_list", {});const message_edit = {__esModule: true};rewiremock("../../static/js/message_edit").with(message_edit);diff --git a/frontend_tests/node_tests/ui_init.js b/frontend_tests/node_tests/ui_init.jsindex 344ecf4e12b..1af1ada6660 100644--- a/frontend_tests/node_tests/ui_init.js+++ b/frontend_tests/node_tests/ui_init.js@@ -108,7 +108,6 @@ rewiremock.enable();const util = zrequire("util");zrequire("hash_util");-zrequire("condense");zrequire("lightbox");zrequire("overlays");zrequire("message_view_header");diff --git a/static/js/bundles/app.js b/static/js/bundles/app.jsindex 03a35c7104b..c66d74a9517 100644--- a/static/js/bundles/app.js+++ b/static/js/bundles/app.js@@ -26,7 +26,6 @@ import "../narrow";import "../reload";import "../compose_actions";import "../subs";-import "../condense";import "../resize";import "../list_widget";import "../floating_recipient_bar";diff --git a/static/js/condense.js b/static/js/condense.jsindex 8faadb9ff0f..4649dd9d753 100644--- a/static/js/condense.js+++ b/static/js/condense.js@@ -1,7 +1,5 @@-"use strict";--const message_viewport = require("./message_viewport");-const rows = require("./rows");+import * as message_viewport from "./message_viewport";+import * as rows from "./rows";/*This library implements two related, similar concepts:@@ -39,7 +37,7 @@ function uncondense_row(row) {show_condense_link(row);}-exports.uncollapse = function (row) {+export function uncollapse(row) {// Uncollapse a message, restoring the condensed message [More] or// [Condense] link if necessary.const message = current_msg_list.get(rows.id(row));@@ -72,9 +70,9 @@ exports.uncollapse = function (row) {process_row(row);process_row(home_row);-};+}-exports.collapse = function (row) {+export function collapse(row) {// Collapse a message, hiding the condensed message [More] or// [Condense] link if necessary.const message = current_msg_list.get(rows.id(row));@@ -100,9 +98,9 @@ exports.collapse = function (row) {process_row(row);process_row(home_row);-};+}-exports.toggle_collapse = function (message) {+export function toggle_collapse(message) {if (message.is_me_message) {// Disabled temporarily because /me messages don't have a// styling for collapsing /me messages (they only recently@@ -130,29 +128,29 @@ exports.toggle_collapse = function (message) {if (is_condensable) {message.condensed = true;content.addClass("condensed");- exports.show_message_expander(row);+ show_message_expander(row);row.find(".message_condenser").hide();}- exports.uncollapse(row);+ uncollapse(row);} else {if (is_condensed) {message.condensed = false;content.removeClass("condensed");- exports.hide_message_expander(row);+ hide_message_expander(row);row.find(".message_condenser").show();} else {- exports.collapse(row);+ collapse(row);}}-};+}-exports.clear_message_content_height_cache = function () {+export function clear_message_content_height_cache() {_message_content_height_cache.clear();-};+}-exports.un_cache_message_content_height = function (message_id) {+export function un_cache_message_content_height(message_id) {_message_content_height_cache.delete(message_id);-};+}function get_message_height(elem, message_id) {if (_message_content_height_cache.has(message_id)) {@@ -165,19 +163,19 @@ function get_message_height(elem, message_id) {return height;}-exports.hide_message_expander = function (row) {+export function hide_message_expander(row) {if (row.find(".could-be-condensed").length !== 0) {row.find(".message_expander").hide();}-};+}-exports.show_message_expander = function (row) {+export function show_message_expander(row) {if (row.find(".could-be-condensed").length !== 0) {row.find(".message_expander").show();}-};+}-exports.condense_and_collapse = function (elems) {+export function condense_and_collapse(elems) {const height_cutoff = message_viewport.height() * 0.65;for (const elem of elems) {@@ -236,9 +234,9 @@ exports.condense_and_collapse = function (elems) {$(elem).find(".message_expander").show();}}-};+}-exports.initialize = function () {+export function initialize() {$("#message_feed_container").on("click", ".message_expander", function (e) {// Expanding a message can mean either uncollapsing or// uncondensing it.@@ -247,7 +245,7 @@ exports.initialize = function () {const content = row.find(".message_content");if (message.collapsed) {// Uncollapse.- exports.uncollapse(row);+ uncollapse(row);} else if (content.hasClass("condensed")) {// Uncondense (show the full long message).message.condensed = false;@@ -266,6 +264,4 @@ exports.initialize = function () {e.stopPropagation();e.preventDefault();});-};--window.condense = exports;+}diff --git a/static/js/global.d.ts b/static/js/global.d.tsindex 8d3d1684f84..c0494d69788 100644--- a/static/js/global.d.ts+++ b/static/js/global.d.ts@@ -16,7 +16,6 @@ declare let click_handlers: any;declare let compose_actions: any;declare let composebox_typeahead: any;declare let compose_ui: any;-declare let condense: any;declare let confirm_dialog: any;declare let csrf_token: any;declare let current_msg_list: any;diff --git a/static/js/hotkey.js b/static/js/hotkey.jsindex 8ffd7503c56..e5bd2d928a1 100644--- a/static/js/hotkey.js+++ b/static/js/hotkey.js@@ -5,6 +5,7 @@ const emoji = require("../shared/js/emoji");const common = require("./common");const compose = require("./compose");const compose_state = require("./compose_state");+const condense = require("./condense");const copy_and_paste = require("./copy_and_paste");const drafts = require("./drafts");const feedback_widget = require("./feedback_widget");diff --git a/static/js/message_edit.js b/static/js/message_edit.jsindex 43c3466750f..71050208641 100644--- a/static/js/message_edit.js+++ b/static/js/message_edit.js@@ -5,6 +5,7 @@ import render_topic_edit_form from "../templates/topic_edit_form.hbs";import * as channel from "./channel";import * as compose from "./compose";+import * as condense from "./condense";import * as echo from "./echo";import * as loading from "./loading";import * as markdown from "./markdown";diff --git a/static/js/message_events.js b/static/js/message_events.jsindex 9d5fdeae8c0..8bf16e5fa57 100644--- a/static/js/message_events.js+++ b/static/js/message_events.js@@ -4,6 +4,7 @@ const alert_words = require("./alert_words");const channel = require("./channel");const compose_fade = require("./compose_fade");const compose_state = require("./compose_state");+const condense = require("./condense");const huddle_data = require("./huddle_data");const message_edit = require("./message_edit");const message_edit_history = require("./message_edit_history");diff --git a/static/js/message_list_view.js b/static/js/message_list_view.jsindex f4cf64a32bc..8cb7f8562ce 100644--- a/static/js/message_list_view.js+++ b/static/js/message_list_view.js@@ -8,6 +8,7 @@ import render_single_message from "../templates/single_message.hbs";import * as compose from "./compose";import * as compose_fade from "./compose_fade";+import * as condense from "./condense";import * as message_edit from "./message_edit";import * as message_viewport from "./message_viewport";import * as narrow_state from "./narrow_state";diff --git a/static/js/narrow.js b/static/js/narrow.jsindex 0f9e78512bf..777a2f200a7 100644--- a/static/js/narrow.js+++ b/static/js/narrow.js@@ -4,6 +4,7 @@ const channel = require("./channel");const compose = require("./compose");const compose_fade = require("./compose_fade");const compose_state = require("./compose_state");+const condense = require("./condense");const {Filter} = require("./filter");const message_edit = require("./message_edit");const {MessageListData} = require("./message_list_data");diff --git a/static/js/popovers.js b/static/js/popovers.jsindex 570d84a1015..2c3e29cfe85 100644--- a/static/js/popovers.js+++ b/static/js/popovers.js@@ -17,6 +17,7 @@ const render_user_info_popover_title = require("../templates/user_info_popover_tconst render_user_profile_modal = require("../templates/user_profile_modal.hbs");const compose_state = require("./compose_state");+const condense = require("./condense");const feature_flags = require("./feature_flags");const message_edit = require("./message_edit");const message_edit_history = require("./message_edit_history");diff --git a/static/js/resize.js b/static/js/resize.jsindex ad4997313fc..528b7d03329 100644--- a/static/js/resize.js+++ b/static/js/resize.js@@ -2,6 +2,7 @@const autosize = require("autosize");+const condense = require("./condense");const message_viewport = require("./message_viewport");const util = require("./util");diff --git a/static/js/ui_init.js b/static/js/ui_init.jsindex 028b8ac198e..b16c8a2da68 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.hbsconst alert_words = require("./alert_words");const compose = require("./compose");const compose_pm_pill = require("./compose_pm_pill");+const condense = require("./condense");const copy_and_paste = require("./copy_and_paste");const drafts = require("./drafts");const echo = require("./echo");