Use a delegated event handler on the presence list

This code also has the side effect of making it no longer possible to
click to the right of a name to start composing a message to them.

Fixes #931

(imported from commit 80e995ccc8ead18b80a39181c47cc94d6063f0f6)
This commit is contained in:
Zev Benjamin 2013-03-07 14:12:27 -05:00
parent ebb095d0ce
commit 94a3e2c7a4

View File

@ -895,6 +895,12 @@ $(function () {
var message = current_msg_list.get(rows.id(row));
timerender.set_full_datetime(message, time_elem);
});
$('#user_presences').on('click', 'a', function (e) {
var email = $(e.target).attr('data-email');
compose.start('private', {private_message_recipient: email});
e.preventDefault();
});
});
function sort_narrow_list() {
@ -994,14 +1000,10 @@ exports.set_presence_list = function (users, presence_info) {
function add_entry(name, email, type) {
var entry = $('<li>')
.append($('<a>').attr('href', '#')
.append($('<a>').attr({href: '#', 'data-email': email})
.text(name))
.addClass('user_' + type)
.attr('title', name + presence_descriptions[type])
.click(function (e) {
compose.start('private', {private_message_recipient: email});
e.preventDefault();
});
.attr('title', name + presence_descriptions[type]);
$('#user_presences').append(entry);
}