1/** 2 * Copied from GDPR Cookie Consent plugin 3 * Add listener on afterBlitzInject instead of DOMLoad 4 * Needed to make it work with blitz cache 5 */ 6 7document.addEventListener('afterBlitzInject', function () { 8 // Trick to animate the popup when injected 9 const popup = document.getElementById("elc-cookie-consent"); 10 if (popup && !popup.classList.contains('elc-hidden')) { 11 popup.classList.add('elc-hidden'); 12 setTimeout(() => { 13 popup.classList.remove('elc-hidden'); 14 }, 10); 15 } 16 17 /* 18 * addEventListner: For all major browsers, except IE 8 and earlier 19 * attachEvent: For IE 8 and earlier versions 20 */ 21 let detailLink = document.getElementById("elc-detail-link"); 22 if (detailLink !== null) { 23 if (detailLink.addEventListener) { 24 detailLink.addEventListener("click", toggleExpand); 25 } else if (detailLink.attachEvent) { 26 detailLink.attachEvent("onclick", toggleExpand); 27 } 28 } 29 30 let hideDetailLink = document.getElementById("elc-hide-detail-link"); 31 if (hideDetailLink !== null) { 32 if (hideDetailLink.addEventListener) { 33 hideDetailLink.addEventListener("click", toggleExpand); 34 } else if (hideDetailLink.attachEvent) { 35 hideDetailLink.attachEvent("onclick", toggleExpand); 36 } 37 } 38 39 let saveLink = document.getElementById("elc-save-link"); 40 if (saveLink !== null) { 41 if (saveLink.addEventListener) { 42 saveLink.addEventListener("click", submitConsent); 43 } else if (saveLink.attachEvent) { 44 saveLink.attachEvent("onclick", submitConsent); 45 } 46 } 47 48 let acceptLink = document.getElementById("elc-accept-link"); 49 if (acceptLink !== null) { 50 if (acceptLink.addEventListener) { 51 acceptLink.addEventListener("click", submitConsent); 52 } else if (acceptLink.attachEvent) { 53 acceptLink.attachEvent("onclick", submitConsent); 54 } 55 } 56 57 58 let acceptAllLink = document.getElementById("elc-accept-all-link"); 59 if (acceptAllLink !== null) { 60 if (acceptAllLink.addEventListener) { 61 acceptAllLink.addEventListener("click", submitAllConsent); 62 } else if (acceptAllLink.attachEvent) { 63 acceptAllLink.attachEvent("onclick", submitAllConsent); 64 } 65 } 66 67 let tabLink = document.getElementsByClassName("elc-tab-link"); 68 for (let i = 0; i < tabLink.length; i++) { 69 if (tabLink[i].addEventListener) { 70 tabLink[i].addEventListener("click", toggleTab); 71 } else if (tabLink[i].attachEvent) { 72 tabLink[i].attachEvent("onclick", toggleTab); 73 } 74 } 75}); 76 77function submitConsent(event) { 78 79 event.preventDefault(); 80 81 let form = document.querySelector('#elc-cookie-consent-form'); 82 let data = serialize(form); 83 84 document.getElementById("elc-cookie-consent").classList.toggle('elc-hidden'); 85 86 let xhr = new XMLHttpRequest(); 87 xhr.open('POST', form.dataset.url); 88 xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 89 xhr.send(data); 90 91 xhr.onreadystatechange = function () { 92 if (xhr.readyState === 4) { 93 if (xhr.status !== 200) console.log('Error: ' + xhr.status); 94 else if (form.hasAttribute("data-refresh") && form.dataset.refresh === "true" && form.hasAttribute("data-refreshtime")) { 95 refresh(form.dataset.refreshtime) 96 } 97 } 98 } 99} 100 101function submitAllConsent(event) { 102 103 event.preventDefault(); 104 105 let form = document.querySelector('#elc-cookie-consent-form'); 106 107 for (let i = 0; i < form.elements.length; i++) { 108 109 if (form.elements[i].type == 'checkbox') { 110 111 if (form.elements[i].checked == false) { 112 form.elements[i].checked = true; 113 } 114 } 115 } 116 117 let data = serialize(form); 118 document.getElementById("elc-cookie-consent").classList.toggle('elc-hidden'); 119 120 let xhr = new XMLHttpRequest(); 121 xhr.open('POST', form.dataset.url); 122 xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 123 xhr.send(data.concat('&acceptAll=true')); 124 125 xhr.onreadystatechange = function () { 126 if (xhr.readyState === 4) { 127 if (xhr.status !== 200) console.log('Error: ' + xhr.status); 128 else if (form.hasAttribute("data-refresh") && form.dataset.refresh === "true" && form.hasAttribute("data-refreshtime")) { 129 refresh(form.dataset.refreshtime) 130 } 131 } 132 } 133} 134 135function refresh(ms) { 136 setTimeout(function () { 137 location.reload(); 138 }, ms); 139} 140 141function toggleExpand(event) { 142 event.preventDefault(); 143 document.getElementById("elc-cookie-consent").classList.toggle('elc-fullwidth'); 144 document.getElementById("elc-cookie-consent").classList.toggle('elc-small'); 145} 146 147function toggleTab(event) { 148 event.preventDefault(); 149 document.getElementById("elc-cookie-consent").classList.toggle('elc-hidden'); 150 document.getElementById("elc-cookie-consent").classList.add('elc-small'); 151} 152 153/*! 154 * Serialize all form data into a query string 155 * (c) 2018 Chris Ferdinandi, MIT License, https://gomakethings.com 156 * @param {Node} form The form to serialize 157 * @return {String}
157 The serialized form data 158 */ 159var serialize = function (form) { 160 161 // Setup our serialized data 162 var serialized = []; 163 164 // Loop through each field in the form 165 for (var i = 0; i < form.elements.length; i++) { 166 167 var field = form.elements[i]; 168 169 // Don't serialize fields without a name, submits, buttons, file and reset inputs, and disabled fields 170 if (!field.name || field.disabled || field.type === 'file' || field.type === 'reset' || field.type === 'button') continue; 171 172 // If a multi-select, get all selections 173 if (field.type === 'select-multiple') { 174 for (var n = 0; n < field.options.length; n++) { 175 if (!field.options[n].selected) continue; 176 serialized.push(encodeURIComponent(field.name) + "=" + encodeURIComponent(field.options[n].value)); 177 } 178 } 179 180 // Convert field data to a query string 181 else if ((field.type !== 'checkbox' && field.type !== 'radio') || field.checked) { 182 serialized.push(encodeURIComponent(field.name) + "=" + encodeURIComponent(field.value)); 183 } 184 } 185 186 return serialized.join('&'); 187 188};
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.