mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-07 22:45:46 +01:00
notifications fix
This commit is contained in:
@@ -2,7 +2,6 @@ define(function() {
|
|||||||
var Notifications = {};
|
var Notifications = {};
|
||||||
|
|
||||||
Notifications.prepareDOM = function() {
|
Notifications.prepareDOM = function() {
|
||||||
// Notifications dropdown
|
|
||||||
var notifContainer = $('.notifications'),
|
var notifContainer = $('.notifications'),
|
||||||
notifTrigger = notifContainer.children('a'),
|
notifTrigger = notifContainer.children('a'),
|
||||||
notifList = $('#notif-list'),
|
notifList = $('#notif-list'),
|
||||||
@@ -10,42 +9,30 @@ define(function() {
|
|||||||
|
|
||||||
notifTrigger.on('click', function(e) {
|
notifTrigger.on('click', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (notifContainer.className.indexOf('open') === -1) {
|
if (!notifContainer.hasClass('open')) {
|
||||||
|
|
||||||
socket.emit('notifications.get', null, function(err, data) {
|
socket.emit('notifications.get', null, function(err, data) {
|
||||||
|
|
||||||
var notifFrag = document.createDocumentFragment(),
|
var numRead = data.read.length,
|
||||||
notifEl = document.createElement('li'),
|
|
||||||
numRead = data.read.length,
|
|
||||||
numUnread = data.unread.length,
|
numUnread = data.unread.length,
|
||||||
x;
|
x;
|
||||||
|
|
||||||
notifList.innerHTML = '';
|
notifList.html('');
|
||||||
|
|
||||||
if (!err && (data.read.length + data.unread.length) > 0) {
|
if (!err && (data.read.length + data.unread.length) > 0) {
|
||||||
for (x = 0; x < numUnread; x++) {
|
for (x = 0; x < numUnread; x++) {
|
||||||
notifEl.setAttribute('data-nid', data.unread[x].nid);
|
notifList.append($('<li class="' + data.unread[x].readClass + '"><a href="' + data.unread[x].path + '"><span class="pull-right">' + utils.relativeTime(data.unread[x].datetime, true) + '</span>' + data.unread[x].text + '</a></li>'));
|
||||||
notifEl.className = data.unread[x].readClass;
|
|
||||||
notifEl.innerHTML = '<a href="' + data.unread[x].path + '"><span class="pull-right">' + utils.relativeTime(data.unread[x].datetime, true) + '</span>' + data.unread[x].text + '</a>';
|
|
||||||
notifFrag.appendChild(notifEl.cloneNode(true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (x = 0; x < numRead; x++) {
|
for (x = 0; x < numRead; x++) {
|
||||||
notifEl.setAttribute('data-nid', data.read[x].nid);
|
notifList.append($('<li class="' + data.read[x].readClass + '"><a href="' + data.read[x].path + '"><span class="pull-right">' + utils.relativeTime(data.read[x].datetime, true) + '</span>' + data.read[x].text + '</a></li>'));
|
||||||
notifEl.className = '';
|
|
||||||
notifEl.innerHTML = '<a href="' + data.read[x].path + '"><span class="pull-right">' + utils.relativeTime(data.read[x].datetime, true) + '</span>' + data.read[x].text + '</a>';
|
|
||||||
notifFrag.appendChild(notifEl.cloneNode(true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
notifEl.className = 'no-notifs';
|
notifList.append($('<li class="no-notifs"><a>You have no notifications</a></li>'));
|
||||||
notifEl.innerHTML = '<a>You have no notifications</a>';
|
|
||||||
notifFrag.appendChild(notifEl.cloneNode(true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add dedicated link to /notifications
|
notifList.append($('<li class="pagelink"><a href="' + RELATIVE_PATH + '/notifications">See all Notifications</a></li>'));
|
||||||
notifEl.removeAttribute('data-nid');
|
|
||||||
notifEl.className = 'pagelink';
|
|
||||||
notifEl.innerHTML = '<a href="' + RELATIVE_PATH + '/notifications">See all Notifications</a>';
|
|
||||||
notifFrag.appendChild(notifEl.cloneNode(true));
|
|
||||||
|
|
||||||
notifList.appendChild(notifFrag);
|
|
||||||
|
|
||||||
updateNotifCount(data.unread.length);
|
updateNotifCount(data.unread.length);
|
||||||
|
|
||||||
@@ -58,27 +45,7 @@ define(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
notifList.on('click', function(e) {
|
|
||||||
var target;
|
|
||||||
switch (e.target.nodeName) {
|
|
||||||
case 'SPAN':
|
|
||||||
target = e.target.parentNode.parentNode;
|
|
||||||
break;
|
|
||||||
case 'A':
|
|
||||||
target = e.target.parentNode;
|
|
||||||
break;
|
|
||||||
case 'li':
|
|
||||||
target = e.target;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (target) {
|
|
||||||
var nid = parseInt(target.getAttribute('data-nid'));
|
|
||||||
if (nid > 0) socket.emit('modules.notifications.mark_read', nid);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var updateNotifCount = function(count) {
|
var updateNotifCount = function(count) {
|
||||||
// Update notification icon, if necessary
|
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
notifIcon.removeClass('fa-bell-o').addClass('fa-bell');
|
notifIcon.removeClass('fa-bell-o').addClass('fa-bell');
|
||||||
} else {
|
} else {
|
||||||
@@ -88,7 +55,6 @@ define(function() {
|
|||||||
notifIcon.toggleClass('unread-count', count > 0);
|
notifIcon.toggleClass('unread-count', count > 0);
|
||||||
notifIcon.attr('data-content', count > 20 ? '20+' : count);
|
notifIcon.attr('data-content', count > 20 ? '20+' : count);
|
||||||
|
|
||||||
// Update the favicon + saved local count
|
|
||||||
Tinycon.setBubble(count);
|
Tinycon.setBubble(count);
|
||||||
localStorage.setItem('notifications:count', count);
|
localStorage.setItem('notifications:count', count);
|
||||||
};
|
};
|
||||||
@@ -116,7 +82,6 @@ define(function() {
|
|||||||
ajaxify.refresh();
|
ajaxify.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the favicon + local storage
|
|
||||||
var savedCount = parseInt(localStorage.getItem('notifications:count'), 10) || 0;
|
var savedCount = parseInt(localStorage.getItem('notifications:count'), 10) || 0;
|
||||||
updateNotifCount(savedCount + 1);
|
updateNotifCount(savedCount + 1);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user