Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/bundle/Resources/public/js/scripts/admin.notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,34 @@ import { appendNotification } from './helpers/notification.helper';

(function (global, doc, ibexa) {
const notificationsContainer = doc.querySelector('.ibexa-notifications-container');
const behindModalContainer = doc.querySelector('.ibexa-notifications-container--behind-modal');
const notifications = JSON.parse(notificationsContainer.dataset.notifications);
const moveNotificationsBehindModal = (event) => {
if (event.defaultPrevented) {
return;
}

behindModalContainer.append(...notificationsContainer.children);
};
const restoreNotifications = () => {
if (doc.querySelector('.modal.show') || !behindModalContainer.childElementCount) {
return;
}

notificationsContainer.prepend(...behindModalContainer.children);
};
const syncBehindModalOffset = ([entry]) => {
behindModalContainer.style.setProperty('--ibexa-notifications-height', `${entry.borderBoxSize[0].blockSize}px`);
};
const restoreOnBackdropRemoval = (mutations) => {
const isBackdropRemoved = mutations.some(({ removedNodes }) =>
[...removedNodes].some((node) => node.classList?.contains('modal-backdrop')),
);

if (isBackdropRemoved) {
restoreNotifications();
}
};
const addNotification = ({ detail }) => {
const { onShow, label, message, customIconPath = '' } = detail;
const config = ibexa.adminUiConfig.notifications[label];
Expand Down Expand Up @@ -33,5 +60,13 @@ import { appendNotification } from './helpers/notification.helper';
messages.forEach((message) => addNotification({ detail: { label, message } }));
});

const notificationsResizeObserver = new ResizeObserver(syncBehindModalOffset);
const backdropMutationObserver = new MutationObserver(restoreOnBackdropRemoval);

notificationsResizeObserver.observe(notificationsContainer);
backdropMutationObserver.observe(doc.body, { childList: true });

doc.body.addEventListener('ibexa-notify', addNotification, false);
doc.addEventListener('show.bs.modal', moveNotificationsBehindModal, false);
doc.addEventListener('hidden.bs.modal', restoreNotifications, false);
})(window, window.document, window.ibexa);
5 changes: 5 additions & 0 deletions src/bundle/Resources/public/scss/_notifications.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
.ids-alert {
margin-bottom: calculateRem(16px);
}

&--behind-modal {
z-index: $ibexa-backdrop-zindex - 1;
transform: translateY(calc(-1 * var(--ibexa-notifications-height, 0px)));
}
}

.ibexa-notification-list {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{#
Toast container: `app.flashes` are rendered on load and each notification type gets its own template,
which admin.notifications.js clones with the `message` placeholder replaced.

The second container is stacked below the modal backdrop; admin.notifications.js moves the toasts
that are already on screen into it while a modal is open.
#}
<div
class="ibexa-notifications-container"
Expand All @@ -12,3 +15,4 @@
})|e('html_attr') }}"
{% endfor %}
></div>
<div class="ibexa-notifications-container ibexa-notifications-container--behind-modal"></div>
Loading