diff --git a/public/src/utils.js b/public/src/utils.js
index ee5bd73f64..405a708b18 100644
--- a/public/src/utils.js
+++ b/public/src/utils.js
@@ -40,28 +40,28 @@
});
},
- relativeTime: function(timestamp) {
+ relativeTime: function(timestamp, min) {
var now = +new Date(),
difference = now - Math.floor(parseFloat(timestamp));
difference = Math.floor(difference / 1000);
- if (difference < 60) return difference + ' second' + (difference !== 1 ? 's' : '');
+ if (difference < 60) return difference + (min ? 's' : ' second') + (difference !== 1 && !min ? 's' : '');
difference = Math.floor(difference / 60);
- if (difference < 60) return difference + ' minute' + (difference !== 1 ? 's' : '');
+ if (difference < 60) return difference + (min ? 'm' : ' minute') + (difference !== 1 && !min ? 's' : '');
difference = Math.floor(difference / 60);
- if (difference < 24) return difference + ' hour' + (difference !== 1 ? 's' : '');
+ if (difference < 24) return difference + (min ? 'h' : ' hour') + (difference !== 1 && !min ? 's' : '');
difference = Math.floor(difference / 24);
- if (difference < 30) return difference + ' day' + (difference !== 1 ? 's' : '');
+ if (difference < 30) return difference + (min ? 'd' : ' day') + (difference !== 1 && !min ? 's' : '');
difference = Math.floor(difference / 30);
- if (difference < 12) return difference + ' month' + (difference !== 1 ? 's' : '');
+ if (difference < 12) return difference + (min ? 'mon' : ' month') + (difference !== 1 && !min ? 's' : '');
difference = Math.floor(difference / 12);
- return difference + ' year' + (difference !== 1 ? 's' : '');
+ return difference + (min ? 'y' : ' year') + (difference !== 1 && !min ? 's' : '');
},
//http://dense13.com/blog/2009/05/03/converting-string-to-slug-javascript/
@@ -83,7 +83,7 @@
return str;
},
- // Willingly stolen from: http://phpjs.org/functions/strip_tags/
+ // Blatently stolen from: http://phpjs.org/functions/strip_tags/
'strip_tags': function(input, allowed) {
allowed = (((allowed || "") + "").toLowerCase().match(/<[a-z][a-z0-9]*>/g) || []).join(''); // making sure the allowed arg is a string containing only tags in lowercase ()
var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi,
diff --git a/public/templates/footer.tpl b/public/templates/footer.tpl
index 272be6477e..15b6ce108c 100644
--- a/public/templates/footer.tpl
+++ b/public/templates/footer.tpl
@@ -102,28 +102,34 @@
case 'li': target = e.target; break;
}
if (target) {
- var nid = target.getAttribute('data-nid');
- socket.emit('api:notifications.mark_read', nid);
+ var nid = parseInt(target.getAttribute('data-nid'));
+ if (nid > 0) socket.emit('api:notifications.mark_read', nid);
}
})
socket.on('api:notifications.get', function(data) {
+ console.log(data);
var notifFrag = document.createDocumentFragment(),
notifEl = document.createElement('li'),
numRead = data.read.length,
numUnread = data.unread.length,
x;
notifList.innerHTML = '';
- for(x=0;x11m' + data.unread[x].text + '';
- notifFrag.appendChild(notifEl.cloneNode(true));
- }
- for(x=0;x11m' + data.read[x].text + '';
- notifFrag.appendChild(notifEl.cloneNode(true));
+ if (data.read.length + data.unread.length > 0) {
+ for(x=0;x' + utils.relativeTime(data.unread[x].datetime, true) + '' + data.unread[x].text + '';
+ notifFrag.appendChild(notifEl.cloneNode(true));
+ }
+ for(x=0;x' + utils.relativeTime(data.unread[x].datetime, true) + '' + data.read[x].text + '';
+ notifFrag.appendChild(notifEl.cloneNode(true));
+ }
+ } else {
+ notifEl.innerHTML = 'You have no notifications';
+ notifFrag.appendChild(notifEl);
}
notifList.appendChild(notifFrag);
});
diff --git a/public/templates/header.tpl b/public/templates/header.tpl
index 219f8f6aa4..f6de74602a 100644
--- a/public/templates/header.tpl
+++ b/public/templates/header.tpl
@@ -16,6 +16,7 @@
+