/** * Store the number of unread notifications on load. * That way, if the number got higher while the page was * still open, we can announce it by popping a nice dialog. */ var unread_on_load = 0; var first_load = false; var unread_new = 0; /** * Clear notifications by emptying the count number * and removing the has-notification class that styles the toggle */ function clearNotificationIcon(){ $('#notifications-count').html(''); $('#notifications-toggle').removeClass('has-notifications'); } // Get notifications by fetching /notifications/ JSON every 30 seconds function getNotifications(){ $.getJSON( "/notifications/", function( data ) { if (!first_load) { unread_on_load = data['items'].length; first_load = true; } var items = []; unread_new = 0; // Only if there's actual data if (data['items'][0]){ // Loop through each item $.each(data['items'], function(i, no){ // Increase the unread_new counter if (!no['is_read']){ unread_new++ }; // Check if the current item has been read, to style it var is_read = no['is_read'] ? 'is_read' : ''; var read_info = 'data-id="'+ no['_id'] + '" data-read="' + no['is_read'] + '"'; // Notification list item var content = '