You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nodebb/public/src/client/notifications.js

60 lines
1.6 KiB
JavaScript

10 years ago
'use strict';
/* globals define, socket, app */
9 years ago
define('forum/notifications', ['components', 'notifications', 'forum/infinitescroll'], function(components, notifs, infinitescroll) {
var Notifications = {};
Notifications.init = function() {
var listEl = $('.notifications-list');
9 years ago
listEl.on('click', '[component="notifications/item/link"]', function() {
10 years ago
var nid = $(this).parents('[data-nid]').attr('data-nid');
socket.emit('notifications.markRead', nid, function(err) {
if (err) {
return app.alertError(err);
}
});
10 years ago
});
$('.timeago').timeago();
components.get('notifications/mark_all').on('click', function() {
10 years ago
socket.emit('notifications.markAllRead', function(err) {
10 years ago
if (err) {
return app.alertError(err.message);
}
components.get('notifications/item').removeClass('unread');
10 years ago
notifs.updateNotifCount(0);
10 years ago
});
});
9 years ago
infinitescroll.init(loadMoreNotifications);
10 years ago
};
9 years ago
function loadMoreNotifications(direction) {
if (direction < 0) {
return;
}
var notifList = $('.notifications-list');
infinitescroll.loadMore('notifications.loadMore', {
after: notifList.attr('data-nextstart')
}, function(data, done) {
if (!data) {
return done();
}
notifList.attr('data-nextstart', data.nextStart);
if (!data.notifications || !data.notifications.length) {
return done();
}
app.parseAndTranslate('notifications', 'notifications', {notifications: data.notifications}, function(html) {
9 years ago
notifList.append(html);
html.find('.timeago').timeago();
done();
});
});
}
return Notifications;
});