43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
(() => {
|
|
let dismissTimer = 0;
|
|
let liftFrame = 0;
|
|
|
|
function liftAboveDialogs(element) {
|
|
if (!element?.showPopover) return;
|
|
try {
|
|
if (element.matches(':popover-open')) element.hidePopover();
|
|
element.showPopover();
|
|
} catch {
|
|
// Older browsers fall back to the fixed-position z-index styling.
|
|
}
|
|
}
|
|
|
|
function show(message) {
|
|
const element = document.getElementById('toast');
|
|
if (!element) return;
|
|
|
|
const label = element.querySelector('span');
|
|
if (label) label.textContent = String(message ?? '');
|
|
|
|
window.clearTimeout(dismissTimer);
|
|
window.cancelAnimationFrame(liftFrame);
|
|
liftAboveDialogs(element);
|
|
element.classList.add('show');
|
|
|
|
// Some flows open a dialog immediately after calling toast(). Reinsert the
|
|
// popover on the next frame so it is the top-most item in the top layer.
|
|
liftFrame = window.requestAnimationFrame(() => liftAboveDialogs(element));
|
|
|
|
dismissTimer = window.setTimeout(() => {
|
|
element.classList.remove('show');
|
|
window.setTimeout(() => {
|
|
try {
|
|
if (element.matches(':popover-open')) element.hidePopover();
|
|
} catch {}
|
|
}, 180);
|
|
}, 2600);
|
|
}
|
|
|
|
window.LinkUpToast = Object.freeze({ show });
|
|
})();
|