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

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2021-02-27 16:02:37 -08:00 committed by Tim Abbott
parent b408565111
commit c71af35461
17 changed files with 93 additions and 89 deletions

View File

@ -199,7 +199,6 @@
"settings_users": false, "settings_users": false,
"starred_messages": false, "starred_messages": false,
"stream_list": false, "stream_list": false,
"stream_popover": false,
"StripeCheckout": false, "StripeCheckout": false,
"subs": false, "subs": false,
"message_view_header": false, "message_view_header": false,

View File

@ -58,6 +58,7 @@ const _popovers = {
}; };
const _stream_popover = { const _stream_popover = {
__esModule: true,
show_streamlist_sidebar() {}, show_streamlist_sidebar() {},
}; };
@ -78,7 +79,7 @@ rewiremock("../../static/js/pm_list").with(_pm_list);
set_global("popovers", _popovers); set_global("popovers", _popovers);
rewiremock("../../static/js/resize").with(_resize); rewiremock("../../static/js/resize").with(_resize);
rewiremock("../../static/js/scroll_util").with(_scroll_util); 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("ui", _ui);
set_global("server_events", { set_global("server_events", {
check_for_unsuspend() {}, check_for_unsuspend() {},

View File

@ -23,7 +23,7 @@ const overlays = set_global("overlays", {
info_overlay_open: () => false, info_overlay_open: () => false,
}); });
set_global("stream_popover", { rewiremock("../../static/js/stream_popover").with({
stream_popped: () => false, stream_popped: () => false,
topic_popped: () => false, topic_popped: () => false,
all_messages_popped: () => false, all_messages_popped: () => false,

View File

@ -13,7 +13,7 @@ rewiremock("../../static/js/narrow_state").with(narrow_state);
set_global("ui", { set_global("ui", {
get_content_element: (element) => element, get_content_element: (element) => element,
}); });
set_global("stream_popover", { rewiremock("../../static/js/stream_popover").with({
hide_topic_popover() {}, hide_topic_popover() {},
}); });
const unread = set_global("unread", {}); const unread = set_global("unread", {});

View File

@ -29,7 +29,7 @@ set_global("emoji_picker", {
hide_emoji_popover: noop, hide_emoji_popover: noop,
}); });
set_global("stream_popover", { rewiremock("../../static/js/stream_popover").with({
hide_stream_popover: noop, hide_stream_popover: noop,
hide_topic_popover: noop, hide_topic_popover: noop,
hide_all_messages_popover: noop, hide_all_messages_popover: noop,

View File

@ -19,7 +19,9 @@ rewiremock("../../static/js/resize").with({
}); });
const popovers = set_global("popovers", {}); 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(); rewiremock.enable();

View File

@ -27,7 +27,6 @@ import "../reload";
import "../compose_actions"; import "../compose_actions";
import "../subs"; import "../subs";
import "../ui"; import "../ui";
import "../stream_popover";
import "../popovers"; import "../popovers";
import "../overlays"; import "../overlays";
import "../typeahead_helper"; import "../typeahead_helper";

View File

@ -16,6 +16,7 @@ import * as rows from "./rows";
import * as settings_panel_menu from "./settings_panel_menu"; import * as settings_panel_menu from "./settings_panel_menu";
import * as settings_toggle from "./settings_toggle"; import * as settings_toggle from "./settings_toggle";
import * as stream_edit from "./stream_edit"; import * as stream_edit from "./stream_edit";
import * as stream_popover from "./stream_popover";
import * as ui_util from "./ui_util"; import * as ui_util from "./ui_util";
import * as user_status_ui from "./user_status_ui"; import * as user_status_ui from "./user_status_ui";
import * as util from "./util"; import * as util from "./util";

View File

@ -72,7 +72,6 @@ declare let settings_user_groups: any;
declare let settings_users: any; declare let settings_users: any;
declare let starred_messages: any; declare let starred_messages: any;
declare let stream_list: any; declare let stream_list: any;
declare let stream_popover: any;
declare let subs: any; declare let subs: any;
declare let message_view_header: any; declare let message_view_header: any;
declare let timerender: any; declare let timerender: any;

View File

@ -13,6 +13,7 @@ const gear_menu = require("./gear_menu");
const lightbox = require("./lightbox"); const lightbox = require("./lightbox");
const message_edit = require("./message_edit"); const message_edit = require("./message_edit");
const muting_ui = require("./muting_ui"); const muting_ui = require("./muting_ui");
const stream_popover = require("./stream_popover");
const topic_zoom = require("./topic_zoom"); const topic_zoom = require("./topic_zoom");
function do_narrow_action(action) { function do_narrow_action(action) {

View File

@ -7,6 +7,7 @@ import * as ListWidget from "./list_widget";
import * as muting from "./muting"; import * as muting from "./muting";
import * as settings_muting from "./settings_muting"; import * as settings_muting from "./settings_muting";
import * as stream_data from "./stream_data"; import * as stream_data from "./stream_data";
import * as stream_popover from "./stream_popover";
import * as unread_ui from "./unread_ui"; import * as unread_ui from "./unread_ui";
function timestamp_ms() { function timestamp_ms() {

View File

@ -2,6 +2,7 @@ import * as narrow_state from "./narrow_state";
import * as people from "./people"; import * as people from "./people";
import * as pm_conversations from "./pm_conversations"; import * as pm_conversations from "./pm_conversations";
import * as pm_list_dom from "./pm_list_dom"; 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 unread_ui from "./unread_ui";
import * as vdom from "./vdom"; import * as vdom from "./vdom";

View File

@ -30,6 +30,7 @@ const resize = require("./resize");
const rows = require("./rows"); const rows = require("./rows");
const settings_config = require("./settings_config"); const settings_config = require("./settings_config");
const settings_data = require("./settings_data"); const settings_data = require("./settings_data");
const stream_popover = require("./stream_popover");
const user_groups = require("./user_groups"); const user_groups = require("./user_groups");
const user_status = require("./user_status"); const user_status = require("./user_status");
const user_status_ui = require("./user_status_ui"); const user_status_ui = require("./user_status_ui");

View File

@ -12,6 +12,7 @@ const resize = require("./resize");
const scroll_util = require("./scroll_util"); const scroll_util = require("./scroll_util");
const stream_color = require("./stream_color"); const stream_color = require("./stream_color");
const stream_data = require("./stream_data"); const stream_data = require("./stream_data");
const stream_popover = require("./stream_popover");
const stream_sort = require("./stream_sort"); const stream_sort = require("./stream_sort");
const topic_list = require("./topic_list"); const topic_list = require("./topic_list");
const topic_zoom = require("./topic_zoom"); const topic_zoom = require("./topic_zoom");

View File

@ -1,21 +1,19 @@
"use strict"; 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";
const render_all_messages_sidebar_actions = require("../templates/all_messages_sidebar_actions.hbs"); import * as channel from "./channel";
const render_delete_topic_modal = require("../templates/delete_topic_modal.hbs"); import * as message_edit from "./message_edit";
const render_move_topic_to_stream = require("../templates/move_topic_to_stream.hbs"); import * as muting from "./muting";
const render_starred_messages_sidebar_actions = require("../templates/starred_messages_sidebar_actions.hbs"); import * as muting_ui from "./muting_ui";
const render_stream_sidebar_actions = require("../templates/stream_sidebar_actions.hbs"); import * as resize from "./resize";
const render_topic_sidebar_actions = require("../templates/topic_sidebar_actions.hbs"); import * as stream_color from "./stream_color";
const render_unstar_messages_modal = require("../templates/unstar_messages_modal.hbs"); import * as stream_data from "./stream_data";
import * as ui_util from "./ui_util";
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");
// We handle stream popovers and topic popovers in this // We handle stream popovers and topic popovers in this
// module. Both are popped up from the left sidebar. // 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); 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); const items = get_popover_menu_items(current_stream_sidebar_elem);
popovers.popover_items_handle_keyboard(key, items); 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); const items = get_popover_menu_items(current_topic_sidebar_elem);
popovers.popover_items_handle_keyboard(key, items); 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); const items = get_popover_menu_items(all_messages_sidebar_elem);
popovers.popover_items_handle_keyboard(key, items); 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); const items = get_popover_menu_items(starred_messages_sidebar_elem);
popovers.popover_items_handle_keyboard(key, items); popovers.popover_items_handle_keyboard(key, items);
}; }
function elem_to_stream_id(elem) { function elem_to_stream_id(elem) {
const stream_id = Number.parseInt(elem.attr("data-stream-id"), 10); 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)); return elem_to_stream_id($(e.currentTarget));
} }
exports.stream_popped = function () { export function stream_popped() {
return current_stream_sidebar_elem !== undefined; return current_stream_sidebar_elem !== undefined;
}; }
exports.topic_popped = function () { export function topic_popped() {
return current_topic_sidebar_elem !== undefined; return current_topic_sidebar_elem !== undefined;
}; }
exports.all_messages_popped = function () { export function all_messages_popped() {
return all_messages_sidebar_elem !== undefined; return all_messages_sidebar_elem !== undefined;
}; }
exports.starred_messages_popped = function () { export function starred_messages_popped() {
return starred_messages_sidebar_elem !== undefined; return starred_messages_sidebar_elem !== undefined;
}; }
exports.hide_stream_popover = function () { export function hide_stream_popover() {
if (exports.stream_popped()) { if (stream_popped()) {
$(current_stream_sidebar_elem).popover("destroy"); $(current_stream_sidebar_elem).popover("destroy");
current_stream_sidebar_elem = undefined; current_stream_sidebar_elem = undefined;
} }
}; }
exports.hide_topic_popover = function () { export function hide_topic_popover() {
if (exports.topic_popped()) { if (topic_popped()) {
$(current_topic_sidebar_elem).popover("destroy"); $(current_topic_sidebar_elem).popover("destroy");
current_topic_sidebar_elem = undefined; current_topic_sidebar_elem = undefined;
} }
}; }
exports.hide_all_messages_popover = function () { export function hide_all_messages_popover() {
if (exports.all_messages_popped()) { if (all_messages_popped()) {
$(all_messages_sidebar_elem).popover("destroy"); $(all_messages_sidebar_elem).popover("destroy");
all_messages_sidebar_elem = undefined; all_messages_sidebar_elem = undefined;
} }
}; }
exports.hide_starred_messages_popover = function () { export function hide_starred_messages_popover() {
if (exports.starred_messages_popped()) { if (starred_messages_popped()) {
$(starred_messages_sidebar_elem).popover("destroy"); $(starred_messages_sidebar_elem).popover("destroy");
starred_messages_sidebar_elem = undefined; starred_messages_sidebar_elem = undefined;
} }
}; }
// These are the only two functions that is really shared by the // These are the only two functions that is really shared by the
// two popovers, so we could split out topic stuff to // two popovers, so we could split out topic stuff to
// another module pretty easily. // another module pretty easily.
exports.show_streamlist_sidebar = function () { export function show_streamlist_sidebar() {
$(".app-main .column-left").addClass("expanded"); $(".app-main .column-left").addClass("expanded");
resize.resize_page_components(); resize.resize_page_components();
}; }
exports.hide_streamlist_sidebar = function () { export function hide_streamlist_sidebar() {
$(".app-main .column-left").removeClass("expanded"); $(".app-main .column-left").removeClass("expanded");
}; }
function stream_popover_sub(e) { function stream_popover_sub(e) {
const elem = $(e.currentTarget).parents("ul"); const elem = $(e.currentTarget).parents("ul");
@ -173,14 +171,14 @@ function build_stream_popover(opts) {
const elt = opts.elt; const elt = opts.elt;
const stream_id = opts.stream_id; 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. // If the popover is already shown, clicking again should toggle it.
exports.hide_stream_popover(); hide_stream_popover();
return; return;
} }
popovers.hide_all(); popovers.hide_all();
exports.show_streamlist_sidebar(); show_streamlist_sidebar();
const content = render_stream_sidebar_actions({ const content = render_stream_sidebar_actions({
stream: stream_data.get_sub_by_id(stream_id), 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 stream_id = opts.stream_id;
const topic_name = opts.topic_name; 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. // If the popover is already shown, clicking again should toggle it.
exports.hide_topic_popover(); hide_topic_popover();
return; return;
} }
@ -222,7 +220,7 @@ function build_topic_popover(opts) {
} }
popovers.hide_all(); popovers.hide_all();
exports.show_streamlist_sidebar(); show_streamlist_sidebar();
const is_muted = muting.is_topic_muted(sub.stream_id, topic_name); const is_muted = muting.is_topic_muted(sub.stream_id, topic_name);
const can_mute_topic = !is_muted; const can_mute_topic = !is_muted;
@ -253,8 +251,8 @@ function build_topic_popover(opts) {
function build_all_messages_popover(e) { function build_all_messages_popover(e) {
const elt = e.target; const elt = e.target;
if (exports.all_messages_popped() && all_messages_sidebar_elem === elt) { if (all_messages_popped() && all_messages_sidebar_elem === elt) {
exports.hide_all_messages_popover(); hide_all_messages_popover();
e.stopPropagation(); e.stopPropagation();
return; return;
} }
@ -278,8 +276,8 @@ function build_all_messages_popover(e) {
function build_starred_messages_popover(e) { function build_starred_messages_popover(e) {
const elt = e.target; const elt = e.target;
if (exports.starred_messages_popped() && starred_messages_sidebar_elem === elt) { if (starred_messages_popped() && starred_messages_sidebar_elem === elt) {
exports.hide_starred_messages_popover(); hide_starred_messages_popover();
e.stopPropagation(); e.stopPropagation();
return; 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, 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)); $("#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"); $("#move_topic_modal").modal("show");
} }
exports.register_click_handlers = function () { export function register_click_handlers() {
$("#stream_filters").on("click", ".stream-sidebar-menu-icon", (e) => { $("#stream_filters").on("click", ".stream-sidebar-menu-icon", (e) => {
e.stopPropagation(); e.stopPropagation();
@ -376,15 +374,15 @@ exports.register_click_handlers = function () {
build_starred_messages_popover, build_starred_messages_popover,
); );
exports.register_stream_handlers(); register_stream_handlers();
exports.register_topic_handlers(); register_topic_handlers();
}; }
exports.register_stream_handlers = function () { export function register_stream_handlers() {
// Stream settings // Stream settings
$("body").on("click", ".open_stream_settings", (e) => { $("body").on("click", ".open_stream_settings", (e) => {
const sub = stream_popover_sub(e); const sub = stream_popover_sub(e);
exports.hide_stream_popover(); hide_stream_popover();
const stream_edit_hash = hash_util.stream_edit_uri(sub); const stream_edit_hash = hash_util.stream_edit_uri(sub);
hashchange.go_to_location(stream_edit_hash); hashchange.go_to_location(stream_edit_hash);
@ -393,7 +391,7 @@ exports.register_stream_handlers = function () {
// Pin/unpin // Pin/unpin
$("body").on("click", ".pin_to_top", (e) => { $("body").on("click", ".pin_to_top", (e) => {
const sub = stream_popover_sub(e); const sub = stream_popover_sub(e);
exports.hide_stream_popover(); hide_stream_popover();
subs.toggle_pin_to_top_stream(sub); subs.toggle_pin_to_top_stream(sub);
e.stopPropagation(); e.stopPropagation();
}); });
@ -401,21 +399,21 @@ exports.register_stream_handlers = function () {
// Mark all messages in stream as read // Mark all messages in stream as read
$("body").on("click", ".mark_stream_as_read", (e) => { $("body").on("click", ".mark_stream_as_read", (e) => {
const sub = stream_popover_sub(e); const sub = stream_popover_sub(e);
exports.hide_stream_popover(); hide_stream_popover();
unread_ops.mark_stream_as_read(sub.stream_id); unread_ops.mark_stream_as_read(sub.stream_id);
e.stopPropagation(); e.stopPropagation();
}); });
// Mark all messages as read // Mark all messages as read
$("body").on("click", "#mark_all_messages_as_read", (e) => { $("body").on("click", "#mark_all_messages_as_read", (e) => {
exports.hide_all_messages_popover(); hide_all_messages_popover();
unread_ops.mark_all_as_read(); unread_ops.mark_all_as_read();
e.stopPropagation(); e.stopPropagation();
}); });
// Unstar all messages // Unstar all messages
$("body").on("click", "#unstar_all_messages", (e) => { $("body").on("click", "#unstar_all_messages", (e) => {
exports.hide_starred_messages_popover(); hide_starred_messages_popover();
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
$(".left-sidebar-modal-holder").empty(); $(".left-sidebar-modal-holder").empty();
@ -431,7 +429,7 @@ exports.register_stream_handlers = function () {
// Toggle displaying starred message count // Toggle displaying starred message count
$("body").on("click", "#toggle_display_starred_msg_count", (e) => { $("body").on("click", "#toggle_display_starred_msg_count", (e) => {
exports.hide_starred_messages_popover(); hide_starred_messages_popover();
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
const starred_msg_counts = page_params.starred_message_counts; const starred_msg_counts = page_params.starred_message_counts;
@ -445,7 +443,7 @@ exports.register_stream_handlers = function () {
// Mute/unmute // Mute/unmute
$("body").on("click", ".toggle_stream_muted", (e) => { $("body").on("click", ".toggle_stream_muted", (e) => {
const sub = stream_popover_sub(e); const sub = stream_popover_sub(e);
exports.hide_stream_popover(); hide_stream_popover();
subs.set_muted(sub, !sub.is_muted); subs.set_muted(sub, !sub.is_muted);
e.stopPropagation(); e.stopPropagation();
}); });
@ -477,14 +475,14 @@ exports.register_stream_handlers = function () {
}); });
$(".streams_popover").on("click", "a.sp-cancel", () => { $(".streams_popover").on("click", "a.sp-cancel", () => {
exports.hide_stream_popover(); hide_stream_popover();
}); });
if ($(window).width() <= 768) { if ($(window).width() <= 768) {
$(".popover-inner").hide().fadeIn(300); $(".popover-inner").hide().fadeIn(300);
$(".popover").addClass("colorpicker-popover"); $(".popover").addClass("colorpicker-popover");
} }
}); });
}; }
function topic_popover_sub(e) { function topic_popover_sub(e) {
const stream_id = topic_popover_stream_id(e); const stream_id = topic_popover_stream_id(e);
@ -501,10 +499,10 @@ function topic_popover_sub(e) {
return sub; return sub;
} }
exports.register_topic_handlers = function () { export function register_topic_handlers() {
// Narrow to topic // Narrow to topic
$("body").on("click", ".narrow_to_topic", (e) => { $("body").on("click", ".narrow_to_topic", (e) => {
exports.hide_topic_popover(); hide_topic_popover();
const sub = topic_popover_sub(e); const sub = topic_popover_sub(e);
if (!sub) { if (!sub) {
@ -556,7 +554,7 @@ exports.register_topic_handlers = function () {
} }
const topic = $(e.currentTarget).attr("data-topic-name"); const topic = $(e.currentTarget).attr("data-topic-name");
exports.hide_topic_popover(); hide_topic_popover();
unread_ops.mark_topic_as_read(stream_id, topic); unread_ops.mark_topic_as_read(stream_id, topic);
e.stopPropagation(); e.stopPropagation();
}); });
@ -573,7 +571,7 @@ exports.register_topic_handlers = function () {
topic_name: topic, topic_name: topic,
}; };
exports.hide_topic_popover(); hide_topic_popover();
$("#delete-topic-modal-holder").html(render_delete_topic_modal(args)); $("#delete-topic-modal-holder").html(render_delete_topic_modal(args));
@ -687,6 +685,4 @@ exports.register_topic_handlers = function () {
}, },
}); });
}); });
}; }
window.stream_popover = exports;

View File

@ -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 render_topic_list_item from "../templates/topic_list_item.hbs";
import * as stream_data from "./stream_data"; 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 stream_topic_history from "./stream_topic_history";
import * as topic_list_data from "./topic_list_data"; import * as topic_list_data from "./topic_list_data";
import * as vdom from "./vdom"; import * as vdom from "./vdom";

View File

@ -1,4 +1,5 @@
import * as resize from "./resize"; import * as resize from "./resize";
import * as stream_popover from "./stream_popover";
export class UserSearch { export class UserSearch {
// This is mostly view code to manage the user search widget // This is mostly view code to manage the user search widget