Skip to content

Node.js based forum software built for the modern web

Move to client side

MrWaffled63ced8a5c12
diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js
index 9c1eaf2e27..11aa8f54e9 100644
--- a/public/src/forum/topic.js
+++ b/public/src/forum/topic.js
@@ -342,7 +342,16 @@ define(['composer'], function(composer) {
}
})();
- $('.favourite-tooltip').tooltip();
+ $('#post-container').on('mouseenter', '.favourite-tooltip', function(e) {
+ 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) {
+ el.attr('title', usernames).tooltip('show');
+ });
+ }
+ });
});
function enableInfiniteLoading() {
diff --git a/public/templates/topic.tpl b/public/templates/topic.tpl
index 8a134876cd..ec72ff958b 100644
--- a/public/templates/topic.tpl
+++ b/public/templates/topic.tpl
@@ -66,7 +66,7 @@
<!-- IF @first -->
<button class="btn btn-sm btn-default follow" type="button" title="Be notified of new replies in this topic"><i class="fa fa-eye"></i></button>
<!-- ENDIF @first -->
- <button title="{posts.favourited_users}" data-favourited="{posts.favourited}" class="favourite favourite-tooltip btn btn-sm btn-default <!-- IF posts.favourited --> btn-warning <!-- ENDIF posts.favourited -->" type="button">
+ <button data-favourited="{posts.favourited}" class="favourite favourite-tooltip btn btn-sm btn-default <!-- IF posts.favourited --> btn-warning <!-- ENDIF posts.favourited -->" type="button">
<span class="favourite-text">[[topic:favourite]]</span>
<span class="post_rep_{posts.pid}">{posts.reputation} </span>
<!-- IF posts.favourited -->
diff --git a/src/socket.io/posts.js b/src/socket.io/posts.js
index 0baed5d0b4..f02fff3117 100644
--- a/src/socket.io/posts.js
+++ b/src/socket.io/posts.js
@@ -3,6 +3,7 @@ var posts = require('../posts'),
topics = require('../topics'),
favourites = require('../favourites'),
postTools = require('../postTools'),
+ user = require('../user'),
index = require('./index'),
SocketPosts = {};
@@ -168,4 +169,28 @@ SocketPosts.getPrivileges = function(socket, pid, callback) {
});
};
+SocketPosts.getFavouritedUsers = function(socket, pid, callback) {
+ favourites.getFavouritedUidsByPids([pid], function(data) {
+ var max = 5; //hardcoded
+ var usernames = "";
+
+ var pid_uids = data[pid];
+ var rest_amount = 0;
+ if (data.hasOwnProperty(pid) && pid_uids.length > 0) {
+ if (pid_uids.length > max) {
+ rest_amount = pid_uids.length - max;
+ pid_uids = pid_uids.slice(0, max);
+ }
+ user.getUsernamesByUids(pid_uids, function(result) {
+ usernames = result.join(', ') + (rest_amount > 0
+ ? " and " + rest_amount + (rest_amount > 1 ? " others" : " other")
+ : "");
+ callback(null, usernames);
+ });
+ } else {
+ callback(null, "");
+ }
+ });
+};
+
module.exports = SocketPosts;
\ No newline at end of file
diff --git a/src/topics.js b/src/topics.js
index 35cf7b0d9a..ba88cef81b 100644
--- a/src/topics.js
+++ b/src/topics.js
@@ -370,33 +370,6 @@ var async = require('async'),
});
}
- function getFavouritedUsers(next) {
- favourites.getFavouritedUidsByPids(pids, function(data) {
- var max = 5; //hardcoded
- var usernames = {};
- async.each(pids, function(pid, next) {
- var pid_uids = data[pid];
- var rest_amount = 0;
- if (data.hasOwnProperty(pid) && pid_uids.length > 0) {
- if (pid_uids.length > max) {
- rest_amount = pid_uids.length - max;
- pid_uids = pid_uids.slice(0, max);
- }
- user.getUsernamesByUids(pid_uids, function(result) {
- usernames[pid] = result.join(', ') + (rest_amount > 0
- ? " and " + rest_amount + (rest_amount > 1 ? " others" : " other")
- : "");
- });
- } else {
- usernames[pid] = [];
- }
- next();
- }, function(err) {
- next(err, usernames);
- });
- });
- }
-
function addUserInfoToPosts(next) {
function iterator(post, callback) {
posts.addUserInfoToPost(post, function() {
@@ -426,19 +399,17 @@ var async = require('async'),
}
}
- async.parallel([getFavouritesData, addUserInfoToPosts, getPrivileges, getFavouritedUsers], function(err, results) {
+ async.parallel([getFavouritesData, addUserInfoToPosts, getPrivileges], function(err, results) {
if(err) {
return callback(err);
}
var fav_data = results[0],
- privileges = results[2],
- fav_users = results[3];
+ privileges = results[2];
for (var i = 0; i < postData.length; ++i) {
var pid = postData[i].pid;
postData[i].favourited = fav_data[pid];
- postData[i].favourited_users = fav_users[pid];
postData[i].display_moderator_tools = (current_user != 0) && privileges[pid].editable;
postData[i].display_move_tools = privileges[pid].move ? '' : 'hidden';
}