-
-
Notifications
You must be signed in to change notification settings - Fork 117
/
cookiebar-latest.min.js
1 lines (1 loc) · 7.08 KB
/
cookiebar-latest.min.js
1
function setupCookieBar(){function e(){if(document.cookie.length>0||null!==window.localStorage&&window.localStorage.length>0){var e=c();void 0===e?w=!0:I=!0}else w=!1;p("always")&&(w=!0),!0===w&&!1===I&&t()}function t(){var e=a(),t="";p("theme")&&(t="-"+p("theme"));var n=C.replace(/[^\/]*$/,""),i=C.indexOf(".min")>-1?".min":"",c=document.createElement("link");c.setAttribute("rel","stylesheet"),c.setAttribute("href",n+"themes/cookiebar"+t+i+".css"),document.head.appendChild(c);var r=new XMLHttpRequest;r.open("GET",n+"lang/"+e+".html",!0),r.onreadystatechange=function(){if(4===r.readyState&&200===r.status){var e=document.createElement("div");e.innerHTML=r.responseText,document.getElementsByTagName("body")[0].appendChild(e),k=document.getElementById("cookie-bar"),b=document.getElementById("cookie-bar-button"),f=document.getElementById("cookie-bar-button-no"),v=document.getElementById("cookie-bar-prompt"),E=document.getElementById("cookie-bar-prompt-button"),h=document.getElementById("cookie-bar-prompt-close"),promptContent=document.getElementById("cookie-bar-prompt-content"),B=document.getElementById("cookie-bar-no-consent"),thirdparty=document.getElementById("cookie-bar-thirdparty"),tracking=document.getElementById("cookie-bar-tracking"),customize=document.getElementById("cookie-bar-customize-block"),buttonCustomize=document.getElementById("cookie-bar-button-customize"),buttonSaveCustomized=document.getElementById("cookiebar-save-customized"),customizeBlock=document.getElementById("cookie-bar-customize-block"),customizeTracking=document.getElementById("cookiebar-tracking-input"),customizeThirdParty=document.getElementById("cookiebar-third-party-input"),scrolling=document.getElementById("cookie-bar-scrolling"),privacyPage=document.getElementById("cookie-bar-privacy-page"),privacyLink=document.getElementById("cookie-bar-privacy-link"),mainBarPrivacyLink=document.getElementById("cookie-bar-main-privacy-link"),p("showNoConsent")||(B.style.display="none",f.style.display="none"),p("showCustomConsent")&&(buttonCustomize.style.display="none"),p("blocking")&&(s(v,500),h.style.display="none"),p("thirdparty")?(thirdparty.style.display="block",customizeThirdParty.style.display="block"):(thirdparty.style.display="none",customizeThirdParty.style.display="none"),p("tracking")?(tracking.style.display="block",customizeTracking.style.display="block"):(tracking.style.display="none",customizeTracking.style.display="none"),p("hideDetailsBtn")&&(E.style.display="none"),p("scrolling")&&(scrolling.style.display="inline-block"),p("top")?(k.style.top=0,u("top")):(k.style.bottom=0,u("bottom")),p("privacyPage")&&(privacyLink.href=o(),privacyPage.style.display="inline-block"),p("showPolicyLink")&&p("privacyPage")&&(mainBarPrivacyLink.href=o(),mainBarPrivacyLink.style.display="inline-block"),p("customize")?(customizeBlock.style.display="block",buttonCustomize.style.display="block"):(customizeBlock.style.display="none",buttonCustomize.style.display="none"),g(),s(k,250),u()}},r.send()}function o(){return decodeURIComponent(p("privacyPage"))}function n(){var e=document.getElementsByTagName("script");for(i=0;i<e.length;i+=1)if(e[i].hasAttribute("src")&&(path=e[i].src,path.indexOf("cookiebar")>-1))return path}function a(){var e=p("forceLang");return!1===e&&(e=navigator.language||navigator.userLanguage),e=e.substr(0,2),CookieLanguages.indexOf(e)<0&&(e="en"),e}function c(){var e=document.cookie.match(/(;)?cookiebar=([^;]*);?/);return null==e?void 0:decodeURI(e[2])}function r(e,t){var o=30;p("remember")&&(o=p("remember"));var n=new Date;n.setDate(n.getDate()+parseInt(o));var i=encodeURI(t)+(null===o?"":"; expires="+n.toUTCString()+";path=/");document.cookie=e+"="+i}function l(){document.cookie.split(";").forEach(function(e){document.cookie=e.replace(/^\ +/,"").replace(/\=.*/,"=;expires="+(new Date).toUTCString()+";path=/")}),null!==localStorage&&localStorage.clear()}function d(e){document.dispatchEvent(new CustomEvent("cookiebarConsent",{cancelable:!0,detail:{consent:e}}))}function s(e,t){var o=e.style;o.opacity=0,o.display="block",function e(){!((o.opacity-=-.1)>.9)&&setTimeout(e,t/10)}()}function m(e,t){var o=e.style;o.opacity=1,function e(){(o.opacity-=.1)<.1?o.display="none":setTimeout(e,t/10)}()}function u(e){setTimeout(function(){var t=document.getElementById("cookie-bar").clientHeight,o=document.getElementsByTagName("body")[0],n=o.currentStyle||window.getComputedStyle(o);switch(e){case"top":o.style.marginTop=parseInt(n.marginTop)+t+"px";break;case"bottom":o.style.marginBottom=parseInt(n.marginBottom)+t+"px"}},300)}function y(){var e=document.getElementById("cookie-bar").clientHeight;if(p("top")){var t=parseInt(document.getElementsByTagName("body")[0].style.marginTop);document.getElementsByTagName("body")[0].style.marginTop=t-e+"px"}else{var o=parseInt(document.getElementsByTagName("body")[0].style.marginBottom);document.getElementsByTagName("body")[0].style.marginBottom=o-e+"px"}}function p(e){var t=C.split(e+"=");return!!t[1]&&t[1].split(/[&?]+/)[0]}function g(){if(b.addEventListener("click",function(){r("cookiebar","CookieAllowed"),y(),m(v,250),m(k,250),d("CookieAllowed"),p("refreshPage")&&window.location.reload()}),f.addEventListener("click",function(){var e=B.textContent.trim(),t=!0;p("noConfirm")||(t=window.confirm(e)),!0===t&&(l(),r("cookiebar","CookieDisallowed"),y(),m(v,250),m(k,250),d("CookieDisallowed"))}),buttonSaveCustomized.addEventListener("click",function(){r("cookiebar","CookieCustomized"),r("cookiebar-tracking",document.getElementById("cookiebar-tracking").checked),r("cookiebar-third-party",document.getElementById("cookiebar-third-party").checked),y(),m(v,250),m(k,250),d("CookieCustomized"),p("refreshPage")&&window.location.reload()}),E.addEventListener("click",function(){s(v,250)}),h.addEventListener("click",function(){m(customize,0),m(v,250)}),buttonCustomize.addEventListener("click",function(){s(customize,0),s(v,250)}),p("scrolling")){var e=document.body.getBoundingClientRect().top,t=!1;window.addEventListener("scroll",function(){!1===t&&(document.body.getBoundingClientRect().top-e>250||document.body.getBoundingClientRect().top-e<-250)&&(r("cookiebar","CookieAllowed"),y(),m(v,250),m(k,250),t=!0,p("refreshPage")&&window.location.reload())})}}var k,b,f,v,E,h,B,C=n(),w=!1,I=!1,T=c();if("CookieDisallowed"==T&&(l(),r("cookiebar","CookieDisallowed")),void 0===T)if(p("noGeoIp"))w=!0,e();else{var L=new XMLHttpRequest;L.open("GET","https://ipapi.co/country",!0),L.onreadystatechange=function(){if(4===L.readyState){if(clearTimeout(z),200===L.status){var t=L.responseText;cookieLawStates.indexOf(t)>-1?w=!0:(I=!0,r("cookiebar","CookieAllowed"),p("refreshPage")&&window.location.reload())}else w=!0;e()}};var z=setTimeout(function(){console.log("cookieBAR - Timeout for ip geolocation"),L.onreadystatechange=function(){},L.abort(),w=!0,e()},1500);L.send()}}var CookieLanguages=["bg","br","ca","cs","da","de","el","en","es","et","fi","fr","hr","hu","it","nl","no","oc","pl","pt","ro","ru","se","sk","sl","tr","uk"],cookieLawStates=["AT","BE","BG","BR","CY","CZ","DE","DK","EE","EL","ES","FI","FR","GB","HR","HU","IE","IT","LT","LU","LV","MT","NL","NO","PL","PT","RO","SE","SI","SK"];document.addEventListener("DOMContentLoaded",function(){setupCookieBar()});