add sweet alerts
This commit is contained in:
parent
77eb65f631
commit
2b325deb14
@ -41,4 +41,52 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
|
|
||||||
searchInput.addEventListener('input', applyFilter);
|
searchInput.addEventListener('input', applyFilter);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
// Convert alerts to SweetAlert2 popups
|
||||||
|
(async function() {
|
||||||
|
if (typeof Swal === 'undefined') return;
|
||||||
|
const alerts = document.querySelectorAll('.alert');
|
||||||
|
for (const alertEl of alerts) {
|
||||||
|
// Don't convert if it contains interactive elements
|
||||||
|
if (alertEl.querySelector('form, ul, .btn, .alert-heading, a')) continue;
|
||||||
|
|
||||||
|
// Skip empty states / full page notices
|
||||||
|
const siblings = Array.from(alertEl.parentElement.children).filter(el => el !== alertEl && el.tagName !== 'SCRIPT' && el.tagName !== 'STYLE' && el.tagName !== 'BR');
|
||||||
|
if (siblings.length === 0 && (alertEl.parentElement.classList.contains('container') || alertEl.parentElement.tagName === 'MAIN' || alertEl.parentElement.classList.contains('col-12'))) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip heavily padded elements (likely structural empty states)
|
||||||
|
if (alertEl.classList.contains('py-4') || alertEl.classList.contains('py-5') || alertEl.classList.contains('py-3') || alertEl.classList.contains('alert-info')) {
|
||||||
|
continue; // Also explicitly skipping alert-info because they are usually informational structure blocks
|
||||||
|
}
|
||||||
|
|
||||||
|
let type = 'info';
|
||||||
|
let titleStr = document.documentElement.lang === 'ar' ? 'ملاحظة' : 'Note';
|
||||||
|
|
||||||
|
if (alertEl.classList.contains('alert-success')) {
|
||||||
|
type = 'success';
|
||||||
|
titleStr = document.documentElement.lang === 'ar' ? 'نجاح' : 'Success';
|
||||||
|
} else if (alertEl.classList.contains('alert-danger')) {
|
||||||
|
type = 'error';
|
||||||
|
titleStr = document.documentElement.lang === 'ar' ? 'خطأ' : 'Error';
|
||||||
|
} else if (alertEl.classList.contains('alert-warning')) {
|
||||||
|
type = 'warning';
|
||||||
|
titleStr = document.documentElement.lang === 'ar' ? 'تنبيه' : 'Warning';
|
||||||
|
}
|
||||||
|
|
||||||
|
const text = alertEl.innerText.trim();
|
||||||
|
if (!text) continue;
|
||||||
|
|
||||||
|
alertEl.style.display = 'none';
|
||||||
|
|
||||||
|
await Swal.fire({
|
||||||
|
icon: type,
|
||||||
|
title: titleStr,
|
||||||
|
text: text,
|
||||||
|
confirmButtonText: document.documentElement.lang === 'ar' ? 'حسنًا' : 'OK',
|
||||||
|
confirmButtonColor: '#0d6efd'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
});
|
||||||
@ -712,6 +712,7 @@ function render_footer(): void
|
|||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
||||||
<script src="<?= h(asset_url('assets/js/main.js')) ?>"></script>
|
<script src="<?= h(asset_url('assets/js/main.js')) ?>"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user