Release v2.2.0
This commit is contained in:
+25
-11
@@ -1,4 +1,4 @@
|
||||
(function () {
|
||||
(function (root) {
|
||||
function getToastTitle(variant) {
|
||||
var textVariant = String(variant || '').trim().toLowerCase();
|
||||
if (textVariant === 'danger') {
|
||||
@@ -141,12 +141,17 @@
|
||||
|
||||
function getMessageVariant(message, fallbackVariant) {
|
||||
var text = String(message || '').trim();
|
||||
if (/\b(?:unable to|cannot|can't|could not|failed to)\s+delete\b/i.test(text) || /\bdelete\b.*\b(?:before|first)\b/i.test(text) || /\bstill (?:in use|linked|assigned|used)\b/i.test(text)) {
|
||||
return 'danger';
|
||||
}
|
||||
if (/\b(?:already exists|already exist|already taken|duplicate|must be unique|name already exists)\b/i.test(text)) {
|
||||
return 'warning';
|
||||
var rules = [
|
||||
{ variant: 'danger', patterns: [/\b(?:unable to|cannot|can't|could not|failed to)\s+delete\b/i, /\bdelete\b.*\b(?:before|first)\b/i, /\bstill (?:in use|linked|assigned|used)\b/i] },
|
||||
{ variant: 'warning', patterns: [/\b(?:already exists|already exist|already taken|duplicate|must be unique|name already exists)\b/i] }
|
||||
];
|
||||
|
||||
for (var i = 0; i < rules.length; i += 1) {
|
||||
if (rules[i].patterns.some(function (pattern) { return pattern.test(text); })) {
|
||||
return rules[i].variant;
|
||||
}
|
||||
}
|
||||
|
||||
return String(fallbackVariant || 'info').trim().toLowerCase() || 'info';
|
||||
}
|
||||
|
||||
@@ -230,9 +235,18 @@
|
||||
}
|
||||
}
|
||||
|
||||
window.dismissToast = dismissToast;
|
||||
window.showToast = showToast;
|
||||
window.initToast = initToast;
|
||||
root.dismissToast = dismissToast;
|
||||
root.showToast = showToast;
|
||||
root.initToast = initToast;
|
||||
root.getMessageVariant = getMessageVariant;
|
||||
|
||||
initToast();
|
||||
}());
|
||||
if (typeof module !== 'undefined' && module.exports) {
|
||||
module.exports = {
|
||||
getMessageVariant: getMessageVariant
|
||||
};
|
||||
}
|
||||
|
||||
if (root.document) {
|
||||
initToast();
|
||||
}
|
||||
}(typeof window !== 'undefined' ? window : globalThis));
|
||||
Reference in New Issue
Block a user