From 8c6daf097b5fcad65bc82e14a45fdc4b1e758f22 Mon Sep 17 00:00:00 2001 From: Matthieu Fesselier Date: Tue, 7 Apr 2020 15:09:54 +0200 Subject: [PATCH] bugfix: wait for notification menu to add listener --- src/scripts/index.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/scripts/index.js b/src/scripts/index.js index acbaa41..9bd9d14 100644 --- a/src/scripts/index.js +++ b/src/scripts/index.js @@ -316,15 +316,21 @@ document.addEventListener("DOMContentLoaded", function(event) { //- Fix badges performances // on load time - document.getElementById('notifications-list').addEventListener('populate', (event) => { - const checkExist = setInterval(function () { // wait for left menus to exist - const subMenus = document.querySelectorAll('.sub-menu > sib-display > div'); - if (subMenus.length >= 2) { - updateBadges(event.target); - clearInterval(checkExist); - } - }, 500); - }, { once: true }); + const checkNotificationMenuExist = setInterval(function () { // wait for notification menu to exist + const notifsMenu = document.getElementById('notifications-list'); + if (notifsMenu) { + clearInterval(checkNotificationMenuExist); + notifsMenu.addEventListener('populate', (event) => { + const checkExist = setInterval(function () { // wait for left menus to exist + const subMenus = document.querySelectorAll('.sub-menu > sib-display > div'); + if (subMenus.length >= 2) { + updateBadges(event.target); + clearInterval(checkExist); + } + }, 500); + }, { once: true }); + } + }, 500); // on refresh notification list window.addEventListener('notificationsRefresh', () => {