mirror of https://github.com/zulip/zulip.git
js: Convert static/js/stream_popover.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
b408565111
commit
c71af35461
|
@ -199,7 +199,6 @@
|
|||
"settings_users": false,
|
||||
"starred_messages": false,
|
||||
"stream_list": false,
|
||||
"stream_popover": false,
|
||||
"StripeCheckout": false,
|
||||
"subs": false,
|
||||
"message_view_header": false,
|
||||
|
|
|
@ -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() {},
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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", {});
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -27,7 +27,6 @@ import "../reload";
|
|||
import "../compose_actions";
|
||||
import "../subs";
|
||||
import "../ui";
|
||||
import "../stream_popover";
|
||||
import "../popovers";
|
||||
import "../overlays";
|
||||
import "../typeahead_helper";
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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";
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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");
|
||||
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 * 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;
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue