update alerts
This commit is contained in:
parent
2b325deb14
commit
a566b2e187
@ -10,7 +10,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
try {
|
try {
|
||||||
await navigator.clipboard.writeText(text);
|
await navigator.clipboard.writeText(text);
|
||||||
const original = button.textContent;
|
const original = button.textContent;
|
||||||
button.textContent = 'Copied';
|
button.textContent = document.documentElement.lang === 'ar' ? 'تم النسخ' : 'Copied';
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
button.textContent = original;
|
button.textContent = original;
|
||||||
}, 1200);
|
}, 1200);
|
||||||
@ -42,25 +42,25 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
searchInput.addEventListener('input', applyFilter);
|
searchInput.addEventListener('input', applyFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert alerts to SweetAlert2 popups
|
// Convert SweetAlert2 popups
|
||||||
(async function() {
|
if (typeof Swal !== 'undefined') {
|
||||||
if (typeof Swal === 'undefined') return;
|
|
||||||
const alerts = document.querySelectorAll('.alert');
|
// 1. Convert Flash Alerts (success, danger, warning)
|
||||||
for (const alertEl of alerts) {
|
const validAlerts = [];
|
||||||
// Don't convert if it contains interactive elements
|
document.querySelectorAll('.alert').forEach(alertEl => {
|
||||||
if (alertEl.querySelector('form, ul, .btn, .alert-heading, a')) continue;
|
// Must be one of the flash message types
|
||||||
|
if (!alertEl.classList.contains('alert-success') &&
|
||||||
// Skip empty states / full page notices
|
!alertEl.classList.contains('alert-danger') &&
|
||||||
const siblings = Array.from(alertEl.parentElement.children).filter(el => el !== alertEl && el.tagName !== 'SCRIPT' && el.tagName !== 'STYLE' && el.tagName !== 'BR');
|
!alertEl.classList.contains('alert-warning')) {
|
||||||
if (siblings.length === 0 && (alertEl.parentElement.classList.contains('container') || alertEl.parentElement.tagName === 'MAIN' || alertEl.parentElement.classList.contains('col-12'))) {
|
return;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip heavily padded elements (likely structural empty states)
|
// Skip if it contains interactive elements
|
||||||
if (alertEl.classList.contains('py-4') || alertEl.classList.contains('py-5') || alertEl.classList.contains('py-3') || alertEl.classList.contains('alert-info')) {
|
if (alertEl.querySelector('form, ul, .btn, .alert-heading, a')) return;
|
||||||
continue; // Also explicitly skipping alert-info because they are usually informational structure blocks
|
|
||||||
}
|
const text = alertEl.innerText.trim();
|
||||||
|
if (!text) return;
|
||||||
|
|
||||||
let type = 'info';
|
let type = 'info';
|
||||||
let titleStr = document.documentElement.lang === 'ar' ? 'ملاحظة' : 'Note';
|
let titleStr = document.documentElement.lang === 'ar' ? 'ملاحظة' : 'Note';
|
||||||
|
|
||||||
@ -75,18 +75,66 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
titleStr = document.documentElement.lang === 'ar' ? 'تنبيه' : 'Warning';
|
titleStr = document.documentElement.lang === 'ar' ? 'تنبيه' : 'Warning';
|
||||||
}
|
}
|
||||||
|
|
||||||
const text = alertEl.innerText.trim();
|
// Hide immediately to prevent flash
|
||||||
if (!text) continue;
|
|
||||||
|
|
||||||
alertEl.style.display = 'none';
|
alertEl.style.display = 'none';
|
||||||
|
|
||||||
|
validAlerts.push({ type, titleStr, text });
|
||||||
|
});
|
||||||
|
|
||||||
await Swal.fire({
|
// Process alerts sequentially so they don't overlap
|
||||||
icon: type,
|
(async function() {
|
||||||
title: titleStr,
|
for (const alertData of validAlerts) {
|
||||||
text: text,
|
await Swal.fire({
|
||||||
confirmButtonText: document.documentElement.lang === 'ar' ? 'حسنًا' : 'OK',
|
icon: alertData.type,
|
||||||
confirmButtonColor: '#0d6efd'
|
title: alertData.titleStr,
|
||||||
|
text: alertData.text,
|
||||||
|
confirmButtonText: document.documentElement.lang === 'ar' ? 'حسنًا' : 'OK',
|
||||||
|
confirmButtonColor: '#0d6efd'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
// 2. Convert standard browser confirm() dialogs (Forms & Links)
|
||||||
|
const interceptConfirms = (selector, eventType, triggerAction) => {
|
||||||
|
document.querySelectorAll(selector).forEach(el => {
|
||||||
|
const jsAttr = el.getAttribute('on' + eventType);
|
||||||
|
if (jsAttr && jsAttr.includes('confirm(')) {
|
||||||
|
// Extract text from inside confirm('...')
|
||||||
|
const match = jsAttr.match(/confirm\(\s*['"](.*?)['"]\s*\)/);
|
||||||
|
const confirmText = match ? match[1] : (document.documentElement.lang === 'ar' ? 'هل أنت متأكد؟' : 'Are you sure?');
|
||||||
|
|
||||||
|
// Remove native confirm
|
||||||
|
el.removeAttribute('on' + eventType);
|
||||||
|
|
||||||
|
el.addEventListener(eventType, function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
Swal.fire({
|
||||||
|
title: document.documentElement.lang === 'ar' ? 'تأكيد' : 'Confirmation',
|
||||||
|
text: confirmText,
|
||||||
|
icon: 'warning',
|
||||||
|
showCancelButton: true,
|
||||||
|
confirmButtonColor: '#dc3545',
|
||||||
|
cancelButtonColor: '#6c757d',
|
||||||
|
confirmButtonText: document.documentElement.lang === 'ar' ? 'نعم، متأكد' : 'Yes, I am sure',
|
||||||
|
cancelButtonText: document.documentElement.lang === 'ar' ? 'إلغاء' : 'Cancel'
|
||||||
|
}).then((result) => {
|
||||||
|
if (result.isConfirmed) {
|
||||||
|
triggerAction(el);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
})();
|
|
||||||
|
// Forms
|
||||||
|
interceptConfirms('form[onsubmit*="confirm"]', 'submit', (form) => {
|
||||||
|
HTMLFormElement.prototype.submit.call(form);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Links (a tags)
|
||||||
|
interceptConfirms('a[onclick*="confirm"]', 'click', (link) => {
|
||||||
|
window.location.href = link.getAttribute('href');
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
@ -2,4 +2,4 @@
|
|||||||
# https://curl.se/docs/http-cookies.html
|
# https://curl.se/docs/http-cookies.html
|
||||||
# This file was generated by libcurl! Edit at your own risk.
|
# This file was generated by libcurl! Edit at your own risk.
|
||||||
|
|
||||||
localhost FALSE / FALSE 0 PHPSESSID tf03tbhu7e9rjeotatir4nlali
|
127.0.0.1 FALSE / FALSE 0 PHPSESSID dc35afddvci5n93ei5dp4uaegu
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user