Skip to content
Snippets Groups Projects
Commit 6af00c10 authored by Robert Phillips's avatar Robert Phillips Committed by Bryan Sharpe
Browse files

Issue #3412588: Replace jquery.once dependencies

parent ba3aa9fd
No related branches found
No related tags found
1 merge request!18Issue #3412588: Replace jquery.once dependencies.
......@@ -2,8 +2,8 @@
Drupal.behaviors.notificationSystemBlock = {
attach: function (context, settings) {
$('.notification-block', context).once('loadNotifications').each(function () {
var $block = $(this);
once('loadNotifications', '.notification-block', context).forEach(function (element) {
var $block = $(element);
// Lazy load data for the notification block.
var $placeholder = $block.find('.notification-block__placeholder');
......@@ -39,29 +39,31 @@
function addEventListeners($context) {
// Mark as Read.
$context.find('.notification-markasread-trigger').once('markAsRead').click(function (e) {
var $button = $(this);
var markAsReadEndpoint = drupalSettings.notificationSystem.markAsReadEndpointUrl;
var providerId = $button.data('notification-provider');
var notificationId = $button.data('notification-id');
markAsReadEndpoint = markAsReadEndpoint.replace('PROVIDER_ID', providerId);
markAsReadEndpoint = markAsReadEndpoint.replace('NOTIFICATION_ID', notificationId);
$.ajax({
url: markAsReadEndpoint,
type: 'GET',
}).done(function (data) {
var $notificationItem = $button.parents('.notification-item');
$notificationItem.addClass('is-read');
updateCounters();
}).fail(function (data) {
if (data.responseJSON.hasOwnProperty('message')) {
console.error('Error while marking notification as read: ' + data.responseJSON.message);
}
else {
console.error('Unknown error while marking notification as read.');
}
once('markAsRead', '.notification-markasread-trigger', $context[0]).forEach(function (element) {
$(element).click(function (e) {
var $button = $(this);
var markAsReadEndpoint = drupalSettings.notificationSystem.markAsReadEndpointUrl;
var providerId = $button.data('notification-provider');
var notificationId = $button.data('notification-id');
markAsReadEndpoint = markAsReadEndpoint.replace('PROVIDER_ID', providerId);
markAsReadEndpoint = markAsReadEndpoint.replace('NOTIFICATION_ID', notificationId);
$.ajax({
url: markAsReadEndpoint,
type: 'GET',
}).done(function (data) {
var $notificationItem = $button.parents('.notification-item');
$notificationItem.addClass('is-read');
updateCounters();
}).fail(function (data) {
if (data.responseJSON.hasOwnProperty('message')) {
console.error('Error while marking notification as read: ' + data.responseJSON.message);
}
else {
console.error('Unknown error while marking notification as read.');
}
});
});
});
}
......
......@@ -8,4 +8,5 @@ notifications_block:
dependencies:
- core/jquery
- core/drupalSettings
- core/once
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment