buddy_list: Refactor click handlers to not rely on placement of user-presence-link.

This commit is contained in:
evykassirer 2024-10-25 12:50:03 -07:00 committed by Tim Abbott
parent 94368dcf2b
commit 08e7c5feea
2 changed files with 13 additions and 14 deletions

View File

@ -515,8 +515,9 @@ export function initialize() {
// BUDDY LIST TOOLTIPS (not displayed on touch devices)
$(".buddy-list-section").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 user_id_string = $(e.currentTarget)
.closest(".user_sidebar_entry")
.attr("data-user-id");
const title_data = buddy_data.get_title_data(user_id_string, false);
// `target_node` is the `ul` element since it stays in DOM even after updates.
@ -531,28 +532,26 @@ export function initialize() {
);
}
do_render_buddy_list_tooltip(
$elem.parent(),
title_data,
get_target_node,
check_reference_removed,
);
const $elem = $(e.currentTarget)
.closest(".user_sidebar_entry")
.find(".selectable_sidebar_block");
do_render_buddy_list_tooltip($elem, title_data, get_target_node, check_reference_removed);
/*
The following implements a little tooltip giving the name for status emoji
when hovering them in the right sidebar. This requires special logic, to avoid
conflicting with the main tooltip or showing duplicate tooltips.
*/
$(".user-presence-link .status-emoji-name").off("mouseenter").off("mouseleave");
$(".user-presence-link .status-emoji-name").on("mouseenter", () => {
const instance = $elem.parent()[0]._tippy;
$(".user_sidebar_entry .status-emoji-name").off("mouseenter").off("mouseleave");
$(".user_sidebar_entry .status-emoji-name").on("mouseenter", () => {
const instance = $elem[0]._tippy;
if (instance && instance.state.isVisible) {
instance.destroy();
}
});
$(".user-presence-link .status-emoji-name").on("mouseleave", () => {
$(".user_sidebar_entry .status-emoji-name").on("mouseleave", () => {
do_render_buddy_list_tooltip(
$elem.parent(),
$elem,
title_data,
get_target_node,
check_reference_removed,

View File

@ -526,7 +526,7 @@ function get_user_card_popover_for_message_items() {
// Functions related to the user card popover in the user sidebar.
function toggle_sidebar_user_card_popover($target) {
const user_id = elem_to_user_id($target.find("a"));
const user_id = elem_to_user_id($target);
const user = people.get_by_user_id(user_id);
// Hiding popovers may mutate current_user_sidebar_user_id.