Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

js: Convert static/js/stream_popover.js to ES6 module.

Anders Kaseorgc71af35461f2
diff --git a/.eslintrc.json b/.eslintrc.json
index fb8386ac5a8..8bd0ab6c2af 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -199,7 +199,6 @@
"settings_users": false,
"starred_messages": false,
"stream_list": false,
- "stream_popover": false,
"StripeCheckout": false,
"subs": false,
"message_view_header": false,
diff --git a/frontend_tests/node_tests/activity.js b/frontend_tests/node_tests/activity.js
index 1842c5809bf..5209393c259 100644
--- a/frontend_tests/node_tests/activity.js
+++ b/frontend_tests/node_tests/activity.js
@@ -58,6 +58,7 @@ const _popovers = {
};
const _stream_popover = {
+ __esModule: true,
show_streamlist_sidebar() {},
};
@@ -78,7 +79,7 @@ rewiremock("../../static/js/pm_list").with(_pm_list);
set_global("popovers", _popovers);
rewiremock("../../static/js/resize").with(_resize);
rewiremock("../../static/js/scroll_util").with(_scroll_util);
-set_global("stream_popover", _stream_popover);
+rewiremock("../../static/js/stream_popover").with(_stream_popover);
set_global("ui", _ui);
set_global("server_events", {
check_for_unsuspend() {},
diff --git a/frontend_tests/node_tests/hotkey.js b/frontend_tests/node_tests/hotkey.js
index 4670421df2b..dc24da575c9 100644
--- a/frontend_tests/node_tests/hotkey.js
+++ b/frontend_tests/node_tests/hotkey.js
@@ -23,7 +23,7 @@ const overlays = set_global("overlays", {
info_overlay_open: () => false,
});
-set_global("stream_popover", {
+rewiremock("../../static/js/stream_popover").with({
stream_popped: () => false,
topic_popped: () => false,
all_messages_popped: () => false,
diff --git a/frontend_tests/node_tests/pm_list.js b/frontend_tests/node_tests/pm_list.js
index b4823744293..d72c5960288 100644
--- a/frontend_tests/node_tests/pm_list.js
+++ b/frontend_tests/node_tests/pm_list.js
@@ -13,7 +13,7 @@ rewiremock("../../static/js/narrow_state").with(narrow_state);
set_global("ui", {
get_content_element: (element) => element,
});
-set_global("stream_popover", {
+rewiremock("../../static/js/stream_popover").with({
hide_topic_popover() {},
});
const unread = set_global("unread", {});
diff --git a/frontend_tests/node_tests/popovers.js b/frontend_tests/node_tests/popovers.js
index 8ea5d403195..5e5d275c918 100644
--- a/frontend_tests/node_tests/popovers.js
+++ b/frontend_tests/node_tests/popovers.js
@@ -29,7 +29,7 @@ set_global("emoji_picker", {
hide_emoji_popover: noop,
});
-set_global("stream_popover", {
+rewiremock("../../static/js/stream_popover").with({
hide_stream_popover: noop,
hide_topic_popover: noop,
hide_all_messages_popover: noop,
diff --git a/frontend_tests/node_tests/stream_search.js b/frontend_tests/node_tests/stream_search.js
index da97f635275..a13d50799bd 100644
--- a/frontend_tests/node_tests/stream_search.js
+++ b/frontend_tests/node_tests/stream_search.js
@@ -19,7 +19,9 @@ rewiremock("../../static/js/resize").with({
});
const popovers = set_global("popovers", {});
-const stream_popover = set_global("stream_popover", {});
+const stream_popover = {__esModule: true};
+
+rewiremock("../../static/js/stream_popover").with(stream_popover);
rewiremock.enable();
diff --git a/static/js/bundles/app.js b/static/js/bundles/app.js
index 7415d4de78e..722b3da8f11 100644
--- a/static/js/bundles/app.js
+++ b/static/js/bundles/app.js
@@ -27,7 +27,6 @@ import "../reload";
import "../compose_actions";
import "../subs";
import "../ui";
-import "../stream_popover";
import "../popovers";
import "../overlays";
import "../typeahead_helper";
diff --git a/static/js/click_handlers.js b/static/js/click_handlers.js
index f9e3822519c..28bb415cd76 100644
--- a/static/js/click_handlers.js
+++ b/static/js/click_handlers.js
@@ -16,6 +16,7 @@ import * as rows from "./rows";
import * as settings_panel_menu from "./settings_panel_menu";
import * as settings_toggle from "./settings_toggle";
import * as stream_edit from "./stream_edit";
+import * as stream_popover from "./stream_popover";
import * as ui_util from "./ui_util";
import * as user_status_ui from "./user_status_ui";
import * as util from "./util";
diff --git a/static/js/global.d.ts b/static/js/global.d.ts
index 523c0d37841..8f4c4a04046 100644
--- a/static/js/global.d.ts
+++ b/static/js/global.d.ts
@@ -72,7 +72,6 @@ declare let settings_user_groups: any;
declare let settings_users: any;
declare let starred_messages: any;
declare let stream_list: any;
-declare let stream_popover: any;
declare let subs: any;
declare let message_view_header: any;
declare let timerender: any;
diff --git a/static/js/hotkey.js b/static/js/hotkey.js
index a761e196471..6dd3b6d47b4 100644
--- a/static/js/hotkey.js
+++ b/static/js/hotkey.js
@@ -13,6 +13,7 @@ const gear_menu = require("./gear_menu");
const lightbox = require("./lightbox");
const message_edit = require("./message_edit");
const muting_ui = require("./muting_ui");
+const stream_popover = require("./stream_popover");
const topic_zoom = require("./topic_zoom");
function do_narrow_action(action) {
diff --git a/static/js/muting_ui.js b/static/js/muting_ui.js
index a4b79b3c3d0..95bdd3c171e 100644
--- a/static/js/muting_ui.js
+++ b/static/js/muting_ui.js
@@ -7,6 +7,7 @@ import * as ListWidget from "./list_widget";
import * as muting from "./muting";
import * as settings_muting from "./settings_muting";
import * as stream_data from "./stream_data";
+import * as stream_popover from "./stream_popover";
import * as unread_ui from "./unread_ui";
function timestamp_ms() {
diff --git a/static/js/pm_list.js b/static/js/pm_list.js
index ddd18561d87..4b9763b6708 100644
--- a/static/js/pm_list.js
+++ b/static/js/pm_list.js
@@ -2,6 +2,7 @@ import * as narrow_state from "./narrow_state";
import * as people from "./people";
import * as pm_conversations from "./pm_conversations";
import * as pm_list_dom from "./pm_list_dom";
+import * as stream_popover from "./stream_popover";
import * as unread_ui from "./unread_ui";
import * as vdom from "./vdom";
diff --git a/static/js/popovers.js b/static/js/popovers.js
index e910bbaa3be..b5fd20ba7e5 100644
--- a/static/js/popovers.js
+++ b/static/js/popovers.js
@@ -30,6 +30,7 @@ const resize = require("./resize");
const rows = require("./rows");
const settings_config = require("./settings_config");
const settings_data = require("./settings_data");
+const stream_popover = require("./stream_popover");
const user_groups = require("./user_groups");
const user_status = require("./user_status");
const user_status_ui = require("./user_status_ui");
diff --git a/static/js/stream_list.js b/static/js/stream_list.js
index e7174f9319f..15db613afd1 100644
--- a/static/js/stream_list.js
+++ b/static/js/stream_list.js
@@ -12,6 +12,7 @@ const resize = require("./resize");
const scroll_util = require("./scroll_util");
const stream_color = require("./stream_color");
const stream_data = require("./stream_data");
+const stream_popover = require("./stream_popover");
const stream_sort = require("./stream_sort");
const topic_list = require("./topic_list");
const topic_zoom = require("./topic_zoom");
diff --git a/static/js/stream_popover.js b/static/js/stream_popover.js
index a69645a0b0a..6a78392fce3 100644
--- a/static/js/stream_popover.js
+++ b/static/js/stream_popover.js
@@ -1,21 +1,19 @@
-"use strict";
-
-const render_all_messages_sidebar_actions = require("../templates/all_messages_sidebar_actions.hbs");
-const render_delete_topic_modal = require("../templates/delete_topic_modal.hbs");
-const render_move_topic_to_stream = require("../templates/move_topic_to_stream.hbs");
-const render_starred_messages_sidebar_actions = require("../templates/starred_messages_sidebar_actions.hbs");
-const render_stream_sidebar_actions = require("../templates/stream_sidebar_actions.hbs");
-const render_topic_sidebar_actions = require("../templates/topic_sidebar_actions.hbs");
-const render_unstar_messages_modal = require("../templates/unstar_messages_modal.hbs");
-
-const channel = require("./channel");
-const message_edit = require("./message_edit");
-const muting = require("./muting");
-const muting_ui = require("./muting_ui");
-const resize = require("./resize");
-const stream_color = require("./stream_color");
-const stream_data = require("./stream_data");
-const ui_util = require("./ui_util");
+import render_all_messages_sidebar_actions from "../templates/all_messages_sidebar_actions.hbs";
+import render_delete_topic_modal from "../templates/delete_topic_modal.hbs";
+import render_move_topic_to_stream from "../templates/move_topic_to_stream.hbs";
+import render_starred_messages_sidebar_actions from "../templates/starred_messages_sidebar_actions.hbs";
+import render_stream_sidebar_actions from "../templates/stream_sidebar_actions.hbs";
+import render_topic_sidebar_actions from "../templates/topic_sidebar_actions.hbs";
+import render_unstar_messages_modal from "../templates/unstar_messages_modal.hbs";
+
+import * as channel from "./channel";
+import * as message_edit from "./message_edit";
+import * as muting from "./muting";
+import * as muting_ui from "./muting_ui";
+import * as resize from "./resize";
+import * as stream_color from "./stream_color";
+import * as stream_data from "./stream_data";
+import * as ui_util from "./ui_util";
// We handle stream popovers and topic popovers in this
// module. Both are popped up from the left sidebar.
@@ -38,25 +36,25 @@ function get_popover_menu_items(sidebar_elem) {
return $("li:not(.divider):visible > a", popover_data.$tip);
}
-exports.stream_sidebar_menu_handle_keyboard = (key) => {
+export function stream_sidebar_menu_handle_keyboard(key) {
const items = get_popover_menu_items(current_stream_sidebar_elem);
popovers.popover_items_handle_keyboard(key, items);
-};
+}
-exports.topic_sidebar_menu_handle_keyboard = (key) => {
+export function topic_sidebar_menu_handle_keyboard(key) {
const items = get_popover_menu_items(current_topic_sidebar_elem);
popovers.popover_items_handle_keyboard(key, items);
-};
+}
-exports.all_messages_sidebar_menu_handle_keyboard = (key) => {
+export function all_messages_sidebar_menu_handle_keyboard(key) {
const items = get_popover_menu_items(all_messages_sidebar_elem);
popovers.popover_items_handle_keyboard(key, items);
-};
+}
-exports.starred_messages_sidebar_menu_handle_keyboard = (key) => {
+export function starred_messages_sidebar_menu_handle_keyboard(key) {
const items = get_popover_menu_items(starred_messages_sidebar_elem);
popovers.popover_items_handle_keyboard(key, items);
-};
+}
function elem_to_stream_id(elem) {
const stream_id = Number.parseInt(elem.attr("data-stream-id"), 10);
@@ -72,61 +70,61 @@ function topic_popover_stream_id(e) {
return elem_to_stream_id($(e.currentTarget));
}
-exports.stream_popped = function () {
+export function stream_popped() {
return current_stream_sidebar_elem !== undefined;
-};
+}
-exports.topic_popped = function () {
+export function topic_popped() {
return current_topic_sidebar_elem !== undefined;
-};
+}
-exports.all_messages_popped = function () {
+export function all_messages_popped() {
return all_messages_sidebar_elem !== undefined;
-};
+}
-exports.starred_messages_popped = function () {
+export function starred_messages_popped() {
return starred_messages_sidebar_elem !== undefined;
-};
+}
-exports.hide_stream_popover = function () {
- if (exports.stream_popped()) {
+export function hide_stream_popover() {
+ if (stream_popped()) {
$(current_stream_sidebar_elem).popover("destroy");
current_stream_sidebar_elem = undefined;
}
-};
+}
-exports.hide_topic_popover = function () {
- if (exports.topic_popped()) {
+export function hide_topic_popover() {
+ if (topic_popped()) {
$(current_topic_sidebar_elem).popover("destroy");
current_topic_sidebar_elem = undefined;
}
-};
+}
-exports.hide_all_messages_popover = function () {
- if (exports.all_messages_popped()) {
+export function hide_all_messages_popover() {
+ if (all_messages_popped()) {
$(all_messages_sidebar_elem).popover("destroy");
all_messages_sidebar_elem = undefined;
}
-};
+}
-exports.hide_starred_messages_popover = function () {
- if (exports.starred_messages_popped()) {
+export function hide_starred_messages_popover() {
+ if (starred_messages_popped()) {
$(starred_messages_sidebar_elem).popover("destroy");
starred_messages_sidebar_elem = undefined;
}
-};
+}
// These are the only two functions that is really shared by the
// two popovers, so we could split out topic stuff to
// another module pretty easily.
-exports.show_streamlist_sidebar = function () {
+export function show_streamlist_sidebar() {
$(".app-main .column-left").addClass("expanded");
resize.resize_page_components();
-};
+}
-exports.hide_streamlist_sidebar = function () {
+export function hide_streamlist_sidebar() {
$(".app-main .column-left").removeClass("expanded");
-};
+}
function stream_popover_sub(e) {
const elem = $(e.currentTarget).parents("ul");
@@ -173,14 +171,14 @@ function build_stream_popover(opts) {
const elt = opts.elt;
const stream_id = opts.stream_id;
- if (exports.stream_popped() && current_stream_sidebar_elem === elt) {
+ if (stream_popped() && current_stream_sidebar_elem === elt) {
// If the popover is already shown, clicking again should toggle it.
- exports.hide_stream_popover();
+ hide_stream_popover();
return;
}
popovers.hide_all();
- exports.show_streamlist_sidebar();
+ show_streamlist_sidebar();
const content = render_stream_sidebar_actions({
stream: stream_data.get_sub_by_id(stream_id),
@@ -209,9 +207,9 @@ function build_topic_popover(opts) {
const stream_id = opts.stream_id;
const topic_name = opts.topic_name;
- if (exports.topic_popped() && current_topic_sidebar_elem === elt) {
+ if (topic_popped() && current_topic_sidebar_elem === elt) {
// If the popover is already shown, clicking again should toggle it.
- exports.hide_topic_popover();
+ hide_topic_popover();
return;
}
@@ -222,7 +220,7 @@ function build_topic_popover(opts) {
}
popovers.hide_all();
- exports.show_streamlist_sidebar();
+ show_streamlist_sidebar();
const is_muted = muting.is_topic_muted(sub.stream_id, topic_name);
const can_mute_topic = !is_muted;
@@ -253,8 +251,8 @@ function build_topic_popover(opts) {
function build_all_messages_popover(e) {
const elt = e.target;
- if (exports.all_messages_popped() && all_messages_sidebar_elem === elt) {
- exports.hide_all_messages_popover();
+ if (all_messages_popped() && all_messages_sidebar_elem === elt) {
+ hide_all_messages_popover();
e.stopPropagation();
return;
}
@@ -278,8 +276,8 @@ function build_all_messages_popover(e) {
function build_starred_messages_popover(e) {
const elt = e.target;
- if (exports.starred_messages_popped() && starred_messages_sidebar_elem === elt) {
- exports.hide_starred_messages_popover();
+ if (starred_messages_popped() && starred_messages_sidebar_elem === elt) {
+ hide_starred_messages_popover();
e.stopPropagation();
return;
}
@@ -323,7 +321,7 @@ function build_move_topic_to_stream_popover(e, current_stream_id, topic_name) {
notify_old_thread: message_edit.notify_old_thread_default,
};
- exports.hide_topic_popover();
+ hide_topic_popover();
$("#move-a-topic-modal-holder").html(render_move_topic_to_stream(args));
@@ -339,7 +337,7 @@ function build_move_topic_to_stream_popover(e, current_stream_id, topic_name) {
$("#move_topic_modal").modal("show");
}
-exports.register_click_handlers = function () {
+export function register_click_handlers() {
$("#stream_filters").on("click", ".stream-sidebar-menu-icon", (e) => {
e.stopPropagation();
@@ -376,15 +374,15 @@ exports.register_click_handlers = function () {
build_starred_messages_popover,
);
- exports.register_stream_handlers();
- exports.register_topic_handlers();
-};
+ register_stream_handlers();
+ register_topic_handlers();
+}
-exports.register_stream_handlers = function () {
+export function register_stream_handlers() {
// Stream settings
$("body").on("click", ".open_stream_settings", (e) => {
const sub = stream_popover_sub(e);
- exports.hide_stream_popover();
+ hide_stream_popover();
const stream_edit_hash = hash_util.stream_edit_uri(sub);
hashchange.go_to_location(stream_edit_hash);
@@ -393,7 +391,7 @@ exports.register_stream_handlers = function () {
// Pin/unpin
$("body").on("click", ".pin_to_top", (e) => {
const sub = stream_popover_sub(e);
- exports.hide_stream_popover();
+ hide_stream_popover();
subs.toggle_pin_to_top_stream(sub);
e.stopPropagation();
});
@@ -401,21 +399,21 @@ exports.register_stream_handlers = function () {
// Mark all messages in stream as read
$("body").on("click", ".mark_stream_as_read", (e) => {
const sub = stream_popover_sub(e);
- exports.hide_stream_popover();
+ hide_stream_popover();
unread_ops.mark_stream_as_read(sub.stream_id);
e.stopPropagation();
});
// Mark all messages as read
$("body").on("click", "#mark_all_messages_as_read", (e) => {
- exports.hide_all_messages_popover();
+ hide_all_messages_popover();
unread_ops.mark_all_as_read();
e.stopPropagation();
});
// Unstar all messages
$("body").on("click", "#unstar_all_messages", (e) => {
- exports.hide_starred_messages_popover();
+ hide_starred_messages_popover();
e.preventDefault();
e.stopPropagation();
$(".left-sidebar-modal-holder").empty();
@@ -431,7 +429,7 @@ exports.register_stream_handlers = function () {
// Toggle displaying starred message count
$("body").on("click", "#toggle_display_starred_msg_count", (e) => {
- exports.hide_starred_messages_popover();
+ hide_starred_messages_popover();
e.preventDefault();
e.stopPropagation();
const starred_msg_counts = page_params.starred_message_counts;
@@ -445,7 +443,7 @@ exports.register_stream_handlers = function () {
// Mute/unmute
$("body").on("click", ".toggle_stream_muted", (e) => {
const sub = stream_popover_sub(e);
- exports.hide_stream_popover();
+ hide_stream_popover();
subs.set_muted(sub, !sub.is_muted);
e.stopPropagation();
});
@@ -477,14 +475,14 @@ exports.register_stream_handlers = function () {
});
$(".streams_popover").on("click", "a.sp-cancel", () => {
- exports.hide_stream_popover();
+ hide_stream_popover();
});
if ($(window).width() <= 768) {
$(".popover-inner").hide().fadeIn(300);
$(".popover").addClass("colorpicker-popover");
}
});
-};
+}
function topic_popover_sub(e) {
const stream_id = topic_popover_stream_id(e);
@@ -501,10 +499,10 @@ function topic_popover_sub(e) {
return sub;
}
-exports.register_topic_handlers = function () {
+export function register_topic_handlers() {
// Narrow to topic
$("body").on("click", ".narrow_to_topic", (e) => {
- exports.hide_topic_popover();
+ hide_topic_popover();
const sub = topic_popover_sub(e);
if (!sub) {
@@ -556,7 +554,7 @@ exports.register_topic_handlers = function () {
}
const topic = $(e.currentTarget).attr("data-topic-name");
- exports.hide_topic_popover();
+ hide_topic_popover();
unread_ops.mark_topic_as_read(stream_id, topic);
e.stopPropagation();
});
@@ -573,7 +571,7 @@ exports.register_topic_handlers = function () {
topic_name: topic,
};
- exports.hide_topic_popover();
+ hide_topic_popover();
$("#delete-topic-modal-holder").html(render_delete_topic_modal(args));
@@ -687,6 +685,4 @@ exports.register_topic_handlers = function () {
},
});
});
-};
-
-window.stream_popover = exports;
+}
diff --git a/static/js/topic_list.js b/static/js/topic_list.js
index af3b05e22fa..5d39f595132 100644
--- a/static/js/topic_list.js
+++ b/static/js/topic_list.js
@@ -5,6 +5,7 @@ import render_more_topics_spinner from "../templates/more_topics_spinner.hbs";
import render_topic_list_item from "../templates/topic_list_item.hbs";
import * as stream_data from "./stream_data";
+import * as stream_popover from "./stream_popover";
import * as stream_topic_history from "./stream_topic_history";
import * as topic_list_data from "./topic_list_data";
import * as vdom from "./vdom";
diff --git a/static/js/user_search.js b/static/js/user_search.js
index 7803c568069..9662d662cff 100644
--- a/static/js/user_search.js
+++ b/static/js/user_search.js
@@ -1,4 +1,5 @@
import * as resize from "./resize";
+import * as stream_popover from "./stream_popover";
export class UserSearch {
// This is mostly view code to manage the user search widget