2021-03-11 05:43:45 +01:00
|
|
|
import $ from "jquery";
|
2021-02-28 01:00:56 +01:00
|
|
|
import _ from "lodash";
|
2021-02-25 02:45:26 +01:00
|
|
|
import tippy from "tippy.js";
|
2021-02-28 01:00:56 +01:00
|
|
|
import WinChan from "winchan";
|
2020-07-28 00:52:14 +02:00
|
|
|
|
2014-03-14 15:30:29 +01:00
|
|
|
// You won't find every click handler here, but it's a good place to start!
|
|
|
|
|
2021-02-28 01:00:56 +01:00
|
|
|
import render_buddy_list_tooltip_content from "../templates/buddy_list_tooltip_content.hbs";
|
|
|
|
|
2021-02-28 01:13:42 +01:00
|
|
|
import * as activity from "./activity";
|
2021-03-16 23:38:59 +01:00
|
|
|
import * as blueslip from "./blueslip";
|
2021-03-22 16:09:12 +01:00
|
|
|
import * as browser_history from "./browser_history";
|
2021-02-28 01:12:35 +01:00
|
|
|
import * as buddy_data from "./buddy_data";
|
2021-02-28 01:00:56 +01:00
|
|
|
import * as channel from "./channel";
|
|
|
|
import * as compose from "./compose";
|
2021-02-28 21:32:22 +01:00
|
|
|
import * as compose_actions from "./compose_actions";
|
2021-02-28 01:00:56 +01:00
|
|
|
import * as compose_state from "./compose_state";
|
2021-02-25 02:45:26 +01:00
|
|
|
import {media_breakpoints_num} from "./css_variables";
|
2021-02-28 01:26:16 +01:00
|
|
|
import * as emoji_picker from "./emoji_picker";
|
2021-02-28 01:07:13 +01:00
|
|
|
import * as hash_util from "./hash_util";
|
2021-02-28 01:15:02 +01:00
|
|
|
import * as hotspots from "./hotspots";
|
2021-04-13 06:51:54 +02:00
|
|
|
import {$t} from "./i18n";
|
2021-02-28 01:00:56 +01:00
|
|
|
import * as message_edit from "./message_edit";
|
|
|
|
import * as message_edit_history from "./message_edit_history";
|
2021-02-28 01:08:13 +01:00
|
|
|
import * as message_flags from "./message_flags";
|
2021-03-30 02:21:21 +02:00
|
|
|
import * as message_lists from "./message_lists";
|
2021-02-28 01:10:03 +01:00
|
|
|
import * as message_store from "./message_store";
|
2021-02-28 01:00:56 +01:00
|
|
|
import * as muting_ui from "./muting_ui";
|
2021-02-28 21:31:57 +01:00
|
|
|
import * as narrow from "./narrow";
|
2021-02-28 01:06:34 +01:00
|
|
|
import * as notifications from "./notifications";
|
2021-02-28 01:03:46 +01:00
|
|
|
import * as overlays from "./overlays";
|
2021-03-25 22:35:45 +01:00
|
|
|
import {page_params} from "./page_params";
|
2021-02-28 01:03:09 +01:00
|
|
|
import * as popovers from "./popovers";
|
2021-02-28 01:25:00 +01:00
|
|
|
import * as reactions from "./reactions";
|
2021-02-28 01:27:48 +01:00
|
|
|
import * as recent_topics from "./recent_topics";
|
2021-02-28 01:00:56 +01:00
|
|
|
import * as rows from "./rows";
|
2021-02-28 01:11:47 +01:00
|
|
|
import * as server_events from "./server_events";
|
2021-02-28 01:00:56 +01:00
|
|
|
import * as settings_panel_menu from "./settings_panel_menu";
|
2021-02-28 01:01:33 +01:00
|
|
|
import * as settings_toggle from "./settings_toggle";
|
2021-02-28 01:00:56 +01:00
|
|
|
import * as stream_edit from "./stream_edit";
|
2021-02-28 21:31:02 +01:00
|
|
|
import * as stream_list from "./stream_list";
|
2021-02-28 01:02:37 +01:00
|
|
|
import * as stream_popover from "./stream_popover";
|
2021-02-28 01:00:56 +01:00
|
|
|
import * as ui_util from "./ui_util";
|
2021-02-28 21:30:08 +01:00
|
|
|
import * as unread_ops from "./unread_ops";
|
2021-02-28 01:00:56 +01:00
|
|
|
import * as user_status_ui from "./user_status_ui";
|
|
|
|
import * as util from "./util";
|
2020-07-24 06:02:07 +02:00
|
|
|
|
2021-02-28 01:00:56 +01:00
|
|
|
export function initialize() {
|
2014-03-14 15:30:29 +01:00
|
|
|
// MESSAGE CLICKING
|
|
|
|
|
2017-07-31 21:45:39 +02:00
|
|
|
function initialize_long_tap() {
|
2019-11-02 00:06:25 +01:00
|
|
|
const MS_DELAY = 750;
|
|
|
|
const meta = {
|
2017-07-31 21:45:39 +02:00
|
|
|
touchdown: false,
|
2018-06-11 16:52:41 +02:00
|
|
|
current_target: undefined,
|
2017-07-31 21:45:39 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
$("#main_div").on("touchstart", ".messagebox", function () {
|
|
|
|
meta.touchdown = true;
|
|
|
|
meta.invalid = false;
|
2019-11-02 00:06:25 +01:00
|
|
|
const id = rows.id($(this).closest(".message_row"));
|
2018-06-11 16:52:41 +02:00
|
|
|
meta.current_target = id;
|
|
|
|
if (!id) {
|
|
|
|
return;
|
|
|
|
}
|
2021-03-30 02:21:21 +02:00
|
|
|
message_lists.current.select_id(id);
|
2020-07-02 01:45:54 +02:00
|
|
|
setTimeout(() => {
|
2018-06-11 16:52:41 +02:00
|
|
|
// The algorithm to trigger long tap is that first, we check
|
|
|
|
// whether the message is still touched after MS_DELAY ms and
|
|
|
|
// the user isn't scrolling the messages(see other touch event
|
|
|
|
// handlers to see how these meta variables are handled).
|
|
|
|
// Later we check whether after MS_DELAY the user is still
|
|
|
|
// long touching the same message as it can be possible that
|
|
|
|
// user touched another message within MS_DELAY period.
|
2020-12-22 11:26:39 +01:00
|
|
|
if (meta.touchdown === true && !meta.invalid && id === meta.current_target) {
|
|
|
|
$(this).trigger("longtap");
|
2017-07-31 21:45:39 +02:00
|
|
|
}
|
2020-07-02 01:45:54 +02:00
|
|
|
}, MS_DELAY);
|
2017-07-31 21:45:39 +02:00
|
|
|
});
|
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
$("#main_div").on("touchend", ".messagebox", () => {
|
2017-07-31 21:45:39 +02:00
|
|
|
meta.touchdown = false;
|
|
|
|
});
|
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
$("#main_div").on("touchmove", ".messagebox", () => {
|
2017-07-31 21:45:39 +02:00
|
|
|
meta.invalid = true;
|
|
|
|
});
|
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
$("#main_div").on("contextmenu", ".messagebox", (e) => {
|
2017-07-31 21:45:39 +02:00
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// this initializes the trigger that will give off the longtap event, which
|
|
|
|
// there is no point in running if we are on desktop since this isn't a
|
|
|
|
// standard event that we would want to support.
|
|
|
|
if (util.is_mobile()) {
|
|
|
|
initialize_long_tap();
|
|
|
|
}
|
|
|
|
|
2020-07-02 00:35:02 +02:00
|
|
|
function is_clickable_message_element(target) {
|
|
|
|
// This function defines all the elements within a message
|
|
|
|
// body that have UI behavior other than starting a reply.
|
2020-07-02 00:38:27 +02:00
|
|
|
|
|
|
|
// Links should be handled by the browser.
|
2020-07-15 01:29:15 +02:00
|
|
|
if (target.closest("a").length > 0) {
|
2020-07-02 00:35:02 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Forms for message editing contain input elements
|
|
|
|
if (target.is("textarea") || target.is("input")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Widget for adjusting the height of a message.
|
|
|
|
if (target.is("div.message_length_controller")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Inline image and twitter previews.
|
|
|
|
if (target.is("img.message_inline_image") || target.is("img.twitter-avatar")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// UI elements for triggering message editing or viewing edit history.
|
|
|
|
if (target.is("i.edit_content_button") || target.is(".message_edit_notice")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For spoilers, allow clicking either the header or elements within it
|
|
|
|
if (target.is(".spoiler-header") || target.parents(".spoiler-header").length > 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-04-25 22:54:23 +02:00
|
|
|
// Ideally, this should be done via ClipboardJS, but it doesn't support
|
2021-04-10 03:06:27 +02:00
|
|
|
// feature of stopPropagation once clicked.
|
|
|
|
// See https://github.com/zenorocha/clipboard.js/pull/475
|
|
|
|
if (target.is(".copy_codeblock") || target.parents(".copy_codeblock").length > 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-07-02 00:35:02 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const select_message_function = function (e) {
|
2014-03-14 15:30:29 +01:00
|
|
|
if (is_clickable_message_element($(e.target))) {
|
|
|
|
// If this click came from a hyperlink, don't trigger the
|
|
|
|
// reply action. The simple way of doing this is simply
|
|
|
|
// to call e.stopPropagation() from within the link's
|
|
|
|
// click handler.
|
|
|
|
//
|
|
|
|
// Unfortunately, on Firefox, this breaks Ctrl-click and
|
|
|
|
// Shift-click, because those are (apparently) implemented
|
|
|
|
// by adding an event listener on link clicks, and
|
|
|
|
// stopPropagation prevents them from being called.
|
|
|
|
return;
|
|
|
|
}
|
2017-04-14 01:14:50 +02:00
|
|
|
|
2020-04-10 13:05:11 +02:00
|
|
|
if (document.getSelection().type === "Range") {
|
|
|
|
// Drags on the message (to copy message text) shouldn't trigger a reply.
|
|
|
|
return;
|
|
|
|
}
|
2014-03-14 15:30:29 +01:00
|
|
|
|
2020-04-10 13:05:11 +02:00
|
|
|
const row = $(this).closest(".message_row");
|
|
|
|
const id = rows.id(row);
|
2014-03-14 15:30:29 +01:00
|
|
|
|
2020-04-10 13:05:11 +02:00
|
|
|
if (message_edit.is_editing(id)) {
|
|
|
|
// Clicks on a message being edited shouldn't trigger a reply.
|
|
|
|
return;
|
2014-03-14 15:30:29 +01:00
|
|
|
}
|
2020-04-10 13:05:11 +02:00
|
|
|
|
2021-03-30 02:21:21 +02:00
|
|
|
message_lists.current.select_id(id);
|
2020-07-15 01:29:15 +02:00
|
|
|
compose_actions.respond_to_message({trigger: "message click"});
|
2020-04-10 13:05:11 +02:00
|
|
|
e.stopPropagation();
|
|
|
|
popovers.hide_all();
|
2017-07-31 21:45:39 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// if on normal non-mobile experience, a `click` event should run the message
|
|
|
|
// selection function which will open the compose box and select the message.
|
|
|
|
if (!util.is_mobile()) {
|
|
|
|
$("#main_div").on("click", ".messagebox", select_message_function);
|
2020-07-15 00:34:28 +02:00
|
|
|
// on the other hand, on mobile it should be done with a long tap.
|
2017-07-31 21:45:39 +02:00
|
|
|
} else {
|
2017-09-15 22:43:12 +02:00
|
|
|
$("#main_div").on("longtap", ".messagebox", function (e) {
|
|
|
|
// find the correct selection API for the browser.
|
2019-11-02 00:06:25 +01:00
|
|
|
const sel = window.getSelection ? window.getSelection() : document.selection;
|
2017-09-15 22:43:12 +02:00
|
|
|
// if one matches, remove the current selections.
|
|
|
|
// after a longtap that is valid, there should be no text selected.
|
|
|
|
if (sel) {
|
|
|
|
if (sel.removeAllRanges) {
|
|
|
|
sel.removeAllRanges();
|
|
|
|
} else if (sel.empty) {
|
|
|
|
sel.empty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
select_message_function.call(this, e);
|
|
|
|
});
|
2017-07-31 21:45:39 +02:00
|
|
|
}
|
2014-03-14 15:30:29 +01:00
|
|
|
|
2020-07-03 17:49:19 +02:00
|
|
|
$("#main_div").on("click", ".star_container", function (e) {
|
2014-03-14 15:30:29 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
popovers.hide_all();
|
2017-12-16 13:33:54 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const message_id = rows.id($(this).closest(".message_row"));
|
|
|
|
const message = message_store.get(message_id);
|
2018-08-01 20:09:12 +02:00
|
|
|
message_flags.toggle_starred_and_update_server(message);
|
2014-03-14 15:30:29 +01:00
|
|
|
});
|
|
|
|
|
2020-07-14 09:08:16 +02:00
|
|
|
$("#main_div").on("click", ".message_reaction", function (e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
emoji_picker.hide_emoji_popover();
|
2020-07-15 01:29:15 +02:00
|
|
|
const local_id = $(this).attr("data-reaction-id");
|
2019-11-02 00:06:25 +01:00
|
|
|
const message_id = rows.get_message_id(this);
|
2017-10-31 22:33:28 +01:00
|
|
|
reactions.process_reaction_click(message_id, local_id);
|
2019-04-04 14:56:54 +02:00
|
|
|
$(".tooltip").remove();
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("mouseenter", ".message_edit_notice", (e) => {
|
2019-08-04 19:38:28 +02:00
|
|
|
if (page_params.realm_allow_edit_history) {
|
|
|
|
$(e.currentTarget).addClass("message_edit_notice_hover");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("mouseleave", ".message_edit_notice", (e) => {
|
2019-08-04 19:38:28 +02:00
|
|
|
if (page_params.realm_allow_edit_history) {
|
|
|
|
$(e.currentTarget).removeClass("message_edit_notice_hover");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".message_edit_notice", (e) => {
|
2019-08-04 19:38:28 +02:00
|
|
|
popovers.hide_all();
|
2019-11-02 00:06:25 +01:00
|
|
|
const message_id = rows.id($(e.currentTarget).closest(".message_row"));
|
2021-03-30 02:21:21 +02:00
|
|
|
const row = message_lists.current.get_row(message_id);
|
|
|
|
const message = message_lists.current.get(rows.id(row));
|
2020-07-15 01:29:15 +02:00
|
|
|
const message_history_cancel_btn = $("#message-history-cancel");
|
2019-08-04 19:38:28 +02:00
|
|
|
|
|
|
|
if (page_params.realm_allow_edit_history) {
|
2020-06-07 04:50:31 +02:00
|
|
|
message_edit_history.show_history(message);
|
2020-07-20 21:24:26 +02:00
|
|
|
message_history_cancel_btn.trigger("focus");
|
2019-08-04 19:38:28 +02:00
|
|
|
}
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
2016-11-18 10:18:08 +01:00
|
|
|
$("#main_div").on("click", "a.stream", function (e) {
|
|
|
|
e.preventDefault();
|
2018-02-15 21:02:47 +01:00
|
|
|
// Note that we may have an href here, but we trust the stream id more,
|
|
|
|
// so we re-encode the hash.
|
2020-10-07 09:17:30 +02:00
|
|
|
const stream_id = Number.parseInt($(this).attr("data-stream-id"), 10);
|
2018-12-14 19:18:24 +01:00
|
|
|
if (stream_id) {
|
2021-03-22 16:09:12 +01:00
|
|
|
browser_history.go_to_location(hash_util.by_stream_uri(stream_id));
|
2016-11-18 10:18:08 +01:00
|
|
|
return;
|
|
|
|
}
|
2020-07-15 01:29:15 +02:00
|
|
|
window.location.href = $(this).attr("href");
|
2016-11-18 10:18:08 +01:00
|
|
|
});
|
|
|
|
|
2019-04-23 18:07:10 +02:00
|
|
|
// USER STATUS MODAL
|
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
$(".user-status-value").on("click", (e) => {
|
2019-04-23 18:07:10 +02:00
|
|
|
e.stopPropagation();
|
2019-11-02 00:06:25 +01:00
|
|
|
const user_status_value = $(e.currentTarget).attr("data-user-status-value");
|
2019-04-23 18:07:10 +02:00
|
|
|
$("input.user_status").val(user_status_value);
|
2019-04-28 22:32:38 +02:00
|
|
|
user_status_ui.toggle_clear_message_button();
|
2019-04-23 18:07:10 +02:00
|
|
|
user_status_ui.update_button();
|
|
|
|
});
|
|
|
|
|
2014-03-14 15:30:29 +01:00
|
|
|
// MESSAGE EDITING
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".edit_content_button", function (e) {
|
2021-03-30 02:21:21 +02:00
|
|
|
const row = message_lists.current.get_row(rows.id($(this).closest(".message_row")));
|
|
|
|
message_lists.current.select_id(rows.id(row));
|
2014-03-14 15:30:29 +01:00
|
|
|
message_edit.start(row);
|
|
|
|
e.stopPropagation();
|
|
|
|
popovers.hide_all();
|
|
|
|
});
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".always_visible_topic_edit,.on_hover_topic_edit", function (e) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const recipient_row = $(this).closest(".recipient_row");
|
2021-03-29 18:39:20 +02:00
|
|
|
message_edit.start_inline_topic_edit(recipient_row);
|
2014-03-14 15:30:29 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
popovers.hide_all();
|
|
|
|
});
|
|
|
|
$("body").on("click", ".topic_edit_save", function (e) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const recipient_row = $(this).closest(".recipient_row");
|
2020-04-13 15:46:41 +02:00
|
|
|
message_edit.save_inline_topic_edit(recipient_row);
|
2014-03-14 15:30:29 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
popovers.hide_all();
|
|
|
|
});
|
|
|
|
$("body").on("click", ".topic_edit_cancel", function (e) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const recipient_row = $(this).closest(".recipient_row");
|
2020-04-13 15:46:41 +02:00
|
|
|
message_edit.end_inline_topic_edit(recipient_row);
|
2014-03-14 15:30:29 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
popovers.hide_all();
|
|
|
|
});
|
|
|
|
$("body").on("click", ".message_edit_save", function (e) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const row = $(this).closest(".message_row");
|
2020-04-13 15:46:41 +02:00
|
|
|
message_edit.save_message_row_edit(row);
|
2014-03-14 15:30:29 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
popovers.hide_all();
|
|
|
|
});
|
|
|
|
$("body").on("click", ".message_edit_cancel", function (e) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const row = $(this).closest(".message_row");
|
2020-04-13 15:46:41 +02:00
|
|
|
message_edit.end_message_row_edit(row);
|
2014-03-14 15:30:29 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
popovers.hide_all();
|
|
|
|
});
|
2016-10-22 02:38:56 +02:00
|
|
|
$("body").on("click", ".message_edit_close", function (e) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const row = $(this).closest(".message_row");
|
2020-04-13 15:46:41 +02:00
|
|
|
message_edit.end_message_row_edit(row);
|
2016-10-22 02:38:56 +02:00
|
|
|
e.stopPropagation();
|
|
|
|
popovers.hide_all();
|
|
|
|
});
|
2017-01-17 20:51:30 +01:00
|
|
|
$("body").on("click", ".copy_message", function (e) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const row = $(this).closest(".message_row");
|
2020-04-13 15:46:41 +02:00
|
|
|
message_edit.end_message_row_edit(row);
|
2021-04-13 06:51:54 +02:00
|
|
|
row.find(".alert-msg").text($t({defaultMessage: "Copied!"}));
|
2018-01-16 01:12:12 +01:00
|
|
|
row.find(".alert-msg").css("display", "block");
|
|
|
|
row.find(".alert-msg").delay(1000).fadeOut(300);
|
2020-09-12 21:04:24 +02:00
|
|
|
if ($(".tooltip").is(":visible")) {
|
|
|
|
$(".tooltip").hide();
|
|
|
|
}
|
2017-01-17 20:51:30 +01:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
2016-12-15 07:26:09 +01:00
|
|
|
$("body").on("click", "a", function () {
|
2016-12-14 23:34:08 +01:00
|
|
|
if (document.activeElement === this) {
|
2017-03-18 21:35:35 +01:00
|
|
|
ui_util.blur_active_element();
|
2016-12-14 23:34:08 +01:00
|
|
|
}
|
|
|
|
});
|
2021-04-21 16:20:16 +02:00
|
|
|
$(".message_edit_form .send-status-close").on("click", function () {
|
2019-11-02 00:06:25 +01:00
|
|
|
const row_id = rows.id($(this).closest(".message_row"));
|
2021-02-03 23:23:32 +01:00
|
|
|
const send_status = $(`#message-edit-send-status-${CSS.escape(row_id)}`);
|
2017-11-28 22:36:58 +01:00
|
|
|
$(send_status).stop(true).fadeOut(200);
|
|
|
|
});
|
2021-04-20 16:22:50 +02:00
|
|
|
$("body").on("click", ".message_edit_form .compose_upload_file", function (e) {
|
2017-11-28 22:36:58 +01:00
|
|
|
e.preventDefault();
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const row_id = rows.id($(this).closest(".message_row"));
|
2021-04-20 16:14:55 +02:00
|
|
|
$(`#edit_form_${CSS.escape(row_id)} .file_input`).trigger("click");
|
2017-11-28 22:36:58 +01:00
|
|
|
});
|
2014-03-14 15:30:29 +01:00
|
|
|
|
2021-04-21 16:20:16 +02:00
|
|
|
$("body").on("click", ".message_edit_form [id^='markdown_preview_']", function (e) {
|
2019-02-05 15:27:17 +01:00
|
|
|
e.preventDefault();
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const row_id = rows.id($(this).closest(".message_row"));
|
2019-02-05 15:27:17 +01:00
|
|
|
function $_(selector) {
|
2021-02-03 23:23:32 +01:00
|
|
|
return $(`${selector}_${CSS.escape(row_id)}`);
|
2019-02-05 15:27:17 +01:00
|
|
|
}
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const content = $_("#message_edit_content").val();
|
2019-02-05 15:27:17 +01:00
|
|
|
$_("#message_edit_content").hide();
|
|
|
|
$_("#markdown_preview").hide();
|
|
|
|
$_("#undo_markdown_preview").show();
|
|
|
|
$_("#preview_message_area").show();
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
compose.render_and_show_preview(
|
|
|
|
$_("#markdown_preview_spinner"),
|
|
|
|
$_("#preview_content"),
|
|
|
|
content,
|
|
|
|
);
|
2019-02-05 15:27:17 +01:00
|
|
|
});
|
|
|
|
|
2021-04-21 16:20:16 +02:00
|
|
|
$("body").on("click", ".message_edit_form [id^='undo_markdown_preview_']", function (e) {
|
2019-02-05 15:27:17 +01:00
|
|
|
e.preventDefault();
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const row_id = rows.id($(this).closest(".message_row"));
|
2019-02-05 15:27:17 +01:00
|
|
|
function $_(selector) {
|
2021-02-03 23:23:32 +01:00
|
|
|
return $(`${selector}_${CSS.escape(row_id)}`);
|
2019-02-05 15:27:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$_("#message_edit_content").show();
|
|
|
|
$_("#undo_markdown_preview").hide();
|
|
|
|
$_("#preview_message_area").hide();
|
|
|
|
$_("#preview_content").empty();
|
|
|
|
$_("#markdown_preview").show();
|
|
|
|
});
|
|
|
|
|
2021-04-08 19:52:11 +02:00
|
|
|
// TOPIC MUTING
|
|
|
|
function mute_or_unmute_topic($elt, mute_topic) {
|
2021-03-13 17:12:56 +01:00
|
|
|
const stream_id = Number.parseInt($elt.attr("data-stream-id"), 10);
|
|
|
|
const topic = $elt.attr("data-topic-name");
|
2021-04-08 19:52:11 +02:00
|
|
|
if (mute_topic) {
|
|
|
|
muting_ui.mute_topic(stream_id, topic);
|
|
|
|
} else {
|
|
|
|
muting_ui.unmute_topic(stream_id, topic);
|
|
|
|
}
|
2021-03-13 17:12:56 +01:00
|
|
|
}
|
2016-11-22 09:20:20 +01:00
|
|
|
|
recent topics: Fix duplicate muting requests sent to server.
Previously, on clicking the "bell" icon from a recent
topics topic row, two click handlers were triggered-
1. The one for the bell in the recent-topics topic
row.
2. The one for the bell in the floating recipient bar.
This is intended to be triggered only when the user
clicks on the bell icon in the floating recipient
bar to mute a topic, but this was triggered on
clicking the recent-topics topic row bell too,
because it wasn't specific and we use the same
HTML class for both the bells.
Because both these click handlers were triggered,
the webapp sent back-to-back duplicate requests to
the server to mute the topic, which caused the sever
to throw "HTTP 400: Topic already muted" error.
This commit fixes this by making the recipient bar
click handler more specific, so that it is triggered
only when the recipient bar bell icon is clicked.
There is also the issue that the recipient bar bell
icon only allows a user to mute the topic, not unmute.
So, when someone mutes a topic, and then clicks on
the recipient bar bell icon, the webapp sends a
request to mute the topic again (not to unmute),
leading to the same error as above.
This commit does not fix that. See #15223.
2021-03-28 09:01:27 +02:00
|
|
|
$("body").on("click", ".message_header .on_hover_topic_mute", (e) => {
|
2016-11-22 09:20:20 +01:00
|
|
|
e.stopPropagation();
|
2021-04-08 19:52:11 +02:00
|
|
|
mute_or_unmute_topic($(e.target), true);
|
2016-11-22 09:20:20 +01:00
|
|
|
});
|
|
|
|
|
2021-03-13 16:45:47 +01:00
|
|
|
// RECENT TOPICS
|
|
|
|
|
2021-03-31 05:36:08 +02:00
|
|
|
$("body").on("keydown", ".on_hover_topic_mute", ui_util.convert_enter_to_click);
|
2020-06-20 09:59:18 +02:00
|
|
|
|
2021-03-13 16:45:47 +01:00
|
|
|
$("body").on("click", "#recent_topics_table .on_hover_topic_unmute", (e) => {
|
2020-05-29 17:22:53 +02:00
|
|
|
e.stopPropagation();
|
2021-04-08 19:52:11 +02:00
|
|
|
const $elt = $(e.target);
|
|
|
|
recent_topics.focus_clicked_element($elt, recent_topics.COLUMNS.mute);
|
|
|
|
mute_or_unmute_topic($elt, false);
|
2020-05-29 17:22:53 +02:00
|
|
|
});
|
|
|
|
|
2021-03-31 05:36:08 +02:00
|
|
|
$("body").on("keydown", ".on_hover_topic_unmute", ui_util.convert_enter_to_click);
|
2020-06-20 09:59:18 +02:00
|
|
|
|
2021-03-13 16:45:47 +01:00
|
|
|
$("body").on("click", "#recent_topics_table .on_hover_topic_mute", (e) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
const $elt = $(e.target);
|
|
|
|
recent_topics.focus_clicked_element($elt, recent_topics.COLUMNS.mute);
|
2021-04-08 19:52:11 +02:00
|
|
|
mute_or_unmute_topic($elt, true);
|
2021-03-13 16:45:47 +01:00
|
|
|
});
|
2020-05-22 20:55:29 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", "#recent_topics_search", (e) => {
|
2020-06-24 16:55:55 +02:00
|
|
|
e.stopPropagation();
|
2021-03-16 15:15:33 +01:00
|
|
|
recent_topics.change_focused_element($(e.target), "click");
|
2020-06-24 16:55:55 +02:00
|
|
|
});
|
|
|
|
|
2021-03-13 16:45:47 +01:00
|
|
|
$("body").on("click", "#recent_topics_table .on_hover_topic_read", (e) => {
|
2020-05-22 20:55:29 +02:00
|
|
|
e.stopPropagation();
|
2021-03-13 16:45:47 +01:00
|
|
|
recent_topics.focus_clicked_element($(e.target), recent_topics.COLUMNS.read);
|
2020-10-07 09:17:30 +02:00
|
|
|
const stream_id = Number.parseInt($(e.currentTarget).attr("data-stream-id"), 10);
|
2020-07-15 01:29:15 +02:00
|
|
|
const topic = $(e.currentTarget).attr("data-topic-name");
|
2020-05-22 20:55:29 +02:00
|
|
|
unread_ops.mark_topic_as_read(stream_id, topic);
|
|
|
|
});
|
|
|
|
|
2021-03-31 05:36:08 +02:00
|
|
|
$("body").on("keydown", ".on_hover_topic_read", ui_util.convert_enter_to_click);
|
2020-06-20 09:59:18 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".btn-recent-filters", (e) => {
|
2020-05-23 09:04:51 +02:00
|
|
|
e.stopPropagation();
|
2021-03-16 15:15:33 +01:00
|
|
|
recent_topics.change_focused_element($(e.target), "click");
|
2020-05-23 09:04:51 +02:00
|
|
|
recent_topics.set_filter(e.currentTarget.dataset.filter);
|
2020-05-29 11:56:19 +02:00
|
|
|
recent_topics.update_filters_view();
|
2020-05-23 09:04:51 +02:00
|
|
|
});
|
|
|
|
|
2021-02-18 06:44:09 +01:00
|
|
|
$("body").on("click", "td.recent_topic_stream", (e) => {
|
|
|
|
e.stopPropagation();
|
2021-03-13 16:45:47 +01:00
|
|
|
recent_topics.focus_clicked_element($(e.target), recent_topics.COLUMNS.stream);
|
2021-02-18 06:44:09 +01:00
|
|
|
window.location.href = $(e.currentTarget).find("a").attr("href");
|
|
|
|
});
|
|
|
|
|
2020-09-21 08:59:48 +02:00
|
|
|
$("body").on("click", "td.recent_topic_name", (e) => {
|
|
|
|
e.stopPropagation();
|
2021-03-13 16:45:47 +01:00
|
|
|
recent_topics.focus_clicked_element($(e.target), recent_topics.COLUMNS.topic);
|
2020-09-21 08:59:48 +02:00
|
|
|
window.location.href = $(e.currentTarget).find("a").attr("href");
|
|
|
|
});
|
|
|
|
|
2020-05-23 09:04:51 +02:00
|
|
|
// Search for all table rows (this combines stream & topic names)
|
2020-07-15 00:34:28 +02:00
|
|
|
$("body").on(
|
|
|
|
"keyup",
|
|
|
|
"#recent_topics_search",
|
|
|
|
_.debounce(() => {
|
|
|
|
recent_topics.update_filters_view();
|
|
|
|
// Wait for user to go idle before initiating search.
|
|
|
|
}, 300),
|
|
|
|
);
|
2020-05-23 09:04:51 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", "#recent_topics_search_clear", (e) => {
|
2020-05-29 12:48:45 +02:00
|
|
|
e.stopPropagation();
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#recent_topics_search").val("");
|
2020-05-29 12:48:45 +02:00
|
|
|
recent_topics.update_filters_view();
|
|
|
|
});
|
|
|
|
|
2014-03-14 15:30:29 +01:00
|
|
|
// RECIPIENT BARS
|
|
|
|
|
|
|
|
function get_row_id_for_narrowing(narrow_link_elem) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const group = rows.get_closest_group(narrow_link_elem);
|
|
|
|
const msg_id = rows.id_for_recipient_row(group);
|
2014-03-14 15:30:29 +01:00
|
|
|
|
2021-03-30 02:21:21 +02:00
|
|
|
const nearest = message_lists.current.get(msg_id);
|
|
|
|
const selected = message_lists.current.selected_message();
|
2014-03-14 15:30:29 +01:00
|
|
|
if (util.same_recipient(nearest, selected)) {
|
|
|
|
return selected.id;
|
|
|
|
}
|
2016-12-02 21:34:35 +01:00
|
|
|
return nearest.id;
|
2014-03-14 15:30:29 +01:00
|
|
|
}
|
|
|
|
|
2020-07-04 16:25:41 +02:00
|
|
|
$("#message_feed_container").on("click", ".narrows_by_recipient", function (e) {
|
2014-03-14 15:30:29 +01:00
|
|
|
if (e.metaKey || e.ctrlKey) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
e.preventDefault();
|
2019-11-02 00:06:25 +01:00
|
|
|
const row_id = get_row_id_for_narrowing(this);
|
2020-07-15 01:29:15 +02:00
|
|
|
narrow.by_recipient(row_id, {trigger: "message header"});
|
2014-03-14 15:30:29 +01:00
|
|
|
});
|
|
|
|
|
2020-07-04 16:25:41 +02:00
|
|
|
$("#message_feed_container").on("click", ".narrows_by_topic", function (e) {
|
2014-03-14 15:30:29 +01:00
|
|
|
if (e.metaKey || e.ctrlKey) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
e.preventDefault();
|
2019-11-02 00:06:25 +01:00
|
|
|
const row_id = get_row_id_for_narrowing(this);
|
2020-07-15 01:29:15 +02:00
|
|
|
narrow.by_topic(row_id, {trigger: "message header"});
|
2014-03-14 15:30:29 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// SIDEBARS
|
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
$("#userlist-toggle-button").on("click", (e) => {
|
2014-03-14 15:30:29 +01:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const sidebarHidden = !$(".app-main .column-right").hasClass("expanded");
|
2014-03-14 15:30:29 +01:00
|
|
|
popovers.hide_all();
|
|
|
|
if (sidebarHidden) {
|
|
|
|
popovers.show_userlist_sidebar();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
$("#streamlist-toggle-button").on("click", (e) => {
|
2014-03-14 15:30:29 +01:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const sidebarHidden = !$(".app-main .column-left").hasClass("expanded");
|
2014-03-14 15:30:29 +01:00
|
|
|
popovers.hide_all();
|
|
|
|
if (sidebarHidden) {
|
2017-03-08 23:39:39 +01:00
|
|
|
stream_popover.show_streamlist_sidebar();
|
2014-03-14 15:30:29 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
$("#user_presences")
|
|
|
|
.expectOne()
|
|
|
|
.on("click", ".selectable_sidebar_block", (e) => {
|
|
|
|
const li = $(e.target).parents("li");
|
2018-04-19 23:14:58 +02:00
|
|
|
|
2020-07-20 22:18:43 +02:00
|
|
|
activity.narrow_for_user({li});
|
2018-04-19 23:14:58 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
popovers.hide_all();
|
|
|
|
$(".tooltip").remove();
|
|
|
|
});
|
2014-03-14 15:30:29 +01:00
|
|
|
|
2019-08-04 14:57:32 +02:00
|
|
|
function do_render_buddy_list_tooltip(elem, title_data) {
|
2021-02-25 02:45:26 +01:00
|
|
|
let placement = "left";
|
2021-04-10 15:30:39 +02:00
|
|
|
let observer;
|
2021-02-25 02:45:26 +01:00
|
|
|
if (window.innerWidth < media_breakpoints_num.md) {
|
|
|
|
// On small devices display tooltips based on available space.
|
|
|
|
// This will default to "bottom" placement for this tooltip.
|
|
|
|
placement = "auto";
|
|
|
|
}
|
|
|
|
tippy(elem[0], {
|
|
|
|
// Quickly display and hide right sidebar tooltips
|
|
|
|
// so that they don't stick and overlap with
|
|
|
|
// each other.
|
|
|
|
delay: 0,
|
|
|
|
content: render_buddy_list_tooltip_content(title_data),
|
|
|
|
arrow: true,
|
|
|
|
placement,
|
|
|
|
allowHTML: true,
|
|
|
|
showOnCreate: true,
|
|
|
|
onHidden: (instance) => {
|
|
|
|
instance.destroy();
|
2021-04-10 15:30:39 +02:00
|
|
|
observer.disconnect();
|
|
|
|
},
|
|
|
|
onShow: (instance) => {
|
|
|
|
// For both buddy list and top left corner pm list, `target_node`
|
|
|
|
// is their parent `ul` element. We cannot use MutationObserver
|
|
|
|
// directly on the reference element because it will be removed
|
|
|
|
// and we need to attach it on an element which will remain in the
|
|
|
|
// DOM which is their parent `ul`.
|
|
|
|
const target_node = $(instance.reference).parents("ul").get(0);
|
|
|
|
// We only need to know if any of the `li` elements were removed.
|
|
|
|
const config = {attributes: false, childList: true, subtree: false};
|
|
|
|
const callback = function (mutationsList) {
|
|
|
|
for (const mutation of mutationsList) {
|
|
|
|
// Hide instance if reference is in the removed node list.
|
|
|
|
if (
|
|
|
|
Array.prototype.includes.call(
|
|
|
|
mutation.removedNodes,
|
|
|
|
instance.reference.parentElement,
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
instance.hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
observer = new MutationObserver(callback);
|
|
|
|
observer.observe(target_node, config);
|
2021-02-25 02:45:26 +01:00
|
|
|
},
|
2021-04-10 19:20:51 +02:00
|
|
|
appendTo: () => document.body,
|
2019-08-04 14:57:32 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// BUDDY LIST TOOLTIPS
|
2021-04-10 15:13:02 +02:00
|
|
|
$("#user_presences").on("mouseenter", ".selectable_sidebar_block", (e) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
const elem = $(e.currentTarget).closest(".user_sidebar_entry").find(".user-presence-link");
|
|
|
|
const user_id_string = elem.attr("data-user-id");
|
|
|
|
const title_data = buddy_data.get_title_data(user_id_string, false);
|
|
|
|
do_render_buddy_list_tooltip(elem.parent(), title_data);
|
|
|
|
});
|
2019-08-04 14:57:32 +02:00
|
|
|
|
|
|
|
// PM LIST TOOLTIPS
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("mouseenter", "#pm_user_status", (e) => {
|
2019-08-04 14:57:32 +02:00
|
|
|
e.stopPropagation();
|
2019-11-02 00:06:25 +01:00
|
|
|
const elem = $(e.currentTarget);
|
2020-07-15 01:29:15 +02:00
|
|
|
const user_ids_string = elem.attr("data-user-ids-string");
|
2019-08-04 14:57:32 +02:00
|
|
|
// This converts from 'true' in the DOM to true.
|
2020-07-15 01:29:15 +02:00
|
|
|
const is_group = JSON.parse(elem.attr("data-is-group"));
|
2019-08-04 14:57:32 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const title_data = buddy_data.get_title_data(user_ids_string, is_group);
|
2019-08-04 14:57:32 +02:00
|
|
|
do_render_buddy_list_tooltip(elem, title_data);
|
|
|
|
});
|
|
|
|
|
2014-03-14 15:30:29 +01:00
|
|
|
// MISC
|
|
|
|
|
2016-09-29 21:56:50 +02:00
|
|
|
(function () {
|
2020-05-26 13:58:18 +02:00
|
|
|
const sel = ["#stream_filters", "#global_filters", "#user_presences"].join(", ");
|
2016-09-29 21:56:50 +02:00
|
|
|
|
|
|
|
$(sel).on("click", "a", function () {
|
|
|
|
this.blur();
|
|
|
|
});
|
2020-07-16 22:35:58 +02:00
|
|
|
})();
|
2016-09-29 21:56:50 +02:00
|
|
|
|
2014-03-14 15:30:29 +01:00
|
|
|
popovers.register_click_handlers();
|
2017-04-27 07:27:25 +02:00
|
|
|
emoji_picker.register_click_handlers();
|
2017-03-05 17:28:40 +01:00
|
|
|
stream_popover.register_click_handlers();
|
2014-03-14 15:30:29 +01:00
|
|
|
notifications.register_click_handlers();
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".logout_button", () => {
|
2020-07-20 21:24:26 +02:00
|
|
|
$("#logout_form").trigger("submit");
|
2014-03-14 15:30:29 +01:00
|
|
|
});
|
2016-12-03 01:12:52 +01:00
|
|
|
|
2020-07-20 21:26:58 +02:00
|
|
|
$(".restart_get_events_button").on("click", () => {
|
2014-03-14 15:30:29 +01:00
|
|
|
server_events.restart_get_events({dont_block: true});
|
|
|
|
});
|
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
$("#settings_page").on("click", ".collapse-settings-btn", () => {
|
2019-05-13 00:43:21 +02:00
|
|
|
settings_toggle.toggle_org_setting_collapse();
|
|
|
|
});
|
2014-03-14 15:30:29 +01:00
|
|
|
|
2020-08-07 19:30:28 +02:00
|
|
|
$(".organization-box").on("show.bs.modal", () => {
|
|
|
|
popovers.hide_all();
|
|
|
|
});
|
|
|
|
|
2014-03-14 15:30:29 +01:00
|
|
|
// COMPOSE
|
|
|
|
|
2021-04-14 13:40:03 +02:00
|
|
|
$("body").on("click", "#compose-send-status .compose-send-status-close", () => {
|
2020-07-15 00:34:28 +02:00
|
|
|
$("#compose-send-status").stop(true).fadeOut(500);
|
|
|
|
});
|
2021-04-14 13:40:03 +02:00
|
|
|
$("body").on("click", "#nonexistent_stream_reply_error .compose-send-status-close", () => {
|
2020-07-15 00:34:28 +02:00
|
|
|
$("#nonexistent_stream_reply_error").stop(true).fadeOut(500);
|
|
|
|
});
|
2014-03-14 15:30:29 +01:00
|
|
|
|
2021-04-14 13:40:03 +02:00
|
|
|
$("body").on("click", ".compose_stream_button", () => {
|
2018-08-13 23:13:00 +02:00
|
|
|
popovers.hide_mobile_message_buttons_popover();
|
2020-07-15 01:29:15 +02:00
|
|
|
compose_actions.start("stream", {trigger: "new topic button"});
|
2014-03-14 15:30:29 +01:00
|
|
|
});
|
2021-04-14 13:40:03 +02:00
|
|
|
$("body").on("click", ".compose_private_button", () => {
|
2018-08-13 23:13:00 +02:00
|
|
|
popovers.hide_mobile_message_buttons_popover();
|
2020-07-15 01:29:15 +02:00
|
|
|
compose_actions.start("private");
|
2014-03-14 15:30:29 +01:00
|
|
|
});
|
2018-08-13 23:13:00 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".compose_mobile_stream_button", () => {
|
2018-08-13 23:13:00 +02:00
|
|
|
popovers.hide_mobile_message_buttons_popover();
|
2020-07-15 01:29:15 +02:00
|
|
|
compose_actions.start("stream", {trigger: "new topic button"});
|
2018-08-13 23:13:00 +02:00
|
|
|
});
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".compose_mobile_private_button", () => {
|
2018-08-13 23:13:00 +02:00
|
|
|
popovers.hide_mobile_message_buttons_popover();
|
2020-07-15 01:29:15 +02:00
|
|
|
compose_actions.start("private");
|
2018-08-13 23:13:00 +02:00
|
|
|
});
|
|
|
|
|
2021-04-14 13:40:03 +02:00
|
|
|
$("body").on("click", ".compose_reply_button", () => {
|
2020-07-15 01:29:15 +02:00
|
|
|
compose_actions.respond_to_message({trigger: "reply button"});
|
2017-12-11 11:39:49 +01:00
|
|
|
});
|
2014-03-14 15:30:29 +01:00
|
|
|
|
2021-04-14 13:40:03 +02:00
|
|
|
$("body").on("click", ".empty_feed_compose_stream", (e) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
compose_actions.start("stream", {trigger: "empty feed message"});
|
2014-03-14 15:30:29 +01:00
|
|
|
e.preventDefault();
|
|
|
|
});
|
2021-04-14 13:40:03 +02:00
|
|
|
$("body").on("click", ".empty_feed_compose_private", (e) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
compose_actions.start("private", {trigger: "empty feed message"});
|
2014-03-14 15:30:29 +01:00
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
2017-01-05 21:11:45 +01:00
|
|
|
$("body").on("click", "[data-overlay-trigger]", function () {
|
2019-11-02 00:06:25 +01:00
|
|
|
const target = $(this).attr("data-overlay-trigger");
|
2021-03-22 16:09:12 +01:00
|
|
|
browser_history.go_to_location(target);
|
2017-01-05 21:11:45 +01:00
|
|
|
});
|
|
|
|
|
2014-03-14 15:30:29 +01:00
|
|
|
function handle_compose_click(e) {
|
2017-04-27 07:27:25 +02:00
|
|
|
// Emoji clicks should be handled by their own click handler in emoji_picker.js
|
2021-04-06 13:34:33 +02:00
|
|
|
if ($(e.target).is("#emoji_map, img.emoji, .drag, .compose_giphy_logo")) {
|
2015-10-15 22:34:30 +02:00
|
|
|
return;
|
|
|
|
}
|
2018-08-13 23:13:00 +02:00
|
|
|
|
|
|
|
// The mobile compose button has its own popover when clicked, so it already.
|
|
|
|
// hides other popovers.
|
|
|
|
if ($(e.target).is(".compose_mobile_button, .compose_mobile_button *")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-14 15:30:29 +01:00
|
|
|
// Don't let clicks in the compose area count as
|
|
|
|
// "unfocusing" our compose -- in other words, e.g.
|
2020-08-11 02:09:14 +02:00
|
|
|
// clicking "Press Enter to send" should not
|
2014-03-14 15:30:29 +01:00
|
|
|
// trigger the composebox-closing code above.
|
|
|
|
// But do allow our formatting link.
|
|
|
|
if (!$(e.target).is("a")) {
|
|
|
|
e.stopPropagation();
|
|
|
|
}
|
|
|
|
// Still hide the popovers, however
|
|
|
|
popovers.hide_all();
|
|
|
|
}
|
|
|
|
|
2021-04-14 13:40:03 +02:00
|
|
|
$("body").on("click", "#compose_buttons", handle_compose_click);
|
|
|
|
$("body").on("click", ".compose-content", handle_compose_click);
|
2014-03-14 15:30:29 +01:00
|
|
|
|
2021-04-14 13:40:03 +02:00
|
|
|
$("body").on("click", "#compose_close", () => {
|
2017-03-18 17:55:11 +01:00
|
|
|
compose_actions.cancel();
|
2014-03-14 15:30:29 +01:00
|
|
|
});
|
|
|
|
|
2021-04-14 13:40:03 +02:00
|
|
|
// LEFT SIDEBAR
|
|
|
|
|
2020-07-20 21:26:58 +02:00
|
|
|
$("#streams_inline_cog").on("click", (e) => {
|
2017-09-09 15:00:00 +02:00
|
|
|
e.stopPropagation();
|
2021-03-22 16:09:12 +01:00
|
|
|
browser_history.go_to_location("streams/subscribed");
|
2017-09-09 15:00:00 +02:00
|
|
|
});
|
|
|
|
|
2020-07-20 21:26:58 +02:00
|
|
|
$("#streams_filter_icon").on("click", (e) => {
|
2017-09-09 15:00:00 +02:00
|
|
|
e.stopPropagation();
|
|
|
|
stream_list.toggle_filter_displayed(e);
|
|
|
|
});
|
|
|
|
|
2014-03-14 15:30:29 +01:00
|
|
|
// WEBATHENA
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".webathena_login", (e) => {
|
2017-04-05 23:33:14 +02:00
|
|
|
$("#zephyr-mirror-error").removeClass("show");
|
2019-11-02 00:06:25 +01:00
|
|
|
const principal = ["zephyr", "zephyr"];
|
2020-07-15 00:34:28 +02:00
|
|
|
WinChan.open(
|
|
|
|
{
|
|
|
|
url: "https://webathena.mit.edu/#!request_ticket_v1",
|
|
|
|
relay_url: "https://webathena.mit.edu/relay.html",
|
|
|
|
params: {
|
|
|
|
realm: "ATHENA.MIT.EDU",
|
2020-07-20 22:18:43 +02:00
|
|
|
principal,
|
2020-07-15 00:34:28 +02:00
|
|
|
},
|
2017-01-12 00:17:43 +01:00
|
|
|
},
|
2020-07-15 00:34:28 +02:00
|
|
|
(err, r) => {
|
|
|
|
if (err) {
|
|
|
|
blueslip.warn(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (r.status !== "OK") {
|
|
|
|
blueslip.warn(r);
|
|
|
|
return;
|
|
|
|
}
|
2014-03-14 15:30:29 +01:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
channel.post({
|
|
|
|
url: "/accounts/webathena_kerberos_login/",
|
|
|
|
data: {cred: JSON.stringify(r.session)},
|
2020-07-20 22:18:43 +02:00
|
|
|
success() {
|
2020-07-15 00:34:28 +02:00
|
|
|
$("#zephyr-mirror-error").removeClass("show");
|
|
|
|
},
|
2020-07-20 22:18:43 +02:00
|
|
|
error() {
|
2020-07-15 00:34:28 +02:00
|
|
|
$("#zephyr-mirror-error").addClass("show");
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
);
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#settings-dropdown").dropdown("toggle");
|
2014-03-14 15:30:29 +01:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
// End Webathena code
|
|
|
|
|
2019-04-12 13:17:29 +02:00
|
|
|
// disable the draggability for left-sidebar components
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#stream_filters, #global_filters").on("dragstart", (e) => {
|
2020-07-22 04:21:43 +02:00
|
|
|
e.target.blur();
|
2020-07-16 10:03:13 +02:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Chrome focuses an element when dragging it which can be confusing when
|
|
|
|
// users involuntarily drag something and we show them the focus outline.
|
2020-07-22 04:21:43 +02:00
|
|
|
$("body").on("dragstart", "a", (e) => e.target.blur());
|
2020-07-16 10:46:32 +02:00
|
|
|
|
|
|
|
// Don't focus links on middle click.
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("mouseup", "a", (e) => {
|
2020-07-15 00:34:28 +02:00
|
|
|
if (e.which === 2) {
|
|
|
|
// middle click
|
2020-07-22 04:21:43 +02:00
|
|
|
e.target.blur();
|
2020-07-16 10:46:32 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Don't focus links on context menu.
|
2020-07-22 04:21:43 +02:00
|
|
|
$("body").on("contextmenu", "a", (e) => e.target.blur());
|
2019-04-12 13:17:29 +02:00
|
|
|
|
2016-12-17 03:44:15 +01:00
|
|
|
(function () {
|
2019-11-02 00:06:25 +01:00
|
|
|
const map = {
|
2019-02-07 08:22:14 +01:00
|
|
|
".stream-description-editable": {
|
|
|
|
on_start: stream_edit.set_raw_description,
|
|
|
|
on_save: stream_edit.change_stream_description,
|
|
|
|
},
|
|
|
|
".stream-name-editable": {
|
|
|
|
on_start: null,
|
|
|
|
on_save: stream_edit.change_stream_name,
|
|
|
|
},
|
2016-12-17 03:44:15 +01:00
|
|
|
};
|
|
|
|
|
2017-02-16 19:50:08 +01:00
|
|
|
$(document).on("keydown", ".editable-section", function (e) {
|
|
|
|
e.stopPropagation();
|
2017-03-22 07:00:13 +01:00
|
|
|
// Cancel editing description if Escape key is pressed.
|
|
|
|
if (e.which === 27) {
|
|
|
|
$("[data-finish-editing='.stream-description-editable']").hide();
|
|
|
|
$(this).attr("contenteditable", false);
|
|
|
|
$(this).text($(this).attr("data-prev-text"));
|
|
|
|
$("[data-make-editable]").html("");
|
2017-03-22 20:10:15 +01:00
|
|
|
} else if (e.which === 13) {
|
2020-07-20 21:24:26 +02:00
|
|
|
$(this).siblings(".checkmark").trigger("click");
|
2017-03-22 07:00:13 +01:00
|
|
|
}
|
2017-02-16 19:50:08 +01:00
|
|
|
});
|
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
$(document).on("drop", ".editable-section", () => false);
|
2017-02-16 19:50:08 +01:00
|
|
|
|
|
|
|
$(document).on("input", ".editable-section", function () {
|
|
|
|
// if there are any child nodes, inclusive of <br> which means you
|
|
|
|
// have lines in your description or title, you're doing something
|
|
|
|
// wrong.
|
2019-11-02 00:06:25 +01:00
|
|
|
for (let x = 0; x < this.childNodes.length; x += 1) {
|
2017-03-22 19:42:54 +01:00
|
|
|
if (this.childNodes[x].nodeType !== 3) {
|
2020-10-07 10:15:47 +02:00
|
|
|
this.textContent = this.textContent.replace(/\n/, "");
|
2017-03-22 19:42:54 +01:00
|
|
|
break;
|
|
|
|
}
|
2017-02-16 19:50:08 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-12-17 03:44:15 +01:00
|
|
|
$("body").on("click", "[data-make-editable]", function () {
|
2019-11-02 00:06:25 +01:00
|
|
|
const selector = $(this).attr("data-make-editable");
|
2021-01-23 02:36:54 +01:00
|
|
|
const edit_area = $(this).parent().find(`${selector}`);
|
2020-02-22 09:50:16 +01:00
|
|
|
$(selector).removeClass("stream-name-edit-box");
|
2016-12-17 03:44:15 +01:00
|
|
|
if (edit_area.attr("contenteditable") === "true") {
|
2021-02-03 23:23:32 +01:00
|
|
|
$(`[data-finish-editing='${CSS.escape(selector)}']`).hide();
|
2016-12-17 03:44:15 +01:00
|
|
|
edit_area.attr("contenteditable", false);
|
|
|
|
edit_area.text(edit_area.attr("data-prev-text"));
|
|
|
|
$(this).html("");
|
|
|
|
} else {
|
2021-02-03 23:23:32 +01:00
|
|
|
$(`[data-finish-editing='${CSS.escape(selector)}']`).show();
|
2016-12-17 03:53:12 +01:00
|
|
|
|
2020-02-22 09:50:16 +01:00
|
|
|
$(selector).addClass("stream-name-edit-box");
|
2020-07-15 00:34:28 +02:00
|
|
|
edit_area
|
|
|
|
.attr("data-prev-text", edit_area.text().trim())
|
2016-12-17 03:53:12 +01:00
|
|
|
.attr("contenteditable", true);
|
|
|
|
|
2019-02-07 08:22:14 +01:00
|
|
|
if (map[selector].on_start) {
|
|
|
|
map[selector].on_start(this, edit_area);
|
|
|
|
}
|
|
|
|
|
2017-11-13 21:38:00 +01:00
|
|
|
ui_util.place_caret_at_end(edit_area[0]);
|
2016-12-17 03:53:12 +01:00
|
|
|
|
2016-12-17 03:44:15 +01:00
|
|
|
$(this).html("×");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$("body").on("click", "[data-finish-editing]", function (e) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const selector = $(this).attr("data-finish-editing");
|
2020-02-22 09:50:16 +01:00
|
|
|
$(selector).removeClass("stream-name-edit-box");
|
2019-02-07 08:22:14 +01:00
|
|
|
if (map[selector].on_save) {
|
|
|
|
map[selector].on_save(e);
|
2016-12-17 03:44:15 +01:00
|
|
|
$(this).hide();
|
2021-01-23 02:36:54 +01:00
|
|
|
$(this).parent().find(`${selector}`).attr("contenteditable", false);
|
2021-02-03 23:23:32 +01:00
|
|
|
$(`[data-make-editable='${CSS.escape(selector)}']`).html("");
|
2016-12-17 03:44:15 +01:00
|
|
|
}
|
|
|
|
});
|
2020-07-16 22:35:58 +02:00
|
|
|
})();
|
2016-12-17 03:44:15 +01:00
|
|
|
|
2017-07-14 03:21:30 +02:00
|
|
|
// HOTSPOTS
|
|
|
|
|
|
|
|
// open
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".hotspot-icon", function (e) {
|
2017-07-14 03:21:30 +02:00
|
|
|
// hide icon
|
2018-03-17 19:35:19 +01:00
|
|
|
hotspots.close_hotspot_icon(this);
|
2017-07-14 03:21:30 +02:00
|
|
|
|
|
|
|
// show popover
|
2020-07-15 00:34:28 +02:00
|
|
|
const hotspot_name = $(e.target)
|
|
|
|
.closest(".hotspot-icon")
|
2020-07-15 01:29:15 +02:00
|
|
|
.attr("id")
|
|
|
|
.replace("hotspot_", "")
|
|
|
|
.replace("_icon", "");
|
|
|
|
const overlay_name = "hotspot_" + hotspot_name + "_overlay";
|
2017-07-14 03:21:30 +02:00
|
|
|
|
|
|
|
overlays.open_overlay({
|
|
|
|
name: overlay_name,
|
2021-02-03 23:23:32 +01:00
|
|
|
overlay: $(`#${CSS.escape(overlay_name)}`),
|
2017-07-14 03:21:30 +02:00
|
|
|
on_close: function () {
|
|
|
|
// close popover
|
2020-07-16 22:40:18 +02:00
|
|
|
$(this).css({display: "block"});
|
2020-07-15 00:34:28 +02:00
|
|
|
$(this).animate(
|
|
|
|
{opacity: 1},
|
|
|
|
{
|
|
|
|
duration: 300,
|
|
|
|
},
|
|
|
|
);
|
2017-07-14 03:21:30 +02:00
|
|
|
}.bind(this),
|
|
|
|
});
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
|
|
|
// confirm
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".hotspot.overlay .hotspot-confirm", function (e) {
|
2017-07-14 03:21:30 +02:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const overlay_name = $(this).closest(".hotspot.overlay").attr("id");
|
2017-07-14 03:21:30 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
const hotspot_name = overlay_name.replace("hotspot_", "").replace("_overlay", "");
|
2017-07-14 03:21:30 +02:00
|
|
|
|
|
|
|
// Comment below to disable marking hotspots as read in production
|
|
|
|
hotspots.post_hotspot_as_read(hotspot_name);
|
|
|
|
|
|
|
|
overlays.close_overlay(overlay_name);
|
2021-02-03 23:23:32 +01:00
|
|
|
$(`#hotspot_${CSS.escape(hotspot_name)}_icon`).remove();
|
2017-07-14 03:21:30 +02:00
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".hotspot-button", (e) => {
|
2018-05-15 23:21:12 +02:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
hotspots.post_hotspot_as_read("intro_reply");
|
|
|
|
hotspots.close_hotspot_icon($("#hotspot_intro_reply_icon"));
|
2020-12-20 15:02:48 +01:00
|
|
|
$("#hotspot_intro_reply_icon").remove();
|
2018-05-15 23:21:12 +02:00
|
|
|
});
|
|
|
|
|
2017-07-14 03:21:30 +02:00
|
|
|
// stop propagation
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".hotspot.overlay .hotspot-popover", (e) => {
|
2017-07-14 03:21:30 +02:00
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
2020-08-09 23:34:22 +02:00
|
|
|
$("body").on("hidden.bs.modal", () => {
|
|
|
|
// Enable mouse events for the background as the modal closes.
|
|
|
|
overlays.enable_background_mouse_events();
|
|
|
|
});
|
|
|
|
|
2014-03-14 15:30:29 +01:00
|
|
|
// MAIN CLICK HANDLER
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$(document).on("click", (e) => {
|
2016-10-15 07:21:30 +02:00
|
|
|
if (e.button !== 0 || $(e.target).is(".drag")) {
|
2014-03-14 15:30:29 +01:00
|
|
|
// Firefox emits right click events on the document, but not on
|
|
|
|
// the child nodes, so the #compose stopPropagation doesn't get a
|
|
|
|
// chance to capture right clicks.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Dismiss popovers if the user has clicked outside them
|
2020-07-15 00:34:28 +02:00
|
|
|
if (
|
|
|
|
$(
|
|
|
|
'.popover-inner, #user-profile-modal, .emoji-info-popover, .app-main [class^="column-"].expanded',
|
|
|
|
).has(e.target).length === 0
|
|
|
|
) {
|
2014-03-14 15:30:29 +01:00
|
|
|
popovers.hide_all();
|
|
|
|
}
|
|
|
|
|
2017-09-08 20:44:23 +02:00
|
|
|
if (compose_state.composing()) {
|
2018-06-22 19:25:54 +02:00
|
|
|
if ($(e.target).closest("a").length > 0) {
|
2021-01-19 15:27:49 +01:00
|
|
|
// Refocus compose message text box if one clicks an external
|
|
|
|
// link/url to view something else while composing a message
|
|
|
|
// See issue #4331 for more details
|
2020-07-20 21:24:26 +02:00
|
|
|
$("#compose-textarea").trigger("focus");
|
2019-03-08 22:27:40 +01:00
|
|
|
return;
|
2020-07-15 00:34:28 +02:00
|
|
|
} else if (
|
|
|
|
!window.getSelection().toString() &&
|
|
|
|
// Clicks inside an overlay, popover, custom
|
|
|
|
// modal, or backdrop of one of the above
|
|
|
|
// should not have any effect on the compose
|
|
|
|
// state.
|
|
|
|
!$(e.target).closest(".overlay").length &&
|
|
|
|
!$(e.target).closest(".popover").length &&
|
|
|
|
!$(e.target).closest(".modal").length &&
|
|
|
|
!$(e.target).closest(".modal-backdrop").length &&
|
|
|
|
$(e.target).closest("body").length
|
|
|
|
) {
|
2017-09-08 20:44:23 +02:00
|
|
|
// Unfocus our compose area if we click out of it. Don't let exits out
|
|
|
|
// of overlays or selecting text (for copy+paste) trigger cancelling.
|
2018-01-18 21:25:01 +01:00
|
|
|
// Check if the click is within the body to prevent extensions from
|
|
|
|
// interfering with the compose box.
|
2017-09-08 20:44:23 +02:00
|
|
|
compose_actions.cancel();
|
|
|
|
}
|
2014-03-14 15:30:29 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Workaround for Bootstrap issue #5900, which basically makes dropdowns
|
|
|
|
// unclickable on mobile devices.
|
|
|
|
// https://github.com/twitter/bootstrap/issues/5900
|
2020-07-15 01:29:15 +02:00
|
|
|
$("a.dropdown-toggle, .dropdown-menu a").on("touchstart", (e) => {
|
2014-03-14 15:30:29 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
});
|
2016-12-03 01:12:52 +01:00
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
$(".settings-header.mobile .fa-chevron-left").on("click", () => {
|
2020-06-25 00:51:20 +02:00
|
|
|
settings_panel_menu.mobile_deactivate_section();
|
2016-12-03 01:12:52 +01:00
|
|
|
});
|
2021-02-28 01:00:56 +01:00
|
|
|
}
|