Add abstraction for manipulating userinfo popovers

(imported from commit 155302f103cfef8475482339596eafc594467532)
This commit is contained in:
Zev Benjamin 2012-11-15 20:30:44 -05:00
parent a5ea766ff6
commit da6cc30134
3 changed files with 32 additions and 22 deletions

View File

@ -44,8 +44,8 @@ var globals =
// ui.js // ui.js
+ ' register_onclick hide_email show_email focus_on' + ' register_onclick hide_email show_email focus_on'
+ ' report_error report_success report_message clicking mouse_moved' + ' report_error report_success report_message clicking mouse_moved'
+ ' userinfo_currently_popped update_gravatars gravatar_stamp' + ' userinfo_currently_popped hide_userinfo_popover update_gravatars'
+ ' register_user_info_mouseover register_user_info_mouseout' + ' gravatar_stamp register_user_info_mouseover register_user_info_mouseout'
// zephyr.js // zephyr.js
+ ' message_array message_dict get_updates_params' + ' message_array message_dict get_updates_params'

View File

@ -78,9 +78,8 @@ function process_hotkey(e) {
} }
return false; return false;
case 27: // Esc: close userinfo popup, cancel compose, or un-narrow case 27: // Esc: close userinfo popup, cancel compose, or un-narrow
if (userinfo_currently_popped !== undefined) { if (userinfo_currently_popped()) {
userinfo_currently_popped.popover("destroy"); hide_userinfo_popover();
userinfo_currently_popped = undefined;
} else if (compose.composing()) { } else if (compose.composing()) {
compose.cancel(); compose.cancel();
} else { } else {

View File

@ -216,17 +216,11 @@ function show_api_key_box() {
$("#api_key_button_box").hide(); $("#api_key_button_box").hide();
} }
var userinfo_currently_popped; var current_userinfo_popover_elem;
function userinfo_popover(event, element, id) { function show_userinfo_popover(element, id) {
event.stopPropagation();
select_message_by_id(id); select_message_by_id(id);
var elt = $(element); var elt = $(element);
if (elt.data('popover') === undefined) { if (elt.data('popover') === undefined) {
// One popover at a time.
if (userinfo_currently_popped) {
userinfo_currently_popped.popover("destroy");
userinfo_currently_popped = undefined;
}
var message = message_dict[id]; var message = message_dict[id];
elt.popover({placement: "bottom", elt.popover({placement: "bottom",
title: templates.userinfo_popover_title(message), title: templates.userinfo_popover_title(message),
@ -234,13 +228,21 @@ function userinfo_popover(event, element, id) {
trigger: "manual" trigger: "manual"
}); });
elt.popover("show"); elt.popover("show");
userinfo_currently_popped = elt; current_userinfo_popover_elem = elt;
} else {
elt.popover("destroy");
userinfo_currently_popped = undefined;
} }
} }
function hide_userinfo_popover() {
if (userinfo_currently_popped()) {
current_userinfo_popover_elem.popover("destroy");
current_userinfo_popover_elem = undefined;
}
}
function userinfo_currently_popped() {
return current_userinfo_popover_elem !== undefined;
}
function safari_composebox_hack(forwards) { function safari_composebox_hack(forwards) {
// OK, so the situation here is basically a lot of work so that // OK, so the situation here is basically a lot of work so that
// Tab-Enter is a valid hotkey for sending a message in Safari. // Tab-Enter is a valid hotkey for sending a message in Safari.
@ -427,10 +429,7 @@ $(function () {
search.initialize(); search.initialize();
$("body").bind('click', function() { $("body").bind('click', function() {
if (userinfo_currently_popped !== undefined) { hide_userinfo_popover();
userinfo_currently_popped.popover('destroy');
userinfo_currently_popped = undefined;
}
}); });
$("#main_div").on("click", ".messagebox", function (e) { $("#main_div").on("click", ".messagebox", function (e) {
@ -481,7 +480,19 @@ $(function () {
$("#main_div").on("click", ".user_info_hover", function (e) { $("#main_div").on("click", ".user_info_hover", function (e) {
var row = $(this).closest(".message_row"); var row = $(this).closest(".message_row");
userinfo_popover(e, this, row.attr('zid')); e.stopPropagation();
var last_popover_elem = current_userinfo_popover_elem;
hide_userinfo_popover();
if (last_popover_elem === undefined
|| last_popover_elem.get()[0] !== this) {
// Only show the popover if either no popover is
// currently up or if the user has clicked on a different
// user_info_hover element than the one that deployed the
// last popover. That is, we want it to be the case that
// a user can dismiss a popover by clicking on the same
// element that caused the popover
show_userinfo_popover(this, row.attr('zid'));
}
}); });
$("#main_div").on("click", ".narrows_by_recipient", function (e) { $("#main_div").on("click", ".narrows_by_recipient", function (e) {