v1.18.x
barisusakli 11 years ago
parent d4dc716acd
commit f49c95c16f

@ -105,6 +105,7 @@
"more_users_and_guests": "%1 more user(s) and %2 guest(s)",
"more_users": "%1 more user(s)",
"more_guests": "%1 more guest(s)",
"users_and_others": "%1 and %2 others",
"sort_by": "Sort by",
"oldest_to_newest": "Oldest to Newest",

@ -36,13 +36,26 @@ define('forum/topic/postTools', ['composer', 'share', 'navigator'], function(com
};
function addFavouriteHandler() {
$('#post-container').on('mouseenter', '.favourite-tooltip', function(e) {
$('#post-container').on('mouseenter', '.favourite-tooltip', function() {
if (!$(this).data('users-loaded')) {
$(this).data('users-loaded', "true");
$(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) {
el.attr('title', usernames).tooltip('show');
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');
}
});
}
});

@ -241,37 +241,18 @@ SocketPosts.getPrivileges = function(socket, pid, callback) {
};
SocketPosts.getFavouritedUsers = function(socket, pid, callback) {
favourites.getFavouritedUidsByPids([pid], function(err, data) {
if(err) {
return callback(err);
}
if(!Array.isArray(data) || !data.length) {
callback(null, "");
callback(null, []);
}
var max = 5; //hardcoded
var finalText = "";
var pid_uids = data[0];
var rest_amount = 0;
if (pid_uids.length > max) {
rest_amount = pid_uids.length - max;
pid_uids = pid_uids.slice(0, max);
}
user.getUsernamesByUids(pid_uids, function(err, usernames) {
if(err) {
return callback(err);
}
finalText = usernames.join(', ') + (rest_amount > 0 ?
(" and " + rest_amount + (rest_amount > 1 ? " others" : " other")) : "");
callback(null, finalText);
});
user.getUsernamesByUids(pid_uids, callback);
});
};

Loading…
Cancel
Save