1document.addEventListener("DOMContentLoaded", function() { 2 var cookieConsent = document.querySelector('.ch-cookie-consent'); 3 var cookieConsentForm = document.querySelector('.ch-cookie-consent__form'); 4 var cookieConsentFormBtn = document.querySelectorAll('.ch-cookie-consent__btn'); 5 var cookieConsentCategoryDetails = document.querySelector('.ch-cookie-consent__category-group'); 6 var cookieConsentCategoryDetailsToggle = document.querySelector('.ch-cookie-consent__toggle-details'); 7 8 // If cookie consent is direct child of body, assume it should be placed on top of the site pushing down the rest of the website 9 if (cookieConsent && cookieConsent.parentNode.nodeName === 'BODY') { 10 if (cookieConsent.classList.contains('ch-cookie-consent--top')) { 11 document.body.style.marginTop = cookieConsent.offsetHeight + 'px'; 12 13 cookieConsent.style.position = 'absolute'; 14 cookieConsent.style.top = '0'; 15 cookieConsent.style.left = '0'; 16 } else { 17 document.body.style.marginBottom = cookieConsent.offsetHeight + 'px'; 18 19 cookieConsent.style.position = 'fixed'; 20 cookieConsent.style.bottom = '0'; 21 cookieConsent.style.left = '0'; 22 } 23 } 24 25 if (cookieConsentForm) { 26 // Submit form via ajax 27 for (var i = 0; i < cookieConsentFormBtn.length; i++) { 28 var btn = cookieConsentFormBtn[i]; 29 btn.addEventListener('click', function (event) { 30 event.preventDefault(); 31 32 var formAction = cookieConsentForm.action ? cookieConsentForm.action : location.href; 33 var xhr = new XMLHttpRequest(); 34 35 xhr.onload = function () { 36 if (xhr.status >= 200 && xhr.status < 300) { 37 cookieConsent.style.display = 'none'; 38 var buttonEvent = new CustomEvent('cookie-consent-form-submit-successful', { 39 detail: event.target 40 }); 41 document.dispatchEvent(buttonEvent); 42 } 43 }; 44 xhr.open('POST', formAction); 45 xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 46 xhr.send(serializeForm(cookieConsentForm, event.target)); 47 48 // Clear all styles from body to prevent the white margin at the end of the page 49 document.body.style.marginBottom = null; 50 document.body.style.marginTop = null; 51 }, false); 52 } 53 } 54 55 if (cookieConsentCategoryDetails && cookieConsentCategoryDetailsToggle) { 56 cookieConsentCategoryDetailsToggle.addEventListener('click', function() { 57 var detailsIsHidden = cookieConsentCategoryDetails.style.display !== 'block'; 58 cookieConsentCategoryDetails.style.display = detailsIsHidden ? 'block' : 'none'; 59 cookieConsentCategoryDetailsToggle.querySelector('.ch-cookie-consent__toggle-details-hide').style.display = detailsIsHidden ? 'block' : 'none'; 60 cookieConsentCategoryDetailsToggle.querySelector('.ch-cookie-consent__toggle-details-show').style.display = detailsIsHidden ? 'none' : 'block'; 61 }); 62 } 63}); 64 65function serializeForm(form, clickedButton) { 66 var serialized = []; 67 68 for (var i = 0; i < form.elements.length; i++) { 69 var field = form.elements[i]; 70 71 if ((field.type !== 'checkbox' && field.type !== 'radio' && field.type !== 'button') || field.checked) { 72 serialized.push(encodeURIComponent(field.name) + "=" + encodeURIComponent(field.value)); 73 } 74 } 75 76 serialized.push(encodeURIComponent(clickedButton.getAttribute('name')) + "="); 77 78 return serialized.join('&'); 79} 80 81if ( typeof window.CustomEvent !== "function" ) { 82 function CustomEvent(event, params) { 83 params = params || {bubbles: false, cancelable: false, detail: undefined}; 84 var evt = document.createEvent('CustomEvent'); 85 evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail); 86 return evt; 87 } 88 89 CustomEvent.prototype = window.Event.prototype; 90 91 window.CustomEvent = CustomEvent; 92}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.