mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 03:55:55 +01:00
show user names who upvoted a post on mouse over
This commit is contained in:
@@ -15,6 +15,8 @@ define('forum/topic/postTools', ['composer', 'share', 'navigator'], function(com
|
|||||||
share.addShareHandlers(topicName);
|
share.addShareHandlers(topicName);
|
||||||
|
|
||||||
addFavouriteHandler();
|
addFavouriteHandler();
|
||||||
|
|
||||||
|
addVoteHandler();
|
||||||
};
|
};
|
||||||
|
|
||||||
PostTools.toggle = function(pid, isDeleted) {
|
PostTools.toggle = function(pid, isDeleted) {
|
||||||
@@ -37,12 +39,27 @@ define('forum/topic/postTools', ['composer', 'share', 'navigator'], function(com
|
|||||||
|
|
||||||
function addFavouriteHandler() {
|
function addFavouriteHandler() {
|
||||||
$('#post-container').on('mouseenter', '.favourite-tooltip', function() {
|
$('#post-container').on('mouseenter', '.favourite-tooltip', function() {
|
||||||
if (!$(this).data('users-loaded')) {
|
loadDataAndCreateTooltip($(this), 'posts.getFavouritedUsers');
|
||||||
$(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) {
|
function addVoteHandler() {
|
||||||
if (err) {
|
$('#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;
|
return;
|
||||||
}
|
}
|
||||||
if (usernames.length > 6) {
|
if (usernames.length > 6) {
|
||||||
@@ -50,15 +67,12 @@ define('forum/topic/postTools', ['composer', 'share', 'navigator'], function(com
|
|||||||
usernames = usernames.slice(0, 5).join(', ').replace(/,/g, '|');
|
usernames = usernames.slice(0, 5).join(', ').replace(/,/g, '|');
|
||||||
translator.translate('[[topic:users_and_others, ' + usernames + ', ' + otherCount + ']]', function(translated) {
|
translator.translate('[[topic:users_and_others, ' + usernames + ', ' + otherCount + ']]', function(translated) {
|
||||||
translated = translated.replace(/\|/g, ',');
|
translated = translated.replace(/\|/g, ',');
|
||||||
el.attr('title', translated).tooltip('show');
|
el.attr('title', translated).tooltip('destroy').tooltip('show');
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
usernames = usernames.join(', ');
|
usernames = usernames.join(', ');
|
||||||
el.attr('title', usernames).tooltip('show');
|
el.attr('title', usernames).tooltip('destroy').tooltip('show');
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function addPostHandlers(tid, threadState) {
|
function addPostHandlers(tid, threadState) {
|
||||||
|
|||||||
@@ -253,4 +253,12 @@ var async = require('async'),
|
|||||||
db.getSetsMembers(sets, callback);
|
db.getSetsMembers(sets, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Favourites.getUpvotedUidsByPids = function(pids, callback) {
|
||||||
|
var sets = pids.map(function(pid) {
|
||||||
|
return 'pid:' + pid + ':upvote';
|
||||||
|
});
|
||||||
|
db.getSetsMembers(sets, callback);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
}(exports));
|
}(exports));
|
||||||
|
|||||||
@@ -250,20 +250,25 @@ SocketPosts.getPrivileges = function(socket, pid, callback) {
|
|||||||
|
|
||||||
SocketPosts.getFavouritedUsers = function(socket, pid, callback) {
|
SocketPosts.getFavouritedUsers = function(socket, pid, callback) {
|
||||||
favourites.getFavouritedUidsByPids([pid], function(err, data) {
|
favourites.getFavouritedUidsByPids([pid], function(err, data) {
|
||||||
if(err) {
|
if (err || !Array.isArray(data) || !data.length) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!Array.isArray(data) || !data.length) {
|
user.getUsernamesByUids(data[0], callback);
|
||||||
callback(null, []);
|
|
||||||
}
|
|
||||||
|
|
||||||
var pid_uids = data[0];
|
|
||||||
|
|
||||||
user.getUsernamesByUids(pid_uids, callback);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
SocketPosts.getUpvoters = function(socket, pid, callback) {
|
||||||
|
favourites.getUpvotedUidsByPids([pid], function(err, data) {
|
||||||
|
if (err || !Array.isArray(data) || !data.length) {
|
||||||
|
return callback(err, []);
|
||||||
|
}
|
||||||
|
|
||||||
|
user.getUsernamesByUids(data[0], callback);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
SocketPosts.getPidPage = function(socket, pid, callback) {
|
SocketPosts.getPidPage = function(socket, pid, callback) {
|
||||||
posts.getPidPage(pid, socket.uid, callback);
|
posts.getPidPage(pid, socket.uid, callback);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user