Release v2.5.6
This commit is contained in:
@@ -1,4 +1,63 @@
|
||||
(function (root) {
|
||||
var pendingToastStorageKey = 'pulse:pending-toast';
|
||||
|
||||
function readPendingToast() {
|
||||
try {
|
||||
if (!root.sessionStorage) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var rawValue = root.sessionStorage.getItem(pendingToastStorageKey);
|
||||
if (!rawValue) {
|
||||
return null;
|
||||
}
|
||||
|
||||
root.sessionStorage.removeItem(pendingToastStorageKey);
|
||||
var payload = JSON.parse(rawValue);
|
||||
if (!payload || !payload.message) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
message: String(payload.message || '').trim(),
|
||||
variant: String(payload.variant || 'info').trim().toLowerCase() || 'info'
|
||||
};
|
||||
} catch (_error) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function writePendingToast(message, variant) {
|
||||
try {
|
||||
if (!root.sessionStorage) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var text = String(message || '').trim();
|
||||
if (!text) {
|
||||
return false;
|
||||
}
|
||||
|
||||
root.sessionStorage.setItem(pendingToastStorageKey, JSON.stringify({
|
||||
message: text,
|
||||
variant: String(variant || 'info').trim().toLowerCase() || 'info'
|
||||
}));
|
||||
return true;
|
||||
} catch (_error) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function clearPendingToast() {
|
||||
try {
|
||||
if (root.sessionStorage) {
|
||||
root.sessionStorage.removeItem(pendingToastStorageKey);
|
||||
}
|
||||
} catch (_error) {
|
||||
// ignore storage cleanup failures
|
||||
}
|
||||
}
|
||||
|
||||
function getToastTitle(variant, message) {
|
||||
var text = String(message || '').trim();
|
||||
if (/\b(?:deleted|removed)\.?$/i.test(text)) {
|
||||
@@ -219,9 +278,15 @@
|
||||
function initToast() {
|
||||
var toast = document.getElementById('app-toast');
|
||||
if (!toast) {
|
||||
var pendingToast = readPendingToast();
|
||||
if (pendingToast) {
|
||||
showToast(pendingToast.message, pendingToast.variant);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
clearPendingToast();
|
||||
|
||||
try {
|
||||
var url = new URL(window.location.href);
|
||||
if (url.searchParams.has('message')) {
|
||||
@@ -250,6 +315,7 @@
|
||||
root.showToast = showToast;
|
||||
root.initToast = initToast;
|
||||
root.getMessageVariant = getMessageVariant;
|
||||
root.queueToastAfterRefresh = writePendingToast;
|
||||
|
||||
if (typeof module !== 'undefined' && module.exports) {
|
||||
module.exports = {
|
||||
|
||||
Reference in New Issue
Block a user