mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
fix: js error when clicking a notification
that sends you to same page
This commit is contained in:
@@ -6,14 +6,19 @@ define('forum/header/notifications', function () {
|
||||
notifications.prepareDOM = function () {
|
||||
const notifTrigger = $('[component="notifications"] [data-bs-toggle="dropdown"]');
|
||||
|
||||
notifTrigger.on('show.bs.dropdown', (ev) => {
|
||||
requireAndCall('loadNotifications', $(ev.target).parent().find('[component="notifications/list"]'));
|
||||
notifTrigger.on('show.bs.dropdown', async (ev) => {
|
||||
const notifications = await app.require('notifications');
|
||||
const triggerEl = $(ev.target);
|
||||
notifications.loadNotifications(triggerEl, triggerEl.parent().find('[component="notifications/list"]'));
|
||||
});
|
||||
|
||||
notifTrigger.each((index, el) => {
|
||||
const dropdownEl = $(el).parent().find('.dropdown-menu');
|
||||
const triggerEl = $(el);
|
||||
const dropdownEl = triggerEl.parent().find('.dropdown-menu');
|
||||
if (dropdownEl.hasClass('show')) {
|
||||
requireAndCall('loadNotifications', dropdownEl.find('[component="notifications/list"]'));
|
||||
app.require('notifications').then((notifications) => {
|
||||
notifications.loadNotifications(triggerEl, dropdownEl.find('[component="notifications/list"]'));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -24,18 +29,14 @@ define('forum/header/notifications', function () {
|
||||
socket.on('event:notifications.updateCount', onUpdateCount);
|
||||
};
|
||||
|
||||
function onNewNotification(data) {
|
||||
requireAndCall('onNewNotification', data);
|
||||
async function onNewNotification(data) {
|
||||
const notifications = await app.require('notifications');
|
||||
notifications.onNewNotification(data);
|
||||
}
|
||||
|
||||
function onUpdateCount(data) {
|
||||
requireAndCall('updateNotifCount', data);
|
||||
}
|
||||
|
||||
function requireAndCall(method, param) {
|
||||
require(['notifications'], function (notifications) {
|
||||
notifications[method](param);
|
||||
});
|
||||
async function onUpdateCount(data) {
|
||||
const notifications = await app.require('notifications');
|
||||
notifications.updateNotifCount(data);
|
||||
}
|
||||
|
||||
return notifications;
|
||||
|
||||
@@ -28,7 +28,7 @@ define('notifications', [
|
||||
});
|
||||
hooks.on('filter:notifications.load', _addTimeagoString);
|
||||
|
||||
Notifications.loadNotifications = function (notifList, callback) {
|
||||
Notifications.loadNotifications = function (triggerEl, notifList, callback) {
|
||||
callback = callback || function () {};
|
||||
socket.emit('notifications.get', null, function (err, data) {
|
||||
if (err) {
|
||||
@@ -47,7 +47,7 @@ define('notifications', [
|
||||
if (scrollToPostIndexIfOnPage(notifEl)) {
|
||||
ev.stopPropagation();
|
||||
ev.preventDefault();
|
||||
components.get('notifications/list').dropdown('toggle');
|
||||
triggerEl.dropdown('toggle');
|
||||
}
|
||||
|
||||
const unread = notifEl.hasClass('unread');
|
||||
|
||||
Reference in New Issue
Block a user