mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46: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 () {
|
notifications.prepareDOM = function () {
|
||||||
const notifTrigger = $('[component="notifications"] [data-bs-toggle="dropdown"]');
|
const notifTrigger = $('[component="notifications"] [data-bs-toggle="dropdown"]');
|
||||||
|
|
||||||
notifTrigger.on('show.bs.dropdown', (ev) => {
|
notifTrigger.on('show.bs.dropdown', async (ev) => {
|
||||||
requireAndCall('loadNotifications', $(ev.target).parent().find('[component="notifications/list"]'));
|
const notifications = await app.require('notifications');
|
||||||
|
const triggerEl = $(ev.target);
|
||||||
|
notifications.loadNotifications(triggerEl, triggerEl.parent().find('[component="notifications/list"]'));
|
||||||
});
|
});
|
||||||
|
|
||||||
notifTrigger.each((index, el) => {
|
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')) {
|
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);
|
socket.on('event:notifications.updateCount', onUpdateCount);
|
||||||
};
|
};
|
||||||
|
|
||||||
function onNewNotification(data) {
|
async function onNewNotification(data) {
|
||||||
requireAndCall('onNewNotification', data);
|
const notifications = await app.require('notifications');
|
||||||
|
notifications.onNewNotification(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onUpdateCount(data) {
|
async function onUpdateCount(data) {
|
||||||
requireAndCall('updateNotifCount', data);
|
const notifications = await app.require('notifications');
|
||||||
}
|
notifications.updateNotifCount(data);
|
||||||
|
|
||||||
function requireAndCall(method, param) {
|
|
||||||
require(['notifications'], function (notifications) {
|
|
||||||
notifications[method](param);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return notifications;
|
return notifications;
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ define('notifications', [
|
|||||||
});
|
});
|
||||||
hooks.on('filter:notifications.load', _addTimeagoString);
|
hooks.on('filter:notifications.load', _addTimeagoString);
|
||||||
|
|
||||||
Notifications.loadNotifications = function (notifList, callback) {
|
Notifications.loadNotifications = function (triggerEl, notifList, callback) {
|
||||||
callback = callback || function () {};
|
callback = callback || function () {};
|
||||||
socket.emit('notifications.get', null, function (err, data) {
|
socket.emit('notifications.get', null, function (err, data) {
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -47,7 +47,7 @@ define('notifications', [
|
|||||||
if (scrollToPostIndexIfOnPage(notifEl)) {
|
if (scrollToPostIndexIfOnPage(notifEl)) {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
components.get('notifications/list').dropdown('toggle');
|
triggerEl.dropdown('toggle');
|
||||||
}
|
}
|
||||||
|
|
||||||
const unread = notifEl.hasClass('unread');
|
const unread = notifEl.hasClass('unread');
|
||||||
|
|||||||
Reference in New Issue
Block a user