var max_events; var bg; $(document).ready(function(){ max_events=localStorage["events"]; if(localStorage["events"]==undefined){ localStorage["events"]="20"; } bg=chrome.extension.getBackgroundPage(); // Display the information if (bg.fetchEvents().length == 0) { showError("Error in fetching data!! Check your internet connection"); } else { showEvents(); } // Adding buttons listeners document.getElementById("m_refresh").addEventListener("click", mrefresh); // Added listener to background messages chrome.runtime.onMessage.addListener(function(message,sender,sendResponse){ switch (message.text) { case "FETCH_EVENTS": setSpinner(); //$('div.b').hide(); break; case "FETCH_EVENTS_SUCCESS": unsetSpinner(); showEvents(); break; case "FETCH_EVENTS_DATA_ERROR": unsetSpinner(); showError("Error in fetching data!! Check your internet connection"); break; case "FETCH_EVENTS_URL_ERROR": unsetSpinner(); showError("Configure ip address,API password, user name and password with correct values"); break; default: console.log("Unrecognized message: ", message.text); break; } }); }); function setSpinner () { $('#refr_img_id').attr("src", "images/spinny.gif"); } function unsetSpinner() { $('#refr_img_id').attr("src", "images/refresh.png"); } function clearError() { $('.error').hide(); $('.error a').text(""); $('.result').css('height', null); } function showError(text){ $('.error a').text(text); $('.error').show(); $('.result').height(420); } function showEvents(){ clearError(); $('#events').empty(); var e_refr = document.getElementById('event_temp'); if(e_refr){ wrapper.removeChild(e_refr); } var allEvents = bg.fetchEvents(); var notVisitedEvents = bg.fetchNotVisited(); var eve=document.createElement('div'); eve.id="event_temp"; eve.setAttribute("class","b"); var i=0; if(allEvents.length>0){ while(i_ 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(); $(this).attr({src: 'images/minus.png'}); } else { $('#' + pid).slideUp(); $(this).attr({src: 'images/plus.png'}); } } function mrefresh(){ localStorage["new_events"]=0; bg.updateBadge(); clearError(); bg.resetInterval(); bg.main(); }