mirror of https://github.com/zulip/zulip.git
js: Convert static/js/message_view_header.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
d36c6f23f6
commit
5438a04b84
|
@ -158,7 +158,6 @@
|
|||
"stream_list": false,
|
||||
"StripeCheckout": false,
|
||||
"subs": false,
|
||||
"message_view_header": false,
|
||||
"typing_events": false,
|
||||
"ui": false,
|
||||
"ui_init": false,
|
||||
|
|
|
@ -36,7 +36,8 @@ set_global("page_params", {});
|
|||
const search = {__esModule: true};
|
||||
rewiremock("../../static/js/search").with(search);
|
||||
const stream_list = set_global("stream_list", {});
|
||||
const message_view_header = set_global("message_view_header", {});
|
||||
const message_view_header = {__esModule: true};
|
||||
rewiremock("../../static/js/message_view_header").with(message_view_header);
|
||||
const top_left_corner = {__esModule: true};
|
||||
rewiremock("../../static/js/top_left_corner").with(top_left_corner);
|
||||
const typing_events = set_global("typing_events", {});
|
||||
|
|
|
@ -25,7 +25,7 @@ set_global("narrow", {
|
|||
rewiremock("../../static/js/notifications").with({
|
||||
redraw_title: noop,
|
||||
});
|
||||
set_global("message_view_header", {
|
||||
rewiremock("../../static/js/message_view_header").with({
|
||||
render_title_area: noop,
|
||||
});
|
||||
|
||||
|
|
|
@ -39,7 +39,6 @@ rewiremock.enable();
|
|||
const search = zrequire("search");
|
||||
const search_pill = zrequire("search_pill");
|
||||
const {Filter} = zrequire("Filter", "js/filter");
|
||||
zrequire("message_view_header");
|
||||
|
||||
run_test("clear_search_form", () => {
|
||||
$("#search_query").val("noise");
|
||||
|
|
|
@ -33,7 +33,6 @@ set_global("setTimeout", (func) => func());
|
|||
rewiremock.enable();
|
||||
|
||||
const search = zrequire("search");
|
||||
zrequire("message_view_header");
|
||||
|
||||
run_test("update_button_visibility", () => {
|
||||
const search_query = $("#search_query");
|
||||
|
|
|
@ -113,7 +113,6 @@ rewiremock.enable();
|
|||
|
||||
const util = zrequire("util");
|
||||
|
||||
zrequire("message_view_header");
|
||||
zrequire("search_pill_widget");
|
||||
zrequire("unread");
|
||||
zrequire("bot_data");
|
||||
|
|
|
@ -37,7 +37,6 @@ import "../templates";
|
|||
import "../dropdown_list_widget";
|
||||
import "../settings_profile_fields";
|
||||
import "../settings";
|
||||
import "../message_view_header";
|
||||
import "../bot_data";
|
||||
import "../reactions";
|
||||
import "../typing_events";
|
||||
|
|
|
@ -29,7 +29,6 @@ declare let search_pill_widget: any;
|
|||
declare let settings_profile_fields: any;
|
||||
declare let stream_list: any;
|
||||
declare let subs: any;
|
||||
declare let message_view_header: any;
|
||||
declare let typing_events: any;
|
||||
declare let ui: any;
|
||||
declare let unread: any;
|
||||
|
|
|
@ -15,6 +15,7 @@ import * as lightbox from "./lightbox";
|
|||
import * as list_util from "./list_util";
|
||||
import * as message_edit from "./message_edit";
|
||||
import * as message_flags from "./message_flags";
|
||||
import * as message_view_header from "./message_view_header";
|
||||
import * as muting_ui from "./muting_ui";
|
||||
import * as navigate from "./navigate";
|
||||
import * as overlays from "./overlays";
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
"use strict";
|
||||
import render_message_view_header from "../templates/message_view_header.hbs";
|
||||
|
||||
const render_message_view_header = require("../templates/message_view_header.hbs");
|
||||
|
||||
const narrow_state = require("./narrow_state");
|
||||
const peer_data = require("./peer_data");
|
||||
const rendered_markdown = require("./rendered_markdown");
|
||||
const search = require("./search");
|
||||
import * as narrow_state from "./narrow_state";
|
||||
import * as peer_data from "./peer_data";
|
||||
import * as rendered_markdown from "./rendered_markdown";
|
||||
import * as search from "./search";
|
||||
|
||||
function get_formatted_sub_count(sub_count) {
|
||||
if (sub_count >= 1000) {
|
||||
|
@ -59,13 +57,13 @@ function make_message_view_header(filter) {
|
|||
return message_view_header;
|
||||
}
|
||||
|
||||
exports.colorize_message_view_header = function () {
|
||||
export function colorize_message_view_header() {
|
||||
const filter = narrow_state.filter();
|
||||
if (filter === undefined || !filter._sub) {
|
||||
return;
|
||||
}
|
||||
$("#message_view_header .stream > .fa").css("color", filter._sub.color);
|
||||
};
|
||||
}
|
||||
|
||||
function append_and_display_title_area(message_view_header_data) {
|
||||
const message_view_header_elem = $("#message_view_header");
|
||||
|
@ -73,7 +71,7 @@ function append_and_display_title_area(message_view_header_data) {
|
|||
const rendered = render_message_view_header(message_view_header_data);
|
||||
message_view_header_elem.append(rendered);
|
||||
if (message_view_header_data.stream_settings_link) {
|
||||
exports.colorize_message_view_header();
|
||||
colorize_message_view_header();
|
||||
}
|
||||
message_view_header_elem.removeClass("notdisplayed");
|
||||
const content = message_view_header_elem.find("span.rendered_markdown");
|
||||
|
@ -119,22 +117,22 @@ function build_message_view_header(filter) {
|
|||
// This makes sure we don't waste time appending
|
||||
// message_view_header on a template where it's never used
|
||||
if (filter && !filter.is_common_narrow()) {
|
||||
exports.open_search_bar_and_close_narrow_description();
|
||||
open_search_bar_and_close_narrow_description();
|
||||
} else {
|
||||
const message_view_header_data = make_message_view_header(filter);
|
||||
append_and_display_title_area(message_view_header_data);
|
||||
bind_title_area_handlers();
|
||||
if (page_params.search_pills_enabled && $("#search_query").is(":focus")) {
|
||||
exports.open_search_bar_and_close_narrow_description();
|
||||
open_search_bar_and_close_narrow_description();
|
||||
} else {
|
||||
exports.close_search_bar_and_open_narrow_description();
|
||||
close_search_bar_and_open_narrow_description();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// we rely entirely on this function to ensure
|
||||
// the searchbar has the right text.
|
||||
exports.reset_searchbox_text = function () {
|
||||
export function reset_searchbox_text() {
|
||||
let search_string = narrow_state.search_string();
|
||||
if (search_string !== "") {
|
||||
if (!page_params.search_pills_enabled && !narrow_state.filter().is_search()) {
|
||||
|
@ -143,58 +141,56 @@ exports.reset_searchbox_text = function () {
|
|||
}
|
||||
$("#search_query").val(search_string);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.exit_search = function () {
|
||||
export function exit_search() {
|
||||
const filter = narrow_state.filter();
|
||||
if (!filter || filter.is_common_narrow()) {
|
||||
// for common narrows, we change the UI (and don't redirect)
|
||||
exports.close_search_bar_and_open_narrow_description();
|
||||
close_search_bar_and_open_narrow_description();
|
||||
} else {
|
||||
// for "searching narrows", we redirect
|
||||
window.location.href = filter.generate_redirect_url();
|
||||
}
|
||||
$(".app").trigger("focus");
|
||||
};
|
||||
}
|
||||
|
||||
exports.initialize = function () {
|
||||
exports.render_title_area();
|
||||
export function initialize() {
|
||||
render_title_area();
|
||||
|
||||
// register searchbar click handler
|
||||
$("#search_exit").on("click", (e) => {
|
||||
message_view_header.exit_search();
|
||||
exit_search();
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
exports.render_title_area = function () {
|
||||
export function render_title_area() {
|
||||
const filter = narrow_state.filter();
|
||||
build_message_view_header(filter);
|
||||
};
|
||||
}
|
||||
|
||||
// This function checks if "modified_sub" which is the stream whose values
|
||||
// have been updated is the same as the stream which is currently
|
||||
// narrowed (filter._sub) and rerenders if necessary
|
||||
exports.maybe_rerender_title_area_for_stream = function (modified_sub) {
|
||||
export function maybe_rerender_title_area_for_stream(modified_sub) {
|
||||
const filter = narrow_state.filter();
|
||||
if (filter && filter._sub && filter._sub.stream_id === modified_sub.stream_id) {
|
||||
message_view_header.render_title_area();
|
||||
render_title_area();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.open_search_bar_and_close_narrow_description = function () {
|
||||
exports.reset_searchbox_text();
|
||||
export function open_search_bar_and_close_narrow_description() {
|
||||
reset_searchbox_text();
|
||||
$(".navbar-search").addClass("expanded");
|
||||
$("#message_view_header").addClass("hidden");
|
||||
};
|
||||
}
|
||||
|
||||
exports.close_search_bar_and_open_narrow_description = function () {
|
||||
export function close_search_bar_and_open_narrow_description() {
|
||||
const filter = narrow_state.filter();
|
||||
if (!(filter && !filter.is_common_narrow())) {
|
||||
$(".navbar-search").removeClass("expanded");
|
||||
$("#message_view_header").removeClass("hidden");
|
||||
}
|
||||
};
|
||||
|
||||
window.message_view_header = exports;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ const message_fetch = require("./message_fetch");
|
|||
const {MessageListData} = require("./message_list_data");
|
||||
const message_scroll = require("./message_scroll");
|
||||
const message_store = require("./message_store");
|
||||
const message_view_header = require("./message_view_header");
|
||||
const narrow_state = require("./narrow_state");
|
||||
const notifications = require("./notifications");
|
||||
const people = require("./people");
|
||||
|
|
|
@ -10,6 +10,7 @@ const ListWidget = require("./list_widget");
|
|||
const {localstorage} = require("./localstorage");
|
||||
const message_store = require("./message_store");
|
||||
const message_util = require("./message_util");
|
||||
const message_view_header = require("./message_view_header");
|
||||
const muting = require("./muting");
|
||||
const narrow_state = require("./narrow_state");
|
||||
const navigate = require("./navigate");
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import {Filter} from "./filter";
|
||||
import * as message_view_header from "./message_view_header";
|
||||
import * as narrow_state from "./narrow_state";
|
||||
import * as search_pill from "./search_pill";
|
||||
import * as search_suggestion from "./search_suggestion";
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import _ from "lodash";
|
||||
|
||||
import * as colorspace from "./colorspace";
|
||||
import * as message_view_header from "./message_view_header";
|
||||
|
||||
export const default_color = "#c2c2c2";
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import * as color_data from "./color_data";
|
||||
import * as message_util from "./message_util";
|
||||
import * as message_view_header from "./message_view_header";
|
||||
import * as narrow_state from "./narrow_state";
|
||||
import * as overlays from "./overlays";
|
||||
import * as peer_data from "./peer_data";
|
||||
|
|
|
@ -14,6 +14,7 @@ const hash_util = require("./hash_util");
|
|||
const hashchange = require("./hashchange");
|
||||
const loading = require("./loading");
|
||||
const message_live_update = require("./message_live_update");
|
||||
const message_view_header = require("./message_view_header");
|
||||
const overlays = require("./overlays");
|
||||
const people = require("./people");
|
||||
const scroll_util = require("./scroll_util");
|
||||
|
|
|
@ -28,6 +28,7 @@ const markdown_config = require("./markdown_config");
|
|||
const message_edit = require("./message_edit");
|
||||
const message_fetch = require("./message_fetch");
|
||||
const message_scroll = require("./message_scroll");
|
||||
const message_view_header = require("./message_view_header");
|
||||
const message_viewport = require("./message_viewport");
|
||||
const muting = require("./muting");
|
||||
const navigate = require("./navigate");
|
||||
|
|
Loading…
Reference in New Issue