// Store the title, to later append notifications count var page_title = document.title; var unread_on_load = 0; var unread_new = 0; var first_load = false; // getNotifications by fetching json every X 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 = '