/** * Initializes tooltips for elements with the data-bs-toggle="tooltip" attribute. * * @param void * @return void */ // const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]'); // const tooltipList = [...tooltipTriggerList].map((tooltipTriggerEl) => new bootstrap.Tooltip(tooltipTriggerEl)); /** * 👉 Subscribes the user to the newsletter. * * This function retrieves the email input value from the newsletter form, * sends it to the server using AJAX, and handles the response. * If the subscription is successful (success = 1, 2, or 3), it removes certain elements * from the DOM and shows success messages. * If the subscription fails, it shows an error message. * * @return bool Returns false to prevent the form from submitting. */ function subscribeToNewsletter() { const email = document.getElementById('newsletter_email').value; if (!email) { return; } const fd = new FormData(); fd.append('email', email); fetch('/ajax-newsletter-subscribe', { method: "POST", body: fd }) .then(res => res.json()) .then(json => { if (json.success == 1 || json.success == 2 || json.success == 3) { document.querySelectorAll('.remove-after-submit').forEach(el => el.remove()); document.querySelectorAll('.show-after-submit-success').forEach(el => el.classList.remove( 'd-none')); document.querySelectorAll('.show-after-submit-exists').forEach(el => el.classList.add('d-none')); } else { document.querySelectorAll('.show-after-submit-exists').forEach(el => el.classList.remove('d-none')); } }); return false; }