Display not visited events bold on chrome extension

This commit is contained in:
fermin831 2017-11-28 10:36:38 +01:00
parent 5c9822111d
commit 76dfd3cfa0
2 changed files with 49 additions and 15 deletions

View File

@ -1,6 +1,7 @@
var refreshTimer = null;
var isFetching = null;
var storedEvents=new Array();
var storedEvents = new Array();
var notVisited = {};
$(window).load(function() {
initilise();
@ -13,6 +14,13 @@ function fetchEvents() {
return storedEvents;
}
function fetchNotVisited() {
return notVisited;
}
function removeNotVisited(eventId) {
if (notVisited[eventId] === true) delete notVisited[eventId];
}
function main() {
@ -55,31 +63,43 @@ function getEvents(reply){
// If there is no events requested, mark all as visited
if (storedEvents.length == 0) {
for(var k=0;k<fetchedEvents.length;k++){
fetchedEvents[k]['visited'] = true;
}
notVisited = {};
storedEvents = fetchedEvents;
return;
}
// Discriminate the new events
newEvents=fetchNewEvents(fetchedEvents,storedEvents);
var newNotVisited = {};
var notVisitedCount = 0;
// Display the notifications only if popup is not showing
// Check if popup is displayed to make some actions
var views = chrome.extension.getViews({ type: "popup" });
if (views.length == 0) {
for(var k=0;k<newEvents.length;k++){
localStorage["new_events"]++;
for(var k=0;k<newEvents.length;k++){
newNotVisited[newEvents[k]['id']] = true;
if (views.length == 0) {
notVisitedCount++;
displayNotification (newEvents[k])
alertsSound(newEvents[k]);
}
} else {
localStorage["new_events"] = 0;
}
storedEvents = fetchedEvents;
// Make that the old events marked as not visited remains with the
// same status
for(var k=0;k<fetchedEvents.length;k++){
if (notVisited[fetchedEvents[k]['id']] === true) {
newNotVisited[fetchedEvents[k]['id']] = true;
notVisitedCount++;
}
}
notVisited = newNotVisited;
// Update the number
localStorage["new_events"] = (views.length == 0) ? notVisitedCount : 0;
updateBadge();
// Store the requested events
storedEvents = fetchedEvents;
}
function updateBadge() {

View File

@ -69,7 +69,8 @@ function showEvents(){
if(e_refr){
wrapper.removeChild(e_refr);
}
var allEvents=bg.fetchEvents();
var allEvents = bg.fetchEvents();
var notVisitedEvents = bg.fetchNotVisited();
var eve=document.createElement('div');
eve.id="event_temp";
eve.setAttribute("class","b");
@ -83,7 +84,7 @@ function showEvents(){
img.width = '9';
img.height='9';
img.className ='pm';
img.id='i_' + i;
img.id='i_' + i + '_' + allEvents[i]['id'];
eve_title.appendChild(img);
var a = document.createElement('a');
var temp_style;
@ -117,6 +118,10 @@ function showEvents(){
eve_title.setAttribute("style","background:#BABDB6; margin-bottom:-12px;"+temp_style);
break;
}
if (notVisitedEvents[allEvents[i]['id']] === true) {
eve_title.style.fontWeight = 600;
}
eve_title.appendChild(a);
eve.appendChild(eve_title);
@ -152,8 +157,17 @@ function showEvents(){
function showHide() {
var id = $(this).attr('id');
var num = id.split("_")[1];
var pid = "p_" + num;
// Image id has the form i_<position>_<eventId>
var nums = id.split('_');
var pid = "p_" + nums[1];
// Mark as visited if visited
if($(this).parent().css('font-weight') == '600') {
bg.removeNotVisited(nums[2]);
$(this).parent().css('font-weight', '');
}
// Toggle information
if($('#' + pid).css('display') == 'none') {
$('#' + pid).slideDown("fast");
$(this).attr({src: 'images/minus.gif'});