mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-06 14:05:46 +01:00
refactoring favourites
This commit is contained in:
@@ -612,7 +612,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
|
||||
});
|
||||
|
||||
ajaxify.register_events([
|
||||
'event:rep_up', 'event:rep_down', 'event:new_post', 'get_users_in_room',
|
||||
'event:rep_up', 'event:rep_down', 'event:favourited', 'event:unfavourited', 'event:new_post', 'get_users_in_room',
|
||||
'event:topic_deleted', 'event:topic_restored', 'event:topic:locked',
|
||||
'event:topic_unlocked', 'event:topic_pinned', 'event:topic_unpinned',
|
||||
'event:topic_moved', 'event:post_edited', 'event:post_deleted', 'event:post_restored',
|
||||
@@ -714,6 +714,14 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
|
||||
adjust_rep(-1, data.pid, data.uid);
|
||||
});
|
||||
|
||||
socket.on('event:favourited', function(data) {
|
||||
adjust_favourites(1, data.pid, data.uid);
|
||||
});
|
||||
|
||||
socket.on('event:unfavourited', function(data) {
|
||||
adjust_favourites(-1, data.pid, data.uid);
|
||||
});
|
||||
|
||||
socket.on('event:new_post', function(data) {
|
||||
if(config.usePagination) {
|
||||
onNewPostPagination(data);
|
||||
@@ -884,6 +892,15 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
|
||||
reputationElements.html(reputation).attr('data-reputation', reputation);
|
||||
}
|
||||
|
||||
function adjust_favourites(value, pid, uid) {
|
||||
var favourites = $('li[data-pid="' + pid + '"] .favouriteCount'),
|
||||
currentFavourites = parseInt(favourites.attr('data-favourites'), 10);
|
||||
|
||||
currentFavourites += value;
|
||||
|
||||
favourites.html(currentFavourites).attr('data-favourites', currentFavourites);
|
||||
}
|
||||
|
||||
function set_locked_state(locked, alert) {
|
||||
var threadReplyBtn = $('.topic-main-buttons .post_reply'),
|
||||
postReplyBtns = document.querySelectorAll('#post-container .post_reply'),
|
||||
|
||||
Reference in New Issue
Block a user