diff --git a/public/src/modules/notifications.js b/public/src/modules/notifications.js
index e00f366cbd..b209ac22c3 100644
--- a/public/src/modules/notifications.js
+++ b/public/src/modules/notifications.js
@@ -2,7 +2,6 @@ define(function() {
var Notifications = {};
Notifications.prepareDOM = function() {
- // Notifications dropdown
var notifContainer = $('.notifications'),
notifTrigger = notifContainer.children('a'),
notifList = $('#notif-list'),
@@ -10,42 +9,30 @@ define(function() {
notifTrigger.on('click', function(e) {
e.preventDefault();
- if (notifContainer.className.indexOf('open') === -1) {
+ if (!notifContainer.hasClass('open')) {
+
socket.emit('notifications.get', null, function(err, data) {
- var notifFrag = document.createDocumentFragment(),
- notifEl = document.createElement('li'),
- numRead = data.read.length,
+ var numRead = data.read.length,
numUnread = data.unread.length,
x;
- notifList.innerHTML = '';
+ notifList.html('');
+
if (!err && (data.read.length + data.unread.length) > 0) {
for (x = 0; x < numUnread; x++) {
- notifEl.setAttribute('data-nid', data.unread[x].nid);
- notifEl.className = data.unread[x].readClass;
- notifEl.innerHTML = '' + utils.relativeTime(data.unread[x].datetime, true) + '' + data.unread[x].text + '';
- notifFrag.appendChild(notifEl.cloneNode(true));
+ notifList.append($('
' + utils.relativeTime(data.unread[x].datetime, true) + '' + data.unread[x].text + ''));
}
+
for (x = 0; x < numRead; x++) {
- notifEl.setAttribute('data-nid', data.read[x].nid);
- notifEl.className = '';
- notifEl.innerHTML = '' + utils.relativeTime(data.read[x].datetime, true) + '' + data.read[x].text + '';
- notifFrag.appendChild(notifEl.cloneNode(true));
+ notifList.append($('' + utils.relativeTime(data.read[x].datetime, true) + '' + data.read[x].text + ''));
}
+
} else {
- notifEl.className = 'no-notifs';
- notifEl.innerHTML = 'You have no notifications';
- notifFrag.appendChild(notifEl.cloneNode(true));
+ notifList.append($('You have no notifications'));
}
- // Add dedicated link to /notifications
- notifEl.removeAttribute('data-nid');
- notifEl.className = 'pagelink';
- notifEl.innerHTML = 'See all Notifications';
- notifFrag.appendChild(notifEl.cloneNode(true));
-
- notifList.appendChild(notifFrag);
+ notifList.append($('See all Notifications'));
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) {
- // Update notification icon, if necessary
if (count > 0) {
notifIcon.removeClass('fa-bell-o').addClass('fa-bell');
} else {
@@ -88,7 +55,6 @@ define(function() {
notifIcon.toggleClass('unread-count', count > 0);
notifIcon.attr('data-content', count > 20 ? '20+' : count);
- // Update the favicon + saved local count
Tinycon.setBubble(count);
localStorage.setItem('notifications:count', count);
};
@@ -116,7 +82,6 @@ define(function() {
ajaxify.refresh();
}
- // Update the favicon + local storage
var savedCount = parseInt(localStorage.getItem('notifications:count'), 10) || 0;
updateNotifCount(savedCount + 1);
});