35834-vm/assets/js/main.js
Flatlogic Bot 7985ade2ba V1
2025-11-18 18:35:13 +00:00

63 lines
2.3 KiB
JavaScript

document.addEventListener('DOMContentLoaded', function () {
const inviteForm = document.getElementById('invite-form');
if (inviteForm) {
inviteForm.addEventListener('submit', function (e) {
e.preventDefault();
const email = document.getElementById('email').value;
const formData = new FormData();
formData.append('email', email);
fetch('request_invite.php', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
showToast(data.message, data.success ? 'success' : 'error');
if (data.success) {
inviteForm.reset();
}
})
.catch(error => {
showToast('An unexpected error occurred.', 'error');
console.error('Error:', error);
});
});
}
function showToast(message, type) {
const toastContainer = document.getElementById('toast-container');
if (!toastContainer) return;
const toast = document.createElement('div');
toast.className = `toast align-items-center text-white bg-${type === 'success' ? 'success' : 'danger'} border-0 show`;
toast.setAttribute('role', 'alert');
toast.setAttribute('aria-live', 'assertive');
toast.setAttribute('aria-atomic', 'true');
const toastBody = document.createElement('div');
toastBody.className = 'd-flex';
toastBody.innerHTML = `<div class="toast-body">${message}</div><button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>`;
toast.appendChild(toastBody);
toastContainer.appendChild(toast);
const bsToast = new bootstrap.Toast(toast);
bsToast.show();
setTimeout(() => {
bsToast.hide();
setTimeout(() => toast.remove(), 500);
}, 5000);
}
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
});
});
});