const submitForm = (e) => {
e.preventDefault();
const cookieConsentForm = e.target;
const formData = new FormData(cookieConsentForm);
const action = cookieConsentForm.action = '/';
fetch(cookieConsentForm.action, {
method: 'POST',
body: formData
})
// if the response is not a 200 OK, reject the promise
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
// if the response is ok remove the cookie consent bar
document.querySelector('.cookiebar').classList.add('remove');
})
};
document.addEventListener('DOMContentLoaded', function() {
let cookieConsentBar = document.querySelector('.cookiebar');
let allForms = document.querySelectorAll('.cookieConsentForm');
allForms.forEach(form => {
form.addEventListener('submit', submitForm);
// do ui stuff like set button to pointer events none + loading
cookieConsentButton.addEventListener('click', function() {
cookieConsentButton.classList.add('btn_loading');
});
});
});
console.log〈'i: Cookies: requested'〉;Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.