From aa7f6111a69e8b25901b5e2c8f4c4828551316a9 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 29 Nov 2017 12:01:36 +0100 Subject: use typeof if checking for undefined var and always clear timeout before setting a new one --- view/js/main.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'view/js') diff --git a/view/js/main.js b/view/js/main.js index c9bde8452..888934ea8 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -339,8 +339,8 @@ function closeMenu(theID) { function markRead(notifType) { $.get('ping?f=&markRead='+notifType); - if(timer) clearTimeout(timer); $('.' + notifType + '-button').hide(); + if(timer) clearTimeout(timer); timer = setTimeout(updateInit,2000); } @@ -412,7 +412,8 @@ function notificationsUpdate() { $.jGrowl(this.message, { sticky: false, theme: 'info', life: 10000 }); }); }) - timer = setTimeout(updateInit, updateInterval); + if(timer) clearTimeout(timer); + timer = setTimeout(updateInit,updateInterval); } function contextualHelp() { @@ -762,7 +763,7 @@ function liveUpdate(notify_id) { // else data was valid - reset the recursion counter liveRecurse = 0; - if(notify_id !== 'undefined') { + if(typeof notify_id !== 'undefined') { $.post( "hq", { -- cgit v1.2.3