2013-06-28 22:38:40 +02:00
|
|
|
var popovers = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
|
|
|
var current_actions_popover_elem;
|
2013-07-11 23:06:58 +02:00
|
|
|
var current_message_info_popover_elem;
|
2013-09-12 22:02:55 +02:00
|
|
|
var userlist_placement = "right";
|
|
|
|
|
2017-01-04 02:44:49 +01:00
|
|
|
var list_of_popovers = [];
|
|
|
|
|
|
|
|
// this utilizes the proxy pattern to intercept all calls to $.fn.popover
|
|
|
|
// and push the $.fn.data($o, "popover") results to an array.
|
|
|
|
// this is needed so that when we try to unload popovers, we can kill all dead
|
|
|
|
// ones that no longer have valid parents in the DOM.
|
|
|
|
(function (popover) {
|
|
|
|
|
|
|
|
$.fn.popover = function () {
|
|
|
|
// apply the jQuery object as `this`, and popover function arguments.
|
|
|
|
popover.apply(this, arguments);
|
|
|
|
|
|
|
|
// if there is a valid "popover" key in the jQuery data object then
|
|
|
|
// push it to the array.
|
|
|
|
if (this.data("popover")) {
|
|
|
|
list_of_popovers.push(this.data("popover"));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// add back all shallow properties of $.fn.popover to the new proxied version.
|
|
|
|
for (var x in popover) {
|
|
|
|
if (popover.hasOwnProperty(x)) {
|
|
|
|
$.fn.popover[x] = popover[x];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}($.fn.popover));
|
|
|
|
|
2017-09-30 17:54:26 +02:00
|
|
|
function load_medium_avatar(user, elt) {
|
|
|
|
var user_avatar_url = "avatar/" + user.user_id + "/medium";
|
2017-03-04 13:43:21 +01:00
|
|
|
var sender_avatar_medium = new Image();
|
2017-09-28 01:52:25 +02:00
|
|
|
sender_avatar_medium.src = user_avatar_url;
|
2017-07-26 20:03:38 +02:00
|
|
|
$(sender_avatar_medium).on("load", function () {
|
2017-09-30 17:54:26 +02:00
|
|
|
elt.css("background-image", "url(" + $(this).attr("src") + ")");
|
2017-03-04 13:43:21 +01:00
|
|
|
});
|
|
|
|
}
|
2017-03-05 04:46:37 +01:00
|
|
|
|
2017-05-12 20:17:17 +02:00
|
|
|
function user_last_seen_time_status(user_id) {
|
2017-06-19 19:03:39 +02:00
|
|
|
var status = presence.get_status(user_id);
|
|
|
|
if (status === "active") {
|
2017-05-12 20:17:17 +02:00
|
|
|
return i18n.t("Active now");
|
|
|
|
}
|
2017-10-12 17:50:41 +02:00
|
|
|
|
2017-08-17 01:07:27 +02:00
|
|
|
if (page_params.realm_is_zephyr_mirror_realm) {
|
|
|
|
// We don't send presence data to clients in Zephyr mirroring realms
|
|
|
|
return i18n.t("Unknown");
|
|
|
|
}
|
2017-08-28 01:40:34 +02:00
|
|
|
|
2017-10-12 17:50:41 +02:00
|
|
|
// There are situations where the client has incomplete presence
|
|
|
|
// history on a user. This can happen when users are deactivated,
|
|
|
|
// or when they just haven't been present in a long time (and we
|
|
|
|
// may have queries on presence that go back only N weeks).
|
|
|
|
//
|
|
|
|
// We give the somewhat vague status of "Unknown" for these users.
|
2017-08-28 01:40:34 +02:00
|
|
|
var last_active_date = presence.last_active_date(user_id);
|
|
|
|
if (last_active_date === undefined) {
|
|
|
|
return i18n.t("Unknown");
|
|
|
|
}
|
|
|
|
return timerender.last_seen_status_from_date(last_active_date.clone());
|
2017-05-12 20:17:17 +02:00
|
|
|
}
|
|
|
|
|
2017-09-30 17:25:49 +02:00
|
|
|
// element is the target element to pop off of
|
|
|
|
// user is the user whose profile to show
|
|
|
|
// message is the message containing it, which should be selected
|
2017-09-30 17:37:49 +02:00
|
|
|
function show_user_info_popover(element, user, message) {
|
2013-07-11 23:06:58 +02:00
|
|
|
var last_popover_elem = current_message_info_popover_elem;
|
2013-07-09 00:58:08 +02:00
|
|
|
popovers.hide_all();
|
2013-06-28 22:38:40 +02:00
|
|
|
if (last_popover_elem !== undefined
|
|
|
|
&& last_popover_elem.get()[0] === element) {
|
|
|
|
// We want it to be the case that a user can dismiss a popover
|
|
|
|
// by clicking on the same element that caused the popover.
|
|
|
|
return;
|
|
|
|
}
|
2017-09-30 17:25:49 +02:00
|
|
|
current_msg_list.select_id(message.id);
|
2013-06-28 22:38:40 +02:00
|
|
|
var elt = $(element);
|
|
|
|
if (elt.data('popover') === undefined) {
|
2017-09-30 17:31:49 +02:00
|
|
|
if (user === undefined) {
|
2017-11-06 15:32:31 +01:00
|
|
|
// This is never supposed to happen, not even for deactivated
|
|
|
|
// users, so we'll need to debug this error if it occurs.
|
2017-09-30 17:31:49 +02:00
|
|
|
blueslip.error('Bad sender in message' + message.sender_id);
|
|
|
|
return;
|
2017-02-07 02:54:01 +01:00
|
|
|
}
|
|
|
|
|
2013-06-28 22:38:40 +02:00
|
|
|
var args = {
|
2017-09-30 17:31:49 +02:00
|
|
|
user_full_name: user.full_name,
|
|
|
|
user_email: user.email,
|
|
|
|
user_id: user.user_id,
|
|
|
|
user_time: people.get_user_time(user.user_id),
|
|
|
|
presence_status: presence.get_status(user.user_id),
|
|
|
|
user_last_seen_time_status: user_last_seen_time_status(user.user_id),
|
|
|
|
pm_with_uri: narrow.pm_with_uri(user.email),
|
|
|
|
sent_by_uri: narrow.by_sender_uri(user.email),
|
2017-04-25 15:25:31 +02:00
|
|
|
narrowed: narrow_state.active(),
|
2017-03-04 13:43:21 +01:00
|
|
|
private_message_class: "respond_personal_button",
|
2017-10-26 21:00:30 +02:00
|
|
|
is_active: people.is_active_user_for_popover(user.user_id),
|
2013-06-28 22:38:40 +02:00
|
|
|
};
|
|
|
|
|
2017-03-22 14:13:22 +01:00
|
|
|
var ypos = elt.offset().top;
|
2017-04-02 21:01:58 +02:00
|
|
|
var popover_size = 428;
|
2017-03-22 14:13:22 +01:00
|
|
|
var placement = "right";
|
|
|
|
|
|
|
|
if (!((ypos + (popover_size / 2) < message_viewport.height()) &&
|
|
|
|
(ypos > (popover_size / 2)))) {
|
|
|
|
if (((ypos + popover_size) < message_viewport.height())) {
|
|
|
|
placement = "bottom";
|
|
|
|
} else if (ypos > popover_size) {
|
|
|
|
placement = "top";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-28 22:38:40 +02:00
|
|
|
elt.popover({
|
2017-03-22 14:13:22 +01:00
|
|
|
placement: placement,
|
2017-10-18 19:16:41 +02:00
|
|
|
template: templates.render('user_info_popover', {class: "message-info-popover"}),
|
|
|
|
title: templates.render('user_info_popover_title',
|
|
|
|
{user_avatar: "avatar/" + user.email}),
|
|
|
|
content: templates.render('user_info_popover_content', args),
|
|
|
|
trigger: "manual",
|
2013-07-11 23:06:58 +02:00
|
|
|
});
|
|
|
|
elt.popover("show");
|
2017-03-03 21:57:06 +01:00
|
|
|
|
2017-09-30 17:54:26 +02:00
|
|
|
load_medium_avatar(user, $(".popover-avatar"));
|
2017-03-03 21:57:06 +01:00
|
|
|
|
2013-07-11 23:06:58 +02:00
|
|
|
current_message_info_popover_elem = elt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-08 18:28:22 +01:00
|
|
|
exports.toggle_actions_popover = function (element, id) {
|
2013-07-11 23:06:58 +02:00
|
|
|
var last_popover_elem = current_actions_popover_elem;
|
|
|
|
popovers.hide_all();
|
|
|
|
if (last_popover_elem !== undefined
|
|
|
|
&& last_popover_elem.get()[0] === element) {
|
|
|
|
// We want it to be the case that a user can dismiss a popover
|
|
|
|
// by clicking on the same element that caused the popover.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-20 05:11:25 +02:00
|
|
|
$(element).closest('.message_row').toggleClass('has_popover has_actions_popover');
|
2013-07-11 23:06:58 +02:00
|
|
|
current_msg_list.select_id(id);
|
|
|
|
var elt = $(element);
|
|
|
|
if (elt.data('popover') === undefined) {
|
|
|
|
var message = current_msg_list.get(id);
|
2016-10-22 04:26:35 +02:00
|
|
|
var editability = message_edit.get_editability(message);
|
2016-10-25 22:56:28 +02:00
|
|
|
var use_edit_icon;
|
2016-10-22 02:38:56 +02:00
|
|
|
var editability_menu_item;
|
|
|
|
if (editability === message_edit.editability_types.FULL) {
|
2016-10-25 22:56:28 +02:00
|
|
|
use_edit_icon = true;
|
2016-10-22 02:38:56 +02:00
|
|
|
editability_menu_item = i18n.t("Edit");
|
|
|
|
} else if (editability === message_edit.editability_types.TOPIC_ONLY) {
|
2016-10-25 22:56:28 +02:00
|
|
|
use_edit_icon = false;
|
2017-03-08 13:59:48 +01:00
|
|
|
editability_menu_item = i18n.t("View source / Edit topic");
|
2016-10-22 02:38:56 +02:00
|
|
|
} else {
|
2016-10-25 22:56:28 +02:00
|
|
|
use_edit_icon = false;
|
2017-03-08 13:57:42 +01:00
|
|
|
editability_menu_item = i18n.t("View source");
|
2016-10-22 02:38:56 +02:00
|
|
|
}
|
2013-09-09 20:24:21 +02:00
|
|
|
var can_mute_topic =
|
|
|
|
message.stream &&
|
|
|
|
message.subject &&
|
|
|
|
!muting.is_topic_muted(message.stream, message.subject);
|
2013-09-09 20:42:10 +02:00
|
|
|
var can_unmute_topic =
|
|
|
|
message.stream &&
|
|
|
|
message.subject &&
|
|
|
|
muting.is_topic_muted(message.stream, message.subject);
|
|
|
|
|
2017-02-20 02:37:58 +01:00
|
|
|
var should_display_edit_history_option = _.any(message.edit_history, function (entry) {
|
|
|
|
return entry.prev_content !== undefined;
|
2017-07-16 11:00:44 +02:00
|
|
|
}) && page_params.realm_allow_edit_history;
|
2017-11-08 13:40:46 +01:00
|
|
|
var should_display_delete_option = page_params.is_admin ||
|
|
|
|
(message.sent_by_me && page_params.realm_allow_message_deleting);
|
2013-07-11 23:06:58 +02:00
|
|
|
var args = {
|
2016-10-22 04:26:35 +02:00
|
|
|
message: message,
|
2016-10-25 22:56:28 +02:00
|
|
|
use_edit_icon: use_edit_icon,
|
2016-10-22 02:38:56 +02:00
|
|
|
editability_menu_item: editability_menu_item,
|
2013-09-09 20:24:21 +02:00
|
|
|
can_mute_topic: can_mute_topic,
|
2013-09-09 20:42:10 +02:00
|
|
|
can_unmute_topic: can_unmute_topic,
|
2016-12-02 13:23:23 +01:00
|
|
|
should_display_add_reaction_option: message.sent_by_me,
|
2017-02-20 02:37:58 +01:00
|
|
|
should_display_edit_history_option: should_display_edit_history_option,
|
2017-05-08 22:46:25 +02:00
|
|
|
conversation_time_uri: narrow.by_conversation_and_time_uri(message, true),
|
2017-04-25 15:25:31 +02:00
|
|
|
narrowed: narrow_state.active(),
|
2017-05-14 21:14:26 +02:00
|
|
|
should_display_delete_option: should_display_delete_option,
|
2013-07-11 23:06:58 +02:00
|
|
|
};
|
|
|
|
|
2017-03-13 17:17:47 +01:00
|
|
|
var ypos = elt.offset().top;
|
2013-07-11 23:06:58 +02:00
|
|
|
elt.popover({
|
2017-03-13 17:17:47 +01:00
|
|
|
// Popover height with 7 items in it is ~190 px
|
|
|
|
placement: ((message_viewport.height() - ypos) < 220) ? 'top' : 'bottom',
|
2013-07-11 23:06:58 +02:00
|
|
|
title: "",
|
2013-06-28 22:38:40 +02:00
|
|
|
content: templates.render('actions_popover_content', args),
|
2017-01-12 00:17:43 +01:00
|
|
|
trigger: "manual",
|
2013-06-28 22:38:40 +02:00
|
|
|
});
|
|
|
|
elt.popover("show");
|
|
|
|
current_actions_popover_elem = elt;
|
|
|
|
}
|
2013-07-11 23:06:58 +02:00
|
|
|
};
|
|
|
|
|
2013-11-07 18:12:48 +01:00
|
|
|
function get_action_menu_menu_items() {
|
2017-05-12 18:40:29 +02:00
|
|
|
if (!current_actions_popover_elem) {
|
|
|
|
blueslip.error('Trying to get menu items when action popover is closed.');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var popover_data = current_actions_popover_elem.data('popover');
|
|
|
|
if (!popover_data) {
|
|
|
|
blueslip.error('Cannot find popover data for actions menu.');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $('li:not(.divider):visible a', popover_data.$tip);
|
2013-11-07 18:12:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function focus_first_action_popover_item() {
|
|
|
|
// For now I recommend only calling this when the user opens the menu with a hotkey.
|
|
|
|
// Our popup menus act kind of funny when you mix keyboard and mouse.
|
|
|
|
var items = get_action_menu_menu_items();
|
2017-05-12 18:40:29 +02:00
|
|
|
if (!items) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-07 18:12:48 +01:00
|
|
|
items.eq(0).expectOne().focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.open_message_menu = function () {
|
|
|
|
var id = current_msg_list.selected_id();
|
2013-11-08 18:28:22 +01:00
|
|
|
popovers.toggle_actions_popover($(".selected_message .actions_hover")[0], id);
|
|
|
|
if (current_actions_popover_elem) {
|
|
|
|
focus_first_action_popover_item();
|
|
|
|
}
|
2013-11-07 18:12:48 +01:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2013-07-11 23:06:58 +02:00
|
|
|
exports.actions_menu_handle_keyboard = function (key) {
|
2013-11-07 18:12:48 +01:00
|
|
|
var items = get_action_menu_menu_items();
|
2017-05-12 18:40:29 +02:00
|
|
|
if (!items) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-11 23:06:58 +02:00
|
|
|
var index = items.index(items.filter(':focus'));
|
|
|
|
|
|
|
|
if (key === "enter" && index >= 0 && index < items.length) {
|
2017-08-23 21:09:55 +02:00
|
|
|
return items[index].click();
|
2013-07-11 23:06:58 +02:00
|
|
|
}
|
|
|
|
if (index === -1) {
|
|
|
|
index = 0;
|
2016-06-09 23:05:34 +02:00
|
|
|
} else if ((key === 'down_arrow' || key === 'vim_down') && index < items.length - 1) {
|
2016-11-30 19:05:04 +01:00
|
|
|
index += 1;
|
2016-06-09 23:05:34 +02:00
|
|
|
} else if ((key === 'up_arrow' || key === 'vim_up') && index > 0) {
|
2016-11-30 19:05:04 +01:00
|
|
|
index -= 1;
|
2013-07-11 23:06:58 +02:00
|
|
|
}
|
|
|
|
items.eq(index).focus();
|
|
|
|
};
|
2013-06-28 22:38:40 +02:00
|
|
|
|
2013-07-11 23:06:58 +02:00
|
|
|
exports.actions_popped = function () {
|
2013-06-28 22:38:40 +02:00
|
|
|
return current_actions_popover_elem !== undefined;
|
2013-07-11 23:06:58 +02:00
|
|
|
};
|
2013-06-28 22:38:40 +02:00
|
|
|
|
|
|
|
exports.hide_actions_popover = function () {
|
2013-07-11 23:06:58 +02:00
|
|
|
if (popovers.actions_popped()) {
|
2017-06-20 05:11:25 +02:00
|
|
|
$('.has_popover').removeClass('has_popover has_actions_popover');
|
2013-06-28 22:38:40 +02:00
|
|
|
current_actions_popover_elem.popover("destroy");
|
|
|
|
current_actions_popover_elem = undefined;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-07-11 23:06:58 +02:00
|
|
|
function message_info_popped() {
|
|
|
|
return current_message_info_popover_elem !== undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.hide_message_info_popover = function () {
|
|
|
|
if (message_info_popped()) {
|
|
|
|
current_message_info_popover_elem.popover("destroy");
|
|
|
|
current_message_info_popover_elem = undefined;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-08-22 20:17:07 +02:00
|
|
|
exports.hide_userlist_sidebar = function () {
|
|
|
|
$(".app-main .column-right").removeClass("expanded");
|
|
|
|
};
|
2013-07-11 23:06:58 +02:00
|
|
|
|
2015-11-25 18:41:32 +01:00
|
|
|
exports.hide_pm_list_sidebar = function () {
|
|
|
|
$(".app-main .column-left").removeClass("expanded");
|
|
|
|
};
|
|
|
|
|
2013-08-23 21:33:43 +02:00
|
|
|
exports.show_userlist_sidebar = function () {
|
|
|
|
$(".app-main .column-right").addClass("expanded");
|
2014-03-13 19:03:31 +01:00
|
|
|
resize.resize_page_components();
|
2013-08-23 21:33:43 +02:00
|
|
|
};
|
|
|
|
|
2015-11-25 18:41:32 +01:00
|
|
|
exports.show_pm_list_sidebar = function () {
|
|
|
|
$(".app-main .column-left").addClass("expanded");
|
|
|
|
resize.resize_page_components();
|
|
|
|
};
|
|
|
|
|
2016-11-17 23:16:29 +01:00
|
|
|
var current_user_sidebar_user_id;
|
2013-12-04 03:30:27 +01:00
|
|
|
var current_user_sidebar_popover;
|
2013-06-28 22:38:40 +02:00
|
|
|
|
|
|
|
function user_sidebar_popped() {
|
2013-12-04 03:30:27 +01:00
|
|
|
return current_user_sidebar_popover !== undefined;
|
2013-06-28 22:38:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
exports.hide_user_sidebar_popover = function () {
|
|
|
|
if (user_sidebar_popped()) {
|
2013-12-04 03:30:27 +01:00
|
|
|
// this hide_* method looks different from all the others since
|
|
|
|
// the presence list may be redrawn. Due to funkiness with jquery's .data()
|
|
|
|
// this would confuse $.popover("destroy"), which looks at the .data() attached
|
2016-12-02 15:16:33 +01:00
|
|
|
// to a certain element. We thus save off the .data("popover") in the
|
|
|
|
// show_user_sidebar_popover and inject it here before calling destroy.
|
2013-12-04 03:30:27 +01:00
|
|
|
$('#user_presences').data("popover", current_user_sidebar_popover);
|
|
|
|
$('#user_presences').popover("destroy");
|
2016-11-17 23:16:29 +01:00
|
|
|
current_user_sidebar_user_id = undefined;
|
2013-12-04 03:30:27 +01:00
|
|
|
current_user_sidebar_popover = undefined;
|
2013-06-28 22:38:40 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-05-23 20:01:24 +02:00
|
|
|
exports.show_sender_info = function () {
|
2017-09-30 17:23:31 +02:00
|
|
|
var $message = $(".selected_message");
|
|
|
|
var $sender = $message.find(".sender_info_hover");
|
|
|
|
var $prev_message = $message.prev();
|
|
|
|
while (!$sender[0]) {
|
|
|
|
$prev_message = $prev_message.prev();
|
|
|
|
if (!$prev_message) {
|
2017-05-23 20:01:24 +02:00
|
|
|
break;
|
|
|
|
}
|
2017-09-30 17:23:31 +02:00
|
|
|
$sender = $prev_message.find(".sender_info_hover");
|
2017-05-23 20:01:24 +02:00
|
|
|
}
|
2017-09-30 17:25:49 +02:00
|
|
|
var message = current_msg_list.get(rows.id($message));
|
|
|
|
var user = people.get_person_from_user_id(message.sender_id);
|
2017-09-30 17:37:49 +02:00
|
|
|
show_user_info_popover($sender[0], user, message);
|
2017-05-23 20:01:24 +02:00
|
|
|
};
|
|
|
|
|
2013-06-28 22:38:40 +02:00
|
|
|
exports.register_click_handlers = function () {
|
|
|
|
$("#main_div").on("click", ".actions_hover", function (e) {
|
|
|
|
var row = $(this).closest(".message_row");
|
|
|
|
e.stopPropagation();
|
2013-11-08 18:28:22 +01:00
|
|
|
popovers.toggle_actions_popover(this, rows.id(row));
|
2013-06-28 22:38:40 +02:00
|
|
|
});
|
|
|
|
|
2013-07-11 23:06:58 +02:00
|
|
|
$("#main_div").on("click", ".sender_info_hover", function (e) {
|
|
|
|
var row = $(this).closest(".message_row");
|
|
|
|
e.stopPropagation();
|
2017-09-30 17:25:49 +02:00
|
|
|
var message = current_msg_list.get(rows.id(row));
|
|
|
|
var user = people.get_person_from_user_id(message.sender_id);
|
2017-09-30 17:37:49 +02:00
|
|
|
show_user_info_popover(this, user, message);
|
2013-07-11 23:06:58 +02:00
|
|
|
});
|
|
|
|
|
2017-09-30 19:19:24 +02:00
|
|
|
$("#main_div").on("click", ".user-mention", function (e) {
|
|
|
|
var row = $(this).closest(".message_row");
|
|
|
|
e.stopPropagation();
|
|
|
|
var message = current_msg_list.get(rows.id(row));
|
|
|
|
var id = $(this).attr('data-user-id');
|
|
|
|
var user = people.get_person_from_user_id(id);
|
|
|
|
show_user_info_popover(this, user, message);
|
|
|
|
});
|
|
|
|
|
2013-06-28 22:38:40 +02:00
|
|
|
$('body').on('click', '.user_popover .narrow_to_private_messages', function (e) {
|
2016-11-15 14:22:52 +01:00
|
|
|
var user_id = $(e.target).parents('ul').attr('data-user-id');
|
|
|
|
var email = people.get_person_from_user_id(user_id).email;
|
|
|
|
|
2013-06-28 22:38:40 +02:00
|
|
|
popovers.hide_user_sidebar_popover();
|
|
|
|
narrow.by('pm-with', email, {select_first_unread: true, trigger: 'user sidebar popover'});
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('body').on('click', '.user_popover .narrow_to_messages_sent', function (e) {
|
2016-11-15 14:22:52 +01:00
|
|
|
var user_id = $(e.target).parents('ul').attr('data-user-id');
|
|
|
|
var email = people.get_person_from_user_id(user_id).email;
|
|
|
|
|
2013-06-28 22:38:40 +02:00
|
|
|
popovers.hide_user_sidebar_popover();
|
|
|
|
narrow.by('sender', email, {select_first_unread: true, trigger: 'user sidebar popover'});
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('body').on('click', '.user_popover .compose_private_message', function (e) {
|
2016-11-15 14:22:52 +01:00
|
|
|
var user_id = $(e.target).parents('ul').attr('data-user-id');
|
|
|
|
var email = people.get_person_from_user_id(user_id).email;
|
2013-06-28 22:38:40 +02:00
|
|
|
popovers.hide_user_sidebar_popover();
|
2016-11-15 14:22:52 +01:00
|
|
|
|
2017-03-18 17:41:47 +01:00
|
|
|
compose_actions.start('private', {private_message_recipient: email, trigger: 'sidebar user actions'});
|
2013-06-28 22:38:40 +02:00
|
|
|
e.stopPropagation();
|
2017-03-04 13:43:21 +01:00
|
|
|
e.preventDefault();
|
2013-06-28 22:38:40 +02:00
|
|
|
});
|
|
|
|
|
2016-12-28 06:29:13 +01:00
|
|
|
$('body').on('click', '.user_popover .mention_user', function (e) {
|
|
|
|
var user_id = $(e.target).parents('ul').attr('data-user-id');
|
2017-03-18 17:41:47 +01:00
|
|
|
compose_actions.start('stream', {trigger: 'sidebar user actions'});
|
2016-12-28 06:29:13 +01:00
|
|
|
var name = people.get_person_from_user_id(user_id).full_name;
|
|
|
|
var textarea = $("#new_message_content");
|
|
|
|
textarea.val('@**' + name + '** ');
|
|
|
|
popovers.hide_user_sidebar_popover();
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
2013-07-17 17:26:18 +02:00
|
|
|
$('body').on('click', '.sender_info_popover .narrow_to_private_messages', function (e) {
|
2017-02-07 17:31:57 +01:00
|
|
|
var user_id = $(e.target).parents('ul').attr('data-user-id');
|
|
|
|
var email = people.get_person_from_user_id(user_id).email;
|
2013-07-17 17:26:18 +02:00
|
|
|
narrow.by('pm-with', email, {select_first_unread: true, trigger: 'user sidebar popover'});
|
|
|
|
popovers.hide_message_info_popover();
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('body').on('click', '.sender_info_popover .narrow_to_messages_sent', function (e) {
|
2017-02-07 17:31:57 +01:00
|
|
|
var user_id = $(e.target).parents('ul').attr('data-user-id');
|
|
|
|
var email = people.get_person_from_user_id(user_id).email;
|
2013-07-17 17:26:18 +02:00
|
|
|
narrow.by('sender', email, {select_first_unread: true, trigger: 'user sidebar popover'});
|
|
|
|
popovers.hide_message_info_popover();
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
2016-12-28 06:29:13 +01:00
|
|
|
$('body').on('click', '.sender_info_popover .mention_user', function (e) {
|
2017-04-14 19:27:12 +02:00
|
|
|
compose_actions.respond_to_message({trigger: 'user sidebar popover'});
|
2016-12-28 06:29:13 +01:00
|
|
|
var user_id = $(e.target).parents('ul').attr('data-user-id');
|
|
|
|
var name = people.get_person_from_user_id(user_id).full_name;
|
|
|
|
var textarea = $("#new_message_content");
|
|
|
|
textarea.val('@**' + name + '** ');
|
|
|
|
popovers.hide_message_info_popover();
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
2013-12-03 23:05:38 +01:00
|
|
|
$('#user_presences').on('click', 'span.arrow', function (e) {
|
2013-12-04 03:30:27 +01:00
|
|
|
e.stopPropagation();
|
2013-12-03 23:05:38 +01:00
|
|
|
|
2013-12-04 03:30:27 +01:00
|
|
|
// use email of currently selected user, rather than some elem comparison,
|
|
|
|
// as the presence list may be redrawn with new elements.
|
|
|
|
var target = $(this).closest('li');
|
2016-11-17 23:16:29 +01:00
|
|
|
var user_id = target.find('a').attr('data-user-id');
|
2013-12-04 03:30:27 +01:00
|
|
|
|
2016-11-17 23:16:29 +01:00
|
|
|
if (current_user_sidebar_user_id === user_id) {
|
2013-12-03 23:05:38 +01:00
|
|
|
// If the popover is already shown, clicking again should toggle it.
|
2013-12-04 03:30:27 +01:00
|
|
|
popovers.hide_all();
|
2013-12-03 23:05:38 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
popovers.hide_all();
|
2013-12-04 03:30:27 +01:00
|
|
|
|
2013-12-03 23:05:38 +01:00
|
|
|
if (userlist_placement === "right") {
|
|
|
|
popovers.show_userlist_sidebar();
|
|
|
|
}
|
2017-03-04 13:43:21 +01:00
|
|
|
|
2017-09-28 01:52:25 +02:00
|
|
|
var user = people.get_person_from_user_id(user_id);
|
|
|
|
var user_email = user.email;
|
2017-03-04 13:43:21 +01:00
|
|
|
|
|
|
|
var args = {
|
|
|
|
user_email: user_email,
|
2017-09-30 17:11:31 +02:00
|
|
|
user_full_name: user.full_name,
|
2017-03-04 13:43:21 +01:00
|
|
|
user_id: user_id,
|
2017-04-02 21:01:58 +02:00
|
|
|
user_time: people.get_user_time(user_id),
|
2017-05-12 20:17:17 +02:00
|
|
|
presence_status: presence.get_status(user_id),
|
|
|
|
user_last_seen_time_status: user_last_seen_time_status(user_id),
|
2017-03-04 13:43:21 +01:00
|
|
|
pm_with_uri: narrow.pm_with_uri(user_email),
|
|
|
|
sent_by_uri: narrow.by_sender_uri(user_email),
|
|
|
|
private_message_class: "compose_private_message",
|
2017-10-26 21:00:30 +02:00
|
|
|
is_active: people.is_active_user_for_popover(user_id),
|
2017-03-04 13:43:21 +01:00
|
|
|
};
|
2013-12-03 23:05:38 +01:00
|
|
|
|
|
|
|
target.popover({
|
2017-10-18 19:16:41 +02:00
|
|
|
template: templates.render('user_info_popover', {class: "user_popover"}),
|
|
|
|
title: templates.render('user_info_popover_title', {user_avatar: "avatar/" + user_email}),
|
|
|
|
content: templates.render('user_info_popover_content', args),
|
|
|
|
trigger: "manual",
|
2017-01-12 00:17:43 +01:00
|
|
|
fixed: true,
|
2017-03-04 13:43:21 +01:00
|
|
|
placement: userlist_placement === "left" ? "right" : "left",
|
2013-12-03 23:05:38 +01:00
|
|
|
});
|
|
|
|
target.popover("show");
|
2017-03-04 13:43:21 +01:00
|
|
|
|
2017-09-30 17:54:26 +02:00
|
|
|
load_medium_avatar(user, $(".popover-avatar"));
|
2017-03-04 13:43:21 +01:00
|
|
|
|
2016-11-17 23:16:29 +01:00
|
|
|
current_user_sidebar_user_id = user_id;
|
2013-12-04 03:30:27 +01:00
|
|
|
current_user_sidebar_popover = target.data('popover');
|
|
|
|
|
2013-12-03 23:05:38 +01:00
|
|
|
});
|
2013-09-17 23:04:44 +02:00
|
|
|
|
2013-06-28 22:38:40 +02:00
|
|
|
$('body').on('click', '.respond_button', function (e) {
|
2017-02-02 13:08:17 +01:00
|
|
|
var textarea = $("#new_message_content");
|
|
|
|
var msgid = $(e.currentTarget).data("message-id");
|
|
|
|
|
2017-04-14 19:27:12 +02:00
|
|
|
compose_actions.respond_to_message({trigger: 'popover respond'});
|
2017-02-02 13:08:17 +01:00
|
|
|
channel.get({
|
|
|
|
url: '/json/messages/' + msgid,
|
|
|
|
idempotent: true,
|
|
|
|
success: function (data) {
|
|
|
|
if (textarea.val() === "") {
|
|
|
|
textarea.val("```quote\n" + data.raw_content +"\n```\n");
|
|
|
|
} else {
|
|
|
|
textarea.val(textarea.val() + "\n```quote\n" + data.raw_content +"\n```\n");
|
|
|
|
}
|
|
|
|
$("#new_message_content").trigger("autosize.resize");
|
|
|
|
},
|
|
|
|
});
|
2013-06-28 22:38:40 +02:00
|
|
|
popovers.hide_actions_popover();
|
|
|
|
e.stopPropagation();
|
2013-07-11 23:06:58 +02:00
|
|
|
e.preventDefault();
|
2013-06-28 22:38:40 +02:00
|
|
|
});
|
|
|
|
$('body').on('click', '.respond_personal_button', function (e) {
|
2017-04-14 19:27:12 +02:00
|
|
|
compose_actions.respond_to_message({reply_type: 'personal', trigger: 'popover respond pm'});
|
2013-07-17 17:26:18 +02:00
|
|
|
popovers.hide_all();
|
2013-06-28 22:38:40 +02:00
|
|
|
e.stopPropagation();
|
2013-07-11 23:06:58 +02:00
|
|
|
e.preventDefault();
|
2013-06-28 22:38:40 +02:00
|
|
|
});
|
|
|
|
$('body').on('click', '.popover_toggle_collapse', function (e) {
|
2017-02-02 21:22:24 +01:00
|
|
|
var msgid = $(e.currentTarget).data('message-id');
|
2013-08-14 22:00:32 +02:00
|
|
|
var row = current_msg_list.get_row(msgid);
|
2013-06-28 22:38:40 +02:00
|
|
|
var message = current_msg_list.get(rows.id(row));
|
|
|
|
|
2016-03-13 19:05:10 +01:00
|
|
|
popovers.hide_actions_popover();
|
2014-04-19 00:32:41 +02:00
|
|
|
|
2016-03-13 19:05:10 +01:00
|
|
|
if (row) {
|
2014-04-19 00:32:41 +02:00
|
|
|
if (message.collapsed) {
|
|
|
|
condense.uncollapse(row);
|
|
|
|
} else {
|
|
|
|
condense.collapse(row);
|
|
|
|
}
|
2016-03-13 19:05:10 +01:00
|
|
|
}
|
2013-06-28 22:38:40 +02:00
|
|
|
|
|
|
|
e.stopPropagation();
|
2013-07-11 23:06:58 +02:00
|
|
|
e.preventDefault();
|
2013-06-28 22:38:40 +02:00
|
|
|
});
|
|
|
|
$('body').on('click', '.popover_edit_message', function (e) {
|
2017-02-02 21:22:24 +01:00
|
|
|
var msgid = $(e.currentTarget).data('message-id');
|
2013-08-14 22:00:32 +02:00
|
|
|
var row = current_msg_list.get_row(msgid);
|
2013-06-28 22:38:40 +02:00
|
|
|
popovers.hide_actions_popover();
|
|
|
|
message_edit.start(row);
|
|
|
|
e.stopPropagation();
|
2013-07-11 23:06:58 +02:00
|
|
|
e.preventDefault();
|
2013-06-28 22:38:40 +02:00
|
|
|
});
|
2017-02-20 02:37:58 +01:00
|
|
|
$('body').on('click', '.view_edit_history', function (e) {
|
|
|
|
var msgid = $(e.currentTarget).data('msgid');
|
|
|
|
var row = current_msg_list.get_row(msgid);
|
|
|
|
var message = current_msg_list.get(rows.id(row));
|
2017-03-15 17:23:40 +01:00
|
|
|
var message_history_cancel_btn = $('#message-history-cancel');
|
2017-02-20 02:37:58 +01:00
|
|
|
|
|
|
|
popovers.hide_actions_popover();
|
|
|
|
message_edit.show_history(message);
|
2017-03-15 17:23:40 +01:00
|
|
|
message_history_cancel_btn.focus();
|
2017-02-20 02:37:58 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
2013-06-28 22:38:40 +02:00
|
|
|
|
2013-09-09 20:24:21 +02:00
|
|
|
$('body').on('click', '.popover_mute_topic', function (e) {
|
|
|
|
var stream = $(e.currentTarget).data('msg-stream');
|
|
|
|
var topic = $(e.currentTarget).data('msg-topic');
|
2016-11-29 20:22:52 +01:00
|
|
|
popovers.hide_actions_popover();
|
2017-03-23 06:57:36 +01:00
|
|
|
muting_ui.mute(stream, topic);
|
2013-09-09 20:24:21 +02:00
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
2013-09-09 20:42:10 +02:00
|
|
|
$('body').on('click', '.popover_unmute_topic', function (e) {
|
|
|
|
var stream = $(e.currentTarget).data('msg-stream');
|
|
|
|
var topic = $(e.currentTarget).data('msg-topic');
|
|
|
|
popovers.hide_actions_popover();
|
2017-10-18 01:12:22 +02:00
|
|
|
muting_ui.unmute(stream, topic);
|
2013-09-09 20:42:10 +02:00
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
2017-05-14 21:14:26 +02:00
|
|
|
$('body').on('click', '.delete_message', function (e) {
|
|
|
|
var msgid = $(e.currentTarget).data('message-id');
|
|
|
|
popovers.hide_actions_popover();
|
|
|
|
message_edit.delete_message(msgid);
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
2017-07-27 19:47:47 +02:00
|
|
|
new Clipboard('.copy_link');
|
2017-05-08 22:46:25 +02:00
|
|
|
|
|
|
|
$('body').on('click', '.copy_link', function (e) {
|
|
|
|
popovers.hide_actions_popover();
|
|
|
|
var id = $(this).attr("data-message-id");
|
|
|
|
var row = $("[zid='" + id + "']");
|
2017-08-23 21:08:49 +02:00
|
|
|
row.find(".alert-copied")
|
|
|
|
.css("display", "block")
|
|
|
|
.delay(1000).fadeOut(300);
|
2017-05-08 22:46:25 +02:00
|
|
|
|
2017-06-20 06:25:20 +02:00
|
|
|
setTimeout(function () {
|
|
|
|
// The Cliboard library works by focusing to a hidden textarea.
|
|
|
|
// We unfocus this so keyboard shortcuts, etc., will work again.
|
|
|
|
$(":focus").blur();
|
|
|
|
}, 0);
|
|
|
|
|
2017-05-08 22:46:25 +02:00
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
2017-01-26 19:57:27 +01:00
|
|
|
(function () {
|
|
|
|
var last_scroll = 0;
|
|
|
|
|
|
|
|
$('.app').on('scroll', function () {
|
|
|
|
var date = new Date().getTime();
|
|
|
|
|
|
|
|
// only run `popovers.hide_all()` if the last scroll was more
|
|
|
|
// than 250ms ago.
|
|
|
|
if (date - last_scroll > 250) {
|
|
|
|
popovers.hide_all();
|
|
|
|
}
|
|
|
|
|
|
|
|
// update the scroll time on every event to make sure it doesn't
|
|
|
|
// retrigger `hide_all` while still scrolling.
|
|
|
|
last_scroll = date;
|
|
|
|
});
|
|
|
|
}());
|
2016-12-31 21:05:50 +01:00
|
|
|
|
2013-06-28 22:38:40 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.any_active = function () {
|
|
|
|
// True if any popover (that this module manages) is currently shown.
|
2017-03-05 17:28:40 +01:00
|
|
|
return popovers.actions_popped() || user_sidebar_popped() ||
|
|
|
|
stream_popover.stream_popped() || stream_popover.topic_popped() ||
|
2017-04-29 09:43:13 +02:00
|
|
|
message_info_popped() || emoji_picker.reactions_popped();
|
2013-06-28 22:38:40 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.hide_all = function () {
|
2017-04-28 22:26:22 +02:00
|
|
|
$('.has_popover').removeClass('has_popover has_actions_popover has_emoji_popover');
|
2013-06-28 22:38:40 +02:00
|
|
|
popovers.hide_actions_popover();
|
2013-07-11 23:06:58 +02:00
|
|
|
popovers.hide_message_info_popover();
|
2017-04-28 22:26:22 +02:00
|
|
|
emoji_picker.hide_emoji_popover();
|
2017-03-05 17:28:40 +01:00
|
|
|
stream_popover.hide_stream_popover();
|
|
|
|
stream_popover.hide_topic_popover();
|
2013-07-08 23:35:06 +02:00
|
|
|
popovers.hide_user_sidebar_popover();
|
2013-08-22 20:17:07 +02:00
|
|
|
popovers.hide_userlist_sidebar();
|
2017-03-05 17:28:40 +01:00
|
|
|
stream_popover.restore_stream_list_size();
|
2017-01-04 02:44:49 +01:00
|
|
|
|
|
|
|
// look through all the popovers that have been added and removed.
|
|
|
|
list_of_popovers.forEach(function ($o) {
|
|
|
|
if (!document.body.contains($o.$element[0]) && $o.$tip) {
|
|
|
|
$o.$tip.remove();
|
|
|
|
}
|
|
|
|
});
|
2013-06-28 22:38:40 +02:00
|
|
|
};
|
|
|
|
|
2013-09-12 22:02:55 +02:00
|
|
|
exports.set_userlist_placement = function (placement) {
|
|
|
|
userlist_placement = placement || "right";
|
|
|
|
};
|
|
|
|
|
2017-08-25 19:59:23 +02:00
|
|
|
exports.compute_placement = function (elt, popover_height, popover_width,
|
|
|
|
prefer_vertical_positioning) {
|
2017-08-01 00:36:09 +02:00
|
|
|
var client_rect = elt.get(0).getBoundingClientRect();
|
|
|
|
var distance_from_top = client_rect.top;
|
|
|
|
var distance_from_bottom = message_viewport.height() - client_rect.bottom;
|
|
|
|
var distance_from_left = client_rect.left;
|
|
|
|
var distance_from_right = message_viewport.width() - client_rect.right;
|
|
|
|
|
|
|
|
var elt_will_fit_horizontally =
|
|
|
|
distance_from_left + elt.width() / 2 > popover_width / 2 &&
|
|
|
|
distance_from_right + elt.width() / 2 > popover_width / 2;
|
|
|
|
|
|
|
|
var elt_will_fit_vertically =
|
|
|
|
distance_from_bottom + elt.height() / 2 > popover_height / 2 &&
|
|
|
|
distance_from_top + elt.height() / 2 > popover_height / 2;
|
|
|
|
|
|
|
|
// default to placing the popover in the center of the screen
|
|
|
|
var placement = 'viewport_center';
|
|
|
|
|
|
|
|
// prioritize left/right over top/bottom
|
|
|
|
if (distance_from_top > popover_height && elt_will_fit_horizontally) {
|
2017-07-27 21:21:14 +02:00
|
|
|
placement = 'top';
|
|
|
|
}
|
2017-08-01 00:36:09 +02:00
|
|
|
if (distance_from_bottom > popover_height && elt_will_fit_horizontally) {
|
|
|
|
placement = 'bottom';
|
|
|
|
}
|
2017-08-25 19:59:23 +02:00
|
|
|
|
|
|
|
if (prefer_vertical_positioning && placement !== 'viewport_center') {
|
2017-11-09 16:26:38 +01:00
|
|
|
// If vertical positioning is preferred and the popover fits in
|
2017-08-25 19:59:23 +02:00
|
|
|
// either top or bottom position then return.
|
|
|
|
return placement;
|
|
|
|
}
|
|
|
|
|
2017-08-01 00:36:09 +02:00
|
|
|
if (distance_from_left > popover_width && elt_will_fit_vertically) {
|
2017-07-27 21:21:14 +02:00
|
|
|
placement = 'left';
|
|
|
|
}
|
2017-08-01 00:36:09 +02:00
|
|
|
if (distance_from_right > popover_width && elt_will_fit_vertically) {
|
2017-07-27 21:21:14 +02:00
|
|
|
placement = 'right';
|
|
|
|
}
|
2017-08-01 00:36:09 +02:00
|
|
|
|
2017-07-27 21:21:14 +02:00
|
|
|
return placement;
|
|
|
|
};
|
|
|
|
|
2013-06-28 22:38:40 +02:00
|
|
|
return exports;
|
|
|
|
}());
|
2016-12-29 12:23:07 +01:00
|
|
|
|
|
|
|
if (typeof module !== 'undefined') {
|
|
|
|
module.exports = popovers;
|
|
|
|
}
|