use typeof if checking for undefined var and always clear timeout before setting a new one

This commit is contained in:
Mario Vavti 2017-11-29 12:01:36 +01:00
parent b1f82257e8
commit aa7f6111a6

View File

@ -339,8 +339,8 @@ function closeMenu(theID) {
function markRead(notifType) { function markRead(notifType) {
$.get('ping?f=&markRead='+notifType); $.get('ping?f=&markRead='+notifType);
if(timer) clearTimeout(timer);
$('.' + notifType + '-button').hide(); $('.' + notifType + '-button').hide();
if(timer) clearTimeout(timer);
timer = setTimeout(updateInit,2000); timer = setTimeout(updateInit,2000);
} }
@ -412,6 +412,7 @@ function notificationsUpdate() {
$.jGrowl(this.message, { sticky: false, theme: 'info', life: 10000 }); $.jGrowl(this.message, { sticky: false, theme: 'info', life: 10000 });
}); });
}) })
if(timer) clearTimeout(timer);
timer = setTimeout(updateInit,updateInterval); timer = setTimeout(updateInit,updateInterval);
} }
@ -762,7 +763,7 @@ function liveUpdate(notify_id) {
// else data was valid - reset the recursion counter // else data was valid - reset the recursion counter
liveRecurse = 0; liveRecurse = 0;
if(notify_id !== 'undefined') { if(typeof notify_id !== 'undefined') {
$.post( $.post(
"hq", "hq",
{ {