From 5b6f5ebf9d2e97ed951a24a2fe278cd3c257207e Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Wed, 4 Dec 2013 11:40:57 -0500 Subject: [PATCH] added tinycon lib and changed notif icon to be in CSS instead of in template --- public/src/forum/footer.js | 23 ++- public/templates/header.tpl | 2 +- public/vendor/tinycon/tinycon.js | 267 +++++++++++++++++++++++++++++++ src/meta.js | 3 +- 4 files changed, 287 insertions(+), 8 deletions(-) create mode 100644 public/vendor/tinycon/tinycon.js diff --git a/public/src/forum/footer.js b/public/src/forum/footer.js index d83f461b2a..3dd72fca29 100644 --- a/public/src/forum/footer.js +++ b/public/src/forum/footer.js @@ -66,7 +66,7 @@ var notifContainer = document.getElementsByClassName('notifications')[0], notifTrigger = notifContainer.querySelector('a'), notifList = document.getElementById('notif-list'), - notifIcon = document.querySelector('.notifications a i'); + notifIcon = $('.notifications a'); notifTrigger.addEventListener('click', function(e) { e.preventDefault(); if (notifContainer.className.indexOf('open') === -1) { @@ -77,7 +77,6 @@ numUnread = data.unread.length, x; notifList.innerHTML = ''; - console.log(data); if ((data.read.length + data.unread.length) > 0) { for (x = 0; x < numUnread; x++) { notifEl.setAttribute('data-nid', data.unread[x].nid); @@ -106,13 +105,13 @@ notifList.appendChild(notifFrag); if (data.unread.length > 0) { - notifIcon.className = 'fa fa-bell active'; + notifIcon.toggleClass('active', true); } else { - notifIcon.className = 'fa fa-bell-o'; + notifIcon.toggleClass('active', false); } socket.emit('api:notifications.mark_all_read', null, function() { - notifIcon.className = 'fa fa-bell-o'; + notifIcon.toggleClass('active', false); utils.refreshTitle(); }); }); @@ -138,8 +137,20 @@ } }); + socket.emit('api:notifications.getCount', function(count) { + // Update notification icon, if necessary + if (count > 0) { + notifIcon.toggleClass('active', true); + } else { + notifIcon.toggleClass('active', false); + } + + // Update favicon + Tinycon.setBubble(count); + }); + socket.on('event:new_notification', function() { - document.querySelector('.notifications a i').className = 'fa fa-bell active'; + notifIcon.toggleClass('active', true); app.alert({ alert_id: 'new_notif', title: 'New notification', diff --git a/public/templates/header.tpl b/public/templates/header.tpl index 1bc395b0c0..73dd44e334 100644 --- a/public/templates/header.tpl +++ b/public/templates/header.tpl @@ -90,7 +90,7 @@