44 lines
1.6 KiB
JavaScript
44 lines
1.6 KiB
JavaScript
document.addEventListener('DOMContentLoaded', function() {
|
|
// Add fade-in classes to sections
|
|
const sections = document.querySelectorAll('section, .card, .table');
|
|
sections.forEach(el => el.classList.add('fade-in'));
|
|
|
|
// Form validation and feedback
|
|
const forms = document.querySelectorAll('.needs-validation');
|
|
Array.from(forms).forEach(form => {
|
|
form.addEventListener('submit', event => {
|
|
if (!form.checkValidity()) {
|
|
event.preventDefault();
|
|
event.stopPropagation();
|
|
}
|
|
form.classList.add('was-validated');
|
|
}, false);
|
|
});
|
|
|
|
// Simple toast notification
|
|
window.showAlert = function(message, type = 'success') {
|
|
const toastContainer = document.getElementById('toast-container');
|
|
if (!toastContainer) {
|
|
const container = document.createElement('div');
|
|
container.id = 'toast-container';
|
|
container.style.position = 'fixed';
|
|
container.style.bottom = '20px';
|
|
container.style.left = '20px';
|
|
container.style.zIndex = '1050';
|
|
document.body.appendChild(container);
|
|
}
|
|
|
|
const toast = document.createElement('div');
|
|
toast.className = `alert alert-${type} fade show`;
|
|
toast.role = 'alert';
|
|
toast.style.marginBottom = '10px';
|
|
toast.innerHTML = message;
|
|
|
|
document.getElementById('toast-container').appendChild(toast);
|
|
|
|
setTimeout(() => {
|
|
toast.classList.remove('show');
|
|
setTimeout(() => toast.remove(), 500);
|
|
}, 3000);
|
|
};
|
|
}); |