diff --git a/public/css/style.less b/public/css/style.less index c3b0c611f8..2851ba8d8a 100644 --- a/public/css/style.less +++ b/public/css/style.less @@ -742,4 +742,26 @@ body .navbar .nodebb-inline-block { #chat-message-input { width:95%; +} + +.dropdown-toggle { + i { + font-size: 12px; + + &.active { + color: #558; + text-shadow: 0 0 1em #aaf, 0 0 1em #aaf, 0 0 1em #aaf; + } + } +} + +#notif-list { + li { + font-size: 12px; + width: 200px; + + &.unread { + background: #eceff5; + } + } } \ No newline at end of file diff --git a/public/templates/footer.tpl b/public/templates/footer.tpl index 1638f19016..0e917d98a3 100644 --- a/public/templates/footer.tpl +++ b/public/templates/footer.tpl @@ -88,7 +88,50 @@ }, false); // Notifications dropdown - // var notifTrigger = document.querySelector('.notifications a'); + var notifTrigger = document.querySelector('.notifications a'), + notifList = document.getElementById('notif-list'); + notifTrigger.addEventListener('click', function() { + socket.emit('api:notifications.get'); + }); + notifList.addEventListener('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 = target.getAttribute('data-nid'); + 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)); + } + notifList.appendChild(notifFrag); + }); + socket.on('api:notifications.counts', function(counts) { + var notifIcon = document.querySelector('.notifications a i'); + if ((counts.unread + counts.read) > 0) notifIcon.className = 'icon-circle active'; + else notifIcon.className = 'icon-circle-blank'; + }); }()); diff --git a/public/templates/header.tpl b/public/templates/header.tpl index dccc0f05e6..c8571f2838 100644 --- a/public/templates/header.tpl +++ b/public/templates/header.tpl @@ -33,23 +33,23 @@