show user names who upvoted a post on mouse over

v1.18.x
barisusakli 11 years ago
parent 005405b16c
commit dae3ef49be

@ -15,6 +15,8 @@ define('forum/topic/postTools', ['composer', 'share', 'navigator'], function(com
share.addShareHandlers(topicName);
addFavouriteHandler();
addVoteHandler();
};
PostTools.toggle = function(pid, isDeleted) {
@ -37,30 +39,42 @@ define('forum/topic/postTools', ['composer', 'share', 'navigator'], function(com
function addFavouriteHandler() {
$('#post-container').on('mouseenter', '.favourite-tooltip', function() {
if (!$(this).data('users-loaded')) {
$(this).data('users-loaded', 'true');
var pid = $(this).parents('.post-row').attr('data-pid');
var el = $(this).attr('title', "Loading...");
socket.emit('posts.getFavouritedUsers', pid, function(err, usernames) {
if (err) {
return;
}
if (usernames.length > 6) {
var otherCount = usernames.length - 5;
usernames = usernames.slice(0, 5).join(', ').replace(/,/g, '|');
translator.translate('[[topic:users_and_others, ' + usernames + ', ' + otherCount + ']]', function(translated) {
translated = translated.replace(/\|/g, ',');
el.attr('title', translated).tooltip('show');
});
} else {
usernames = usernames.join(', ');
el.attr('title', usernames).tooltip('show');
}
});
loadDataAndCreateTooltip($(this), 'posts.getFavouritedUsers');
});
}
function addVoteHandler() {
$('#post-container').on('mouseenter', '.post-row .votes', function() {
loadDataAndCreateTooltip($(this), 'posts.getUpvoters');
});
}
function loadDataAndCreateTooltip(el, method) {
var pid = el.parents('.post-row').attr('data-pid');
socket.emit(method, pid, function(err, usernames) {
if (!err) {
createTooltip(el, usernames);
}
});
}
function createTooltip(el, usernames) {
if (!usernames.length) {
return;
}
if (usernames.length > 6) {
var otherCount = usernames.length - 5;
usernames = usernames.slice(0, 5).join(', ').replace(/,/g, '|');
translator.translate('[[topic:users_and_others, ' + usernames + ', ' + otherCount + ']]', function(translated) {
translated = translated.replace(/\|/g, ',');
el.attr('title', translated).tooltip('destroy').tooltip('show');
});
} else {
usernames = usernames.join(', ');
el.attr('title', usernames).tooltip('destroy').tooltip('show');
}
}
function addPostHandlers(tid, threadState) {
$('.topic').on('click', '.post_reply', function() {
if (!threadState.locked) {

@ -253,4 +253,12 @@ var async = require('async'),
db.getSetsMembers(sets, callback);
};
Favourites.getUpvotedUidsByPids = function(pids, callback) {
var sets = pids.map(function(pid) {
return 'pid:' + pid + ':upvote';
});
db.getSetsMembers(sets, callback);
};
}(exports));

@ -250,20 +250,25 @@ SocketPosts.getPrivileges = function(socket, pid, callback) {
SocketPosts.getFavouritedUsers = function(socket, pid, callback) {
favourites.getFavouritedUidsByPids([pid], function(err, data) {
if(err) {
if (err || !Array.isArray(data) || !data.length) {
return callback(err);
}
if(!Array.isArray(data) || !data.length) {
callback(null, []);
}
user.getUsernamesByUids(data[0], callback);
});
};
var pid_uids = data[0];
SocketPosts.getUpvoters = function(socket, pid, callback) {
favourites.getUpvotedUidsByPids([pid], function(err, data) {
if (err || !Array.isArray(data) || !data.length) {
return callback(err, []);
}
user.getUsernamesByUids(pid_uids, callback);
user.getUsernamesByUids(data[0], callback);
});
};
SocketPosts.getPidPage = function(socket, pid, callback) {
posts.getPidPage(pid, socket.uid, callback);
};

Loading…
Cancel
Save