From dbd0a715f2df4ebff9a5cb6e48ae2965b0142a9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Wed, 27 Sep 2023 17:23:55 -0400 Subject: [PATCH] fix: #12044, only load notifications when opening dropdown update code to use bs5 class "show" --- public/src/client/header/notifications.js | 27 +++++++++++------------ 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/public/src/client/header/notifications.js b/public/src/client/header/notifications.js index 024cc5960f..2b37b45cd0 100644 --- a/public/src/client/header/notifications.js +++ b/public/src/client/header/notifications.js @@ -1,25 +1,24 @@ 'use strict'; -define('forum/header/notifications', ['components'], function (components) { +define('forum/header/notifications', function () { const notifications = {}; notifications.prepareDOM = function () { - const notifContainer = components.get('notifications'); - const notifTrigger = notifContainer.children('a'); - const notifList = components.get('notifications/list'); + const notifTrigger = $('[component="notifications"] [data-bs-toggle="dropdown"]'); + if (!notifTrigger.length) { + return; + } - notifTrigger.on('click', function (e) { - e.preventDefault(); - if (notifContainer.hasClass('open')) { - return; - } - - requireAndCall('loadNotifications', notifList); + notifTrigger.on('show.bs.dropdown', (ev) => { + requireAndCall('loadNotifications', $(ev.target).parent().find('[component="notifications/list"]')); }); - if (notifTrigger.parents('.dropdown').hasClass('open')) { - requireAndCall('loadNotifications', notifList); - } + notifTrigger.each((index, el) => { + const dropdownEl = $(el).parent().find('.dropdown-menu'); + if (dropdownEl.hasClass('show')) { + requireAndCall('loadNotifications', dropdownEl.find('[component="notifications/list"]')); + } + }); socket.removeListener('event:new_notification', onNewNotification); socket.on('event:new_notification', onNewNotification);