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;
|
2016-12-02 13:23:23 +01:00
|
|
|
var current_message_reactions_popover_elem;
|
2015-10-15 22:34:30 +02:00
|
|
|
var emoji_map_is_open = false;
|
2013-06-28 22:38:40 +02:00
|
|
|
|
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));
|
|
|
|
|
2013-07-11 23:06:58 +02:00
|
|
|
function show_message_info_popover(element, id) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
current_msg_list.select_id(id);
|
|
|
|
var elt = $(element);
|
|
|
|
if (elt.data('popover') === undefined) {
|
|
|
|
timerender.set_full_datetime(current_msg_list.get(id),
|
|
|
|
elt.closest(".message_row").find(".message_time"));
|
|
|
|
|
|
|
|
var message = current_msg_list.get(id);
|
2017-02-07 02:54:01 +01:00
|
|
|
var sender = people.get_person_from_user_id(message.sender_id);
|
|
|
|
var sender_email;
|
|
|
|
|
|
|
|
if (sender) {
|
|
|
|
sender_email = sender.email;
|
|
|
|
} else {
|
|
|
|
blueslip.debug('Bad sender in message' + message.sender_id);
|
|
|
|
sender_email = message.sender_email;
|
|
|
|
}
|
|
|
|
|
2013-06-28 22:38:40 +02:00
|
|
|
var args = {
|
|
|
|
message: message,
|
2017-02-09 01:53:50 +01:00
|
|
|
sender_email: sender_email,
|
2017-02-07 02:54:01 +01:00
|
|
|
pm_with_uri: narrow.pm_with_uri(sender_email),
|
|
|
|
sent_by_uri: narrow.by_sender_uri(sender_email),
|
2017-01-12 00:17:43 +01:00
|
|
|
narrowed: narrow.active(),
|
2013-06-28 22:38:40 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
var ypos = elt.offset().top - viewport.scrollTop();
|
|
|
|
elt.popover({
|
|
|
|
placement: (ypos > (viewport.height() - 300)) ? 'top' : 'bottom',
|
2013-07-11 23:06:58 +02:00
|
|
|
title: templates.render('message_info_popover_title', args),
|
|
|
|
content: templates.render('message_info_popover_content', args),
|
2017-01-12 00:17:43 +01:00
|
|
|
trigger: "manual",
|
2013-07-11 23:06:58 +02:00
|
|
|
});
|
|
|
|
elt.popover("show");
|
|
|
|
current_message_info_popover_elem = elt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-02 13:23:23 +01:00
|
|
|
exports.toggle_reactions_popover = function (element, id) {
|
|
|
|
var last_popover_elem = current_message_reactions_popover_elem;
|
|
|
|
popovers.hide_all();
|
2017-01-10 17:21:02 +01:00
|
|
|
$(element).closest('.message_row').toggleClass('has_popover has_reactions_popover');
|
2016-12-02 13:23:23 +01: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
current_msg_list.select_id(id);
|
|
|
|
var elt = $(element);
|
|
|
|
if (elt.data('popover') === undefined) {
|
|
|
|
var emojis = _.clone(emoji.emojis_name_to_css_class);
|
|
|
|
var emojis_used = reactions.get_emojis_used_by_user_for_message_id(id);
|
|
|
|
var realm_emojis = emoji.realm_emojis;
|
|
|
|
_.each(realm_emojis, function (realm_emoji, realm_emoji_name) {
|
|
|
|
emojis[realm_emoji_name] = {
|
|
|
|
name: realm_emoji_name,
|
|
|
|
is_realm_emoji: true,
|
2017-01-12 00:17:43 +01:00
|
|
|
url: realm_emoji.emoji_url,
|
2016-12-02 13:23:23 +01:00
|
|
|
};
|
|
|
|
});
|
|
|
|
_.each(emojis_used, function (emoji_name) {
|
|
|
|
var is_realm_emoji = emojis[emoji_name].is_realm_emoji;
|
|
|
|
var url = emojis[emoji_name].url;
|
|
|
|
emojis[emoji_name] = {
|
|
|
|
name: emoji_name,
|
|
|
|
has_reacted: true,
|
|
|
|
css_class: emoji.emoji_name_to_css_class(emoji_name),
|
|
|
|
is_realm_emoji: is_realm_emoji,
|
2017-01-12 00:17:43 +01:00
|
|
|
url: url,
|
2016-12-02 13:23:23 +01:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
var args = {
|
|
|
|
message_id: id,
|
|
|
|
emojis: emojis,
|
|
|
|
};
|
|
|
|
|
|
|
|
var approx_popover_height = 400;
|
|
|
|
var approx_popover_width = 400;
|
|
|
|
var distance_from_bottom = viewport.height() - elt.offset().top;
|
|
|
|
var distance_from_right = viewport.width() - elt.offset().left;
|
|
|
|
var will_extend_beyond_bottom_of_viewport = distance_from_bottom < approx_popover_height;
|
|
|
|
var will_extend_beyond_top_of_viewport = elt.offset().top < approx_popover_height;
|
|
|
|
var will_extend_beyond_left_of_viewport = elt.offset().left < (approx_popover_width / 2);
|
|
|
|
var will_extend_beyond_right_of_viewport = distance_from_right < (approx_popover_width / 2);
|
|
|
|
var placement = 'bottom';
|
|
|
|
if (will_extend_beyond_bottom_of_viewport && !will_extend_beyond_top_of_viewport) {
|
|
|
|
placement = 'top';
|
|
|
|
}
|
|
|
|
if (will_extend_beyond_right_of_viewport && !will_extend_beyond_left_of_viewport) {
|
|
|
|
placement = 'left';
|
|
|
|
}
|
|
|
|
if (will_extend_beyond_left_of_viewport && !will_extend_beyond_right_of_viewport) {
|
|
|
|
placement = 'right';
|
|
|
|
}
|
|
|
|
elt.prop('title', '');
|
|
|
|
elt.popover({
|
|
|
|
placement: placement,
|
|
|
|
title: "",
|
|
|
|
content: templates.render('reaction_popover_content', args),
|
2017-01-12 00:17:43 +01:00
|
|
|
trigger: "manual",
|
2016-12-02 13:23:23 +01:00
|
|
|
});
|
|
|
|
elt.popover("show");
|
|
|
|
elt.prop('title', 'Add reaction...');
|
|
|
|
$('.reaction-popover-filter').focus();
|
|
|
|
current_message_reactions_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();
|
2017-01-10 17:21:02 +01:00
|
|
|
$(element).closest('.message_row').toggleClass('has_popover has_actions_popover');
|
2013-07-11 23:06:58 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
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;
|
2016-10-22 02:38:56 +02:00
|
|
|
editability_menu_item = i18n.t("View Source");
|
|
|
|
}
|
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);
|
|
|
|
|
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,
|
2014-02-28 20:25:24 +01:00
|
|
|
conversation_time_uri: narrow.by_conversation_and_time_uri(message),
|
2017-01-12 00:17:43 +01:00
|
|
|
narrowed: narrow.active(),
|
2013-07-11 23:06:58 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
var ypos = elt.offset().top - viewport.scrollTop();
|
|
|
|
elt.popover({
|
|
|
|
placement: (ypos > (viewport.height() - 300)) ? 'top' : 'bottom',
|
|
|
|
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() {
|
|
|
|
return $('li:not(.divider):visible a', current_actions_popover_elem.data('popover').$tip);
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
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();
|
2013-07-11 23:06:58 +02:00
|
|
|
var index = items.index(items.filter(':focus'));
|
|
|
|
|
|
|
|
if (key === "enter" && index >= 0 && index < items.length) {
|
|
|
|
return items.eq(index).trigger('click');
|
|
|
|
}
|
|
|
|
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()) {
|
2013-06-28 22:38:40 +02:00
|
|
|
current_actions_popover_elem.popover("destroy");
|
|
|
|
current_actions_popover_elem = undefined;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-08-27 01:47:30 +02:00
|
|
|
exports.topic_ops = {
|
|
|
|
mute: function (stream, topic) {
|
|
|
|
popovers.hide_topic_sidebar_popover();
|
|
|
|
muting.mute_topic(stream, topic);
|
|
|
|
muting_ui.persist_and_rerender();
|
|
|
|
muting_ui.notify_with_undo_option(stream, topic);
|
|
|
|
},
|
|
|
|
// we don't run a unmute_notif function because it isn't an issue as much
|
|
|
|
// if someone accidentally unmutes a stream rather than if they mute it
|
|
|
|
// and miss out on info.
|
|
|
|
unmute: function (stream, topic) {
|
|
|
|
popovers.hide_topic_sidebar_popover();
|
|
|
|
muting.unmute_topic(stream, topic);
|
|
|
|
muting_ui.persist_and_rerender();
|
2017-01-12 00:17:43 +01:00
|
|
|
},
|
2016-08-27 01:47:30 +02:00
|
|
|
};
|
|
|
|
|
2013-07-11 23:06:58 +02:00
|
|
|
function message_info_popped() {
|
|
|
|
return current_message_info_popover_elem !== undefined;
|
|
|
|
}
|
|
|
|
|
2016-12-02 13:23:23 +01:00
|
|
|
function reaction_popped() {
|
|
|
|
return current_message_reactions_popover_elem !== undefined;
|
|
|
|
}
|
|
|
|
|
2013-07-11 23:06:58 +02:00
|
|
|
exports.hide_message_info_popover = function () {
|
|
|
|
if (message_info_popped()) {
|
|
|
|
current_message_info_popover_elem.popover("destroy");
|
|
|
|
current_message_info_popover_elem = undefined;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-12-02 13:23:23 +01:00
|
|
|
exports.hide_reactions_popover = function () {
|
|
|
|
if (reaction_popped()) {
|
|
|
|
current_message_reactions_popover_elem.popover("destroy");
|
|
|
|
current_message_reactions_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
|
|
|
|
2013-08-23 21:33:43 +02:00
|
|
|
exports.hide_streamlist_sidebar = function () {
|
|
|
|
$(".app-main .column-left").removeClass("expanded");
|
|
|
|
};
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
exports.show_streamlist_sidebar = function () {
|
|
|
|
$(".app-main .column-left").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();
|
|
|
|
};
|
|
|
|
|
2013-06-28 22:38:40 +02:00
|
|
|
var current_stream_sidebar_elem;
|
2013-09-17 23:04:44 +02:00
|
|
|
var current_topic_sidebar_elem;
|
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
|
|
|
|
2013-09-12 22:02:55 +02:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
function stream_sidebar_popped() {
|
|
|
|
return current_stream_sidebar_elem !== undefined;
|
|
|
|
}
|
|
|
|
|
2013-09-17 23:04:44 +02:00
|
|
|
function topic_sidebar_popped() {
|
|
|
|
return current_topic_sidebar_elem !== undefined;
|
|
|
|
}
|
|
|
|
|
2015-10-15 22:34:30 +02:00
|
|
|
exports.hide_emoji_map_popover = function () {
|
|
|
|
if (emoji_map_is_open) {
|
|
|
|
$('.emoji_popover').css('display', 'none');
|
|
|
|
$('.drag').css('display', 'none');
|
|
|
|
emoji_map_is_open = false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-06-28 22:38:40 +02:00
|
|
|
exports.hide_stream_sidebar_popover = function () {
|
|
|
|
if (stream_sidebar_popped()) {
|
|
|
|
$(current_stream_sidebar_elem).popover("destroy");
|
|
|
|
current_stream_sidebar_elem = undefined;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-09-17 23:04:44 +02:00
|
|
|
exports.hide_topic_sidebar_popover = function () {
|
|
|
|
if (topic_sidebar_popped()) {
|
|
|
|
$(current_topic_sidebar_elem).popover("destroy");
|
|
|
|
current_topic_sidebar_elem = 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
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-10-15 22:34:30 +02:00
|
|
|
function render_emoji_popover() {
|
2017-01-28 00:25:01 +01:00
|
|
|
var content = (function () {
|
|
|
|
var map = {};
|
|
|
|
for (var x in emoji.emojis_name_to_css_class) {
|
|
|
|
if (!emoji.realm_emojis[x]) {
|
|
|
|
map[x] = {
|
|
|
|
name: x,
|
|
|
|
css_name: emoji.emojis_name_to_css_class[x],
|
|
|
|
url: emoji.emojis_by_name[x],
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return templates.render('emoji_popover_content', {
|
|
|
|
emoji_list: map,
|
|
|
|
realm_emoji: emoji.realm_emojis,
|
|
|
|
});
|
|
|
|
}());
|
2015-10-15 22:34:30 +02:00
|
|
|
|
|
|
|
$('.emoji_popover').append(content);
|
|
|
|
|
|
|
|
$('.drag').show();
|
|
|
|
$('.emoji_popover').css('display', 'inline-block');
|
|
|
|
|
|
|
|
$("#new_message_content").focus();
|
|
|
|
|
|
|
|
emoji_map_is_open = true;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
});
|
|
|
|
|
2016-12-02 13:23:23 +01:00
|
|
|
$("#main_div").on("click", ".reaction_button", function (e) {
|
|
|
|
var row = $(this).closest(".message_row");
|
|
|
|
e.stopPropagation();
|
|
|
|
popovers.toggle_reactions_popover(this, rows.id(row));
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2016-12-31 06:38:23 +01:00
|
|
|
$("body").on("click", ".actions_popover .reaction_button", function (e) {
|
2017-02-02 21:22:24 +01:00
|
|
|
var msgid = $(e.currentTarget).data('message-id');
|
2017-01-03 19:58:46 +01:00
|
|
|
e.preventDefault();
|
2016-12-02 13:23:23 +01:00
|
|
|
e.stopPropagation();
|
2016-12-31 06:38:23 +01:00
|
|
|
// HACK: Because we need the popover to be based off an
|
|
|
|
// element that definitely exists in the page even if the
|
|
|
|
// message wasn't sent by us and thus the .reaction_hover
|
2017-01-10 10:07:38 +01:00
|
|
|
// element is not present, we use the message's
|
|
|
|
// .icon-vector-chevron-down element as the base for the popover.
|
|
|
|
popovers.toggle_reactions_popover($(".selected_message .icon-vector-chevron-down")[0], msgid);
|
2016-12-02 13:23:23 +01: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();
|
|
|
|
show_message_info_popover(this, rows.id(row));
|
|
|
|
});
|
|
|
|
|
2016-10-15 01:13:40 +02:00
|
|
|
(function () {
|
|
|
|
// create locally scoped variables for drag tracking.
|
|
|
|
var meta = {
|
|
|
|
drag: false,
|
|
|
|
c: {
|
2017-01-12 00:17:43 +01:00
|
|
|
y: null,
|
2016-10-15 01:13:40 +02:00
|
|
|
},
|
|
|
|
$popover: $(".emoji_popover"),
|
|
|
|
MIN_HEIGHT: 25,
|
2017-01-12 00:17:43 +01:00
|
|
|
MAX_HEIGHT: 300,
|
2016-10-15 01:13:40 +02:00
|
|
|
};
|
2015-10-15 22:34:30 +02:00
|
|
|
|
2016-10-15 01:13:40 +02:00
|
|
|
// drag must start within the .drag zone.
|
|
|
|
$(".drag").on("mousedown", function (e) {
|
|
|
|
meta.drag = true;
|
|
|
|
meta.c.y = e.screenY;
|
|
|
|
});
|
2015-10-15 22:34:30 +02:00
|
|
|
|
2016-10-15 01:13:40 +02:00
|
|
|
// mouse move that originated in .drag zone can go anywhere.
|
|
|
|
$("body").on("mousemove", function (e) {
|
|
|
|
if (meta.drag) {
|
|
|
|
var diff = e.screenY - meta.c.y;
|
|
|
|
var resolved_height = meta.$popover.height() - diff;
|
2015-10-15 22:34:30 +02:00
|
|
|
|
2016-10-15 01:13:40 +02:00
|
|
|
if (resolved_height > meta.MIN_HEIGHT && resolved_height < meta.MAX_HEIGHT) {
|
|
|
|
meta.$popover.height(resolved_height);
|
|
|
|
}
|
|
|
|
meta.c.y = e.screenY;
|
|
|
|
}
|
|
|
|
});
|
2015-10-15 22:34:30 +02:00
|
|
|
|
2016-10-15 01:13:40 +02:00
|
|
|
// drag ends on mouseup. This cancels all drag events without interfering
|
|
|
|
// with any other events.
|
|
|
|
$("body").on("mouseup", function () {
|
|
|
|
meta.drag = false;
|
|
|
|
});
|
|
|
|
}());
|
2015-10-15 22:34:30 +02:00
|
|
|
|
|
|
|
$("body").on("click", ".emoji_popover", function (e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
|
|
|
$(".emoji_popover").on("click", ".emoji", function (e) {
|
|
|
|
var emoji_choice = $(e.target).attr("title");
|
|
|
|
var textarea = $("#new_message_content");
|
2017-01-08 13:02:38 +01:00
|
|
|
textarea.caret(emoji_choice);
|
2015-10-15 22:34:30 +02:00
|
|
|
textarea.focus();
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#compose").on("click", "#emoji_map", function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
if (emoji_map_is_open) {
|
|
|
|
// If the popover is already shown, clicking again should toggle it.
|
|
|
|
popovers.hide_emoji_map_popover();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
popovers.hide_all();
|
|
|
|
render_emoji_popover();
|
|
|
|
});
|
|
|
|
|
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
|
|
|
|
2016-12-03 03:08:47 +01:00
|
|
|
compose.start('private', {private_message_recipient: email, trigger: 'sidebar user actions'});
|
2013-06-28 22:38:40 +02:00
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
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');
|
|
|
|
compose.start('stream', {trigger: 'sidebar user actions'});
|
|
|
|
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) {
|
|
|
|
compose.respond_to_message({trigger: 'user sidebar popover'});
|
|
|
|
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
|
|
|
var name = target.find('a').attr('data-name');
|
|
|
|
|
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();
|
|
|
|
}
|
2016-11-15 14:22:52 +01:00
|
|
|
var template_vars = {user_id: user_id, name: name};
|
2013-12-04 03:30:27 +01:00
|
|
|
var content = templates.render('user_sidebar_actions', template_vars);
|
2013-12-03 23:05:38 +01:00
|
|
|
|
|
|
|
target.popover({
|
2013-12-04 03:30:27 +01:00
|
|
|
content: content,
|
2013-12-03 23:05:38 +01:00
|
|
|
placement: userlist_placement === "left" ? "right" : "left",
|
|
|
|
trigger: "manual",
|
2017-01-12 00:17:43 +01:00
|
|
|
fixed: true,
|
2013-12-03 23:05:38 +01:00
|
|
|
});
|
|
|
|
target.popover("show");
|
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
|
|
|
|
|
|
|
$('#stream_filters').on('click', '.topic-sidebar-arrow', function (e) {
|
|
|
|
var elt = e.target;
|
|
|
|
|
|
|
|
if (topic_sidebar_popped()
|
|
|
|
&& current_topic_sidebar_elem === elt) {
|
|
|
|
// If the popover is already shown, clicking again should toggle it.
|
|
|
|
popovers.hide_topic_sidebar_popover();
|
|
|
|
e.stopPropagation();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
popovers.hide_all();
|
|
|
|
popovers.show_streamlist_sidebar();
|
|
|
|
|
2016-11-05 19:34:47 +01:00
|
|
|
var stream_name = $(elt).closest('.topic-list').expectOne().attr('data-stream');
|
2013-09-17 23:04:44 +02:00
|
|
|
var topic_name = $(elt).closest('li').expectOne().attr('data-name');
|
|
|
|
|
2013-09-18 00:29:42 +02:00
|
|
|
var is_muted = muting.is_topic_muted(stream_name, topic_name);
|
2013-10-11 18:25:10 +02:00
|
|
|
var can_mute_topic = !is_muted;
|
|
|
|
var can_unmute_topic = is_muted;
|
2013-09-18 00:29:42 +02:00
|
|
|
|
2013-09-17 23:04:44 +02:00
|
|
|
var content = templates.render('topic_sidebar_actions', {
|
2016-12-03 03:08:47 +01:00
|
|
|
stream_name: stream_name,
|
|
|
|
topic_name: topic_name,
|
|
|
|
can_mute_topic: can_mute_topic,
|
2017-01-12 00:17:43 +01:00
|
|
|
can_unmute_topic: can_unmute_topic,
|
2013-09-17 23:04:44 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
$(elt).popover({
|
|
|
|
content: content,
|
|
|
|
trigger: "manual",
|
2017-01-12 00:17:43 +01:00
|
|
|
fixed: true,
|
2013-09-17 23:04:44 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
$(elt).popover("show");
|
|
|
|
|
|
|
|
current_topic_sidebar_elem = elt;
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('body').on('click', '.narrow_to_topic', function (e) {
|
|
|
|
popovers.hide_topic_sidebar_popover();
|
|
|
|
|
|
|
|
var row = $(e.currentTarget).closest('.narrow_to_topic').expectOne();
|
|
|
|
var stream_name = row.attr('data-stream-name');
|
|
|
|
var topic_name = row.attr('data-topic-name');
|
|
|
|
|
2014-02-10 20:53:38 +01:00
|
|
|
var operators = [
|
|
|
|
{operator: 'stream', operand: stream_name},
|
2017-01-12 00:17:43 +01:00
|
|
|
{operator: 'topic', operand: topic_name},
|
2014-02-10 20:53:38 +01:00
|
|
|
];
|
2013-09-17 23:04:44 +02:00
|
|
|
var opts = {select_first_unread: true, trigger: 'sidebar'};
|
|
|
|
narrow.activate(operators, opts);
|
|
|
|
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
2013-09-18 00:29:42 +02:00
|
|
|
$('body').on('click', '.sidebar-popover-mute-topic', function (e) {
|
2013-09-30 19:38:01 +02:00
|
|
|
var stream = $(e.currentTarget).attr('data-stream-name');
|
|
|
|
var topic = $(e.currentTarget).attr('data-topic-name');
|
2016-08-27 01:47:30 +02:00
|
|
|
exports.topic_ops.mute(stream, topic);
|
2013-09-18 00:29:42 +02:00
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('body').on('click', '.sidebar-popover-unmute-topic', function (e) {
|
2013-09-30 19:38:01 +02:00
|
|
|
var stream = $(e.currentTarget).attr('data-stream-name');
|
|
|
|
var topic = $(e.currentTarget).attr('data-topic-name');
|
2016-08-27 01:47:30 +02:00
|
|
|
exports.topic_ops.unmute(stream, topic);
|
2013-09-18 00:29:42 +02:00
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
2016-05-08 15:20:51 +02:00
|
|
|
$('body').on('click', '.sidebar-popover-mark-topic-read', function (e) {
|
|
|
|
var topic = $(e.currentTarget).attr('data-topic-name');
|
|
|
|
var stream = $(e.currentTarget).attr('data-stream-name');
|
|
|
|
popovers.hide_topic_sidebar_popover();
|
|
|
|
unread.mark_topic_as_read(stream,topic);
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
2013-09-18 00:29:42 +02:00
|
|
|
|
2013-09-17 21:24:00 +02:00
|
|
|
$('#stream_filters').on('click', '.stream-sidebar-arrow', function (e) {
|
2013-06-28 22:38:40 +02:00
|
|
|
var elt = e.target;
|
|
|
|
if (stream_sidebar_popped()
|
|
|
|
&& current_stream_sidebar_elem === elt) {
|
|
|
|
// If the popover is already shown, clicking again should toggle it.
|
|
|
|
popovers.hide_stream_sidebar_popover();
|
2013-08-23 21:33:43 +02:00
|
|
|
e.stopPropagation();
|
2013-06-28 22:38:40 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-09 00:58:08 +02:00
|
|
|
popovers.hide_all();
|
2013-08-23 21:33:43 +02:00
|
|
|
popovers.show_streamlist_sidebar();
|
2013-06-28 22:38:40 +02:00
|
|
|
|
|
|
|
var stream = $(elt).parents('li').attr('data-name');
|
|
|
|
|
|
|
|
$(elt).popover({
|
2016-12-03 03:08:47 +01:00
|
|
|
content: templates.render('stream_sidebar_actions', {stream: stream_data.get_sub(stream)}),
|
2013-06-28 22:38:40 +02:00
|
|
|
trigger: "manual",
|
2017-01-12 00:17:43 +01:00
|
|
|
fixed: true,
|
2013-06-28 22:38:40 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// This little function is a workaround for the fact that
|
|
|
|
// Bootstrap popovers don't properly handle being resized --
|
|
|
|
// so after resizing our popover to add in the spectrum color
|
|
|
|
// picker, we need to adjust its height accordingly.
|
|
|
|
function update_spectrum(popover, update_func) {
|
|
|
|
var initial_height = popover[0].offsetHeight;
|
|
|
|
|
|
|
|
var colorpicker = popover.find('.colorpicker-container').find('.colorpicker');
|
|
|
|
update_func(colorpicker);
|
|
|
|
var after_height = popover[0].offsetHeight;
|
|
|
|
|
|
|
|
var popover_root = popover.closest(".popover");
|
|
|
|
var current_top_px = parseFloat(popover_root.css('top').replace('px', ''));
|
|
|
|
var height_delta = - (after_height - initial_height) * 0.5;
|
|
|
|
|
|
|
|
popover_root.css('top', (current_top_px + height_delta) + "px");
|
|
|
|
}
|
|
|
|
|
|
|
|
$(elt).popover("show");
|
2014-02-07 16:55:54 +01:00
|
|
|
var data_id = stream_data.get_sub(stream).stream_id;
|
|
|
|
var popover = $('.streams_popover[data-id=' + data_id + ']');
|
2013-06-28 22:38:40 +02:00
|
|
|
update_spectrum(popover, function (colorpicker) {
|
2013-08-07 19:28:06 +02:00
|
|
|
colorpicker.spectrum(stream_color.sidebar_popover_colorpicker_options);
|
2013-06-28 22:38:40 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
$('.streams_popover').on('click', '.custom_color', function (e) {
|
2013-07-09 20:53:07 +02:00
|
|
|
update_spectrum($(e.target).closest('.streams_popover'), function (colorpicker) {
|
2013-06-28 22:38:40 +02:00
|
|
|
colorpicker.spectrum("destroy");
|
2013-08-07 19:28:06 +02:00
|
|
|
colorpicker.spectrum(stream_color.sidebar_popover_colorpicker_options_full);
|
2013-06-28 22:38:40 +02:00
|
|
|
// In theory this should clean up the old color picker,
|
|
|
|
// but this seems a bit flaky -- the new colorpicker
|
|
|
|
// doesn't fire until you click a button, but the buttons
|
|
|
|
// have been hidden. We work around this by just manually
|
|
|
|
// fixing it up here.
|
|
|
|
colorpicker.parent().find('.sp-container').removeClass('sp-buttons-disabled');
|
2013-07-29 22:29:38 +02:00
|
|
|
$(e.target).hide();
|
2013-06-28 22:38:40 +02:00
|
|
|
});
|
|
|
|
|
2016-12-02 14:06:06 +01:00
|
|
|
$('.streams_popover').on('click', 'a.sp-cancel', function () {
|
2013-06-28 22:38:40 +02:00
|
|
|
popovers.hide_stream_sidebar_popover();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
current_stream_sidebar_elem = elt;
|
2013-07-08 23:35:06 +02:00
|
|
|
e.stopPropagation();
|
2013-06-28 22:38:40 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
$('body').on('click', '.respond_button', function (e) {
|
2016-06-29 00:27:50 +02:00
|
|
|
compose.respond_to_message({trigger: 'popover respond'});
|
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) {
|
2016-06-29 00:27:50 +02:00
|
|
|
compose.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
|
|
|
});
|
2013-10-10 22:05:20 +02:00
|
|
|
$('body').on('click', '.popover_narrow_by_id', function (e) {
|
|
|
|
var msgid = $(e.currentTarget).data('msgid');
|
|
|
|
popovers.hide_actions_popover();
|
|
|
|
narrow.by_id(msgid, {trigger: 'popover'});
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
2013-11-25 16:54:08 +01:00
|
|
|
$('body').on('click', '.popover_narrow_by_conversation_and_time', function (e) {
|
2017-02-02 21:22:24 +01:00
|
|
|
var msgid = $(e.currentTarget).data('message-id');
|
2013-11-25 16:54:08 +01:00
|
|
|
popovers.hide_actions_popover();
|
|
|
|
narrow.by_conversation_and_time(msgid, {trigger: 'popover'});
|
|
|
|
e.stopPropagation();
|
|
|
|
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
|
|
|
});
|
|
|
|
|
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();
|
2016-08-27 01:47:30 +02:00
|
|
|
exports.topic_ops.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();
|
|
|
|
muting.unmute_topic(stream, topic);
|
2013-09-10 20:07:24 +02:00
|
|
|
muting_ui.persist_and_rerender();
|
2013-09-09 20:42:10 +02:00
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
2013-06-28 22:38:40 +02:00
|
|
|
$('body').on('click', '.toggle_home', function (e) {
|
|
|
|
var stream = $(e.currentTarget).parents('ul').attr('data-name');
|
|
|
|
popovers.hide_stream_sidebar_popover();
|
|
|
|
subs.toggle_home(stream);
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('body').on('click', '.narrow_to_stream', function (e) {
|
|
|
|
var stream = $(e.currentTarget).parents('ul').attr('data-name');
|
|
|
|
popovers.hide_stream_sidebar_popover();
|
|
|
|
narrow.by('stream', stream, {select_first_unread: true, trigger: 'sidebar popover'});
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('body').on('click', '.compose_to_stream', function (e) {
|
|
|
|
var stream = $(e.currentTarget).parents('ul').attr('data-name');
|
|
|
|
popovers.hide_stream_sidebar_popover();
|
2016-12-03 03:08:47 +01:00
|
|
|
compose.start('stream', {stream: stream, trigger: 'sidebar stream actions'});
|
2013-06-28 22:38:40 +02:00
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
2016-05-08 15:20:51 +02:00
|
|
|
$('body').on('click', '.mark_stream_as_read', function (e) {
|
|
|
|
var stream = $(e.currentTarget).parents('ul').attr('data-name');
|
|
|
|
popovers.hide_stream_sidebar_popover();
|
|
|
|
unread.mark_stream_as_read(stream);
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
2016-07-01 07:26:09 +02:00
|
|
|
$('body').on('click', '.pin_to_top', function (e) {
|
|
|
|
var stream = $(e.currentTarget).parents('ul').attr('data-name');
|
|
|
|
popovers.hide_stream_sidebar_popover();
|
|
|
|
subs.toggle_pin_to_top_stream(stream);
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
2013-06-28 22:38:40 +02:00
|
|
|
$('body').on('click', '.open_stream_settings', function (e) {
|
|
|
|
var stream = $(e.currentTarget).parents('ul').attr('data-name');
|
|
|
|
popovers.hide_stream_sidebar_popover();
|
2016-11-01 22:32:10 +01:00
|
|
|
|
|
|
|
window.location.hash = "#subscriptions";
|
|
|
|
// the template for subs needs to render.
|
|
|
|
|
|
|
|
subs.onlaunch("narrow_to_row", function () {
|
|
|
|
$(".stream-row[data-stream-name='" + stream + "']").click();
|
|
|
|
}, true);
|
2013-06-28 22:38:40 +02:00
|
|
|
});
|
2013-07-11 23:06:58 +02:00
|
|
|
|
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.
|
2016-12-02 15:16:33 +01:00
|
|
|
return popovers.actions_popped() || user_sidebar_popped() || stream_sidebar_popped() ||
|
2016-12-02 13:23:23 +01:00
|
|
|
topic_sidebar_popped() || message_info_popped() || emoji_map_is_open ||
|
|
|
|
reaction_popped();
|
2013-06-28 22:38:40 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.hide_all = function () {
|
2017-01-10 17:21:02 +01:00
|
|
|
$('.has_popover').removeClass('has_popover has_actions_popover has_reactions_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();
|
2016-12-02 13:23:23 +01:00
|
|
|
popovers.hide_reactions_popover();
|
2013-07-08 23:35:06 +02:00
|
|
|
popovers.hide_stream_sidebar_popover();
|
2013-09-17 23:04:44 +02:00
|
|
|
popovers.hide_topic_sidebar_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();
|
2013-08-23 21:33:43 +02:00
|
|
|
popovers.hide_streamlist_sidebar();
|
2015-10-15 22:34:30 +02:00
|
|
|
popovers.hide_emoji_map_popover();
|
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";
|
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
}
|