/*! * @chiiya/haven v0.6.1 * (c) Elisha Witte * Released under the MIT License. */ /*! * @chiiya/haven v0.6.1 * (c) Elisha Witte * Released under the MIT License. */ !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e=e||self).haven={})}(this,(function(e){"use strict";function n(e){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function o(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}function t(e,n){for(var o=0;oe.length)&&(n=e.length);for(var o=0,t=new Array(n);o=e.length?{done:!0}:{done:!1,value:e[t++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,r=!0,c=!1;return{s:function(){o=e[Symbol.iterator]()},n:function(){var e=o.next();return r=e.done,e},e:function(e){c=!0,a=e},f:function(){try{r||null==o.return||o.return()}finally{if(c)throw a}}}}function d(e){return e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)}var v=function(){function e(){o(this,e)}return i(e,null,[{key:"set",value:function(e,n,o){var t=this.resolveOptions(o),i=encodeURIComponent(String(n)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),a=encodeURIComponent(String(e)).replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape),r=this.encodeAttributes(t);document.cookie="".concat(a,"=").concat(i).concat(r)}},{key:"get",value:function(e){var n,o=f(document.cookie?document.cookie.split("; "):[]);try{for(o.s();!(n=o.n()).done;){var t=n.value.split("=");if(e===d(t[0])){var i=t.slice(1).join("=");return'"'===i.charAt(0)&&(i=i.slice(1,-1)),i=d(i)}}}catch(e){o.e(e)}finally{o.f()}}},{key:"getAll",value:function(){var e,n={},o=f(document.cookie?document.cookie.split("; "):[]);try{for(o.s();!(e=o.n()).done;){var t=e.value.split("="),i=d(t[0]),a=t.slice(1).join("=");'"'===a.charAt(0)&&(a=a.slice(1,-1)),a=d(a),n[i]=a}}catch(e){o.e(e)}finally{o.f()}return n}},{key:"remove",value:function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=this.resolveOptions(Object.assign(n,{expires:-1}));if(e instanceof RegExp)return this.removeByRegex(e,o);var t=this.encodeAttributes(o);document.cookie="".concat(e,"=''").concat(t),this.set(e,"",o)}},{key:"removeByRegex",value:function(e,n){var o=this;Object.keys(this.getAll()).map((function(t){if(e.test(t)){var i=o.encodeAttributes(n);document.cookie="".concat(t,"=''").concat(i),o.set(t,"",n)}}))}},{key:"encodeAttributes",value:function(e){for(var n="",o=0,t=Object.keys(e);o1&&void 0!==arguments[1]?arguments[1]:"opt-in",i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};o(this,e),this.prefix=n,this.type=t,this.attributes=i}return i(e,[{key:"enableFunctionalCookie",value:function(){e.setCookie("".concat(this.prefix,"-functional"),"true",this.attributes),p.emit("functional-enabled")}},{key:"hasFunctionalCookie",value:function(){return e.cookieExists("".concat(this.prefix,"-functional"))}},{key:"enableCookies",value:function(n){e.setCookie("".concat(this.prefix,"-").concat(n),"true",this.attributes),p.emit("".concat(n,"-enabled"))}},{key:"disableCookies",value:function(n){e.setCookie("".concat(this.prefix,"-").concat(n),"false",this.attributes),p.emit("".concat(n,"-disabled"))}},{key:"hasAllCookiesSet",value:function(){var n,o=f(g());try{for(o.s();!(n=o.n()).done;){var t=n.value;if(!e.cookieExists("".concat(this.prefix,"-").concat(t)))return!1}}catch(e){o.e(e)}finally{o.f()}return!0}},{key:"hasCookiesEnabled",value:function(n){var o=e.getCookie("".concat(this.prefix,"-").concat(n));return"opt-in"===this.type?"true"===o:void 0===o||"true"===o}},{key:"hasAllNecessaryCookiesEnabled",value:function(){var e,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],o=f(n);try{for(o.s();!(e=o.n()).done;){var t=e.value;if(!this.hasCookiesEnabled(t))return!1}}catch(e){o.e(e)}finally{o.f()}return!0}},{key:"enableAllCookies",value:function(){var e=this;["functional"].concat(s(g())).map((function(n){return e.enableCookies(n)}))}},{key:"disableAllCookies",value:function(){var e=this;g().map((function(n){return e.disableCookies(n)}))}}],[{key:"getCookie",value:function(e){return v.get(e)}},{key:"setCookie",value:function(e,n,o){v.set(e,n,o)}},{key:"removeCookie",value:function(e,n){v.remove(e,n)}},{key:"cookieExists",value:function(e){return void 0!==v.get(e)&&""!==v.get(e)}}]),e}(),C=function(){function e(){o(this,e)}return i(e,null,[{key:"resolve",value:function(e){e.domains&&Array.isArray(e.domains)&&(e.domains=this.normalizeDomains(e.domains)),this.resolveBaseConfiguration(e),h.notification=m(h.notification,e.notification),h.translations=m(h.translations,e.translations)}},{key:"resolveBaseConfiguration",value:function(e){for(var n=0,o=["prefix","cookies","type","services","purposes"];n0?i:this.getDomains(),h.lang=this.detectLanguage(e),void 0!==e.cookieAttributes&&(h.cookieAttributes=Object.assign(h.cookieAttributes,e.cookieAttributes))}},{key:"detectLanguage",value:function(e){var n=(e.lang||document.documentElement.lang||"en").toLowerCase(),o=/^(\w{2})-(\w{2})$/.exec(n);return null===o?n:o[1]}},{key:"getDomains",value:function(){var e=[],n=window.location.hostname,o=n.match(/(?:[A-Za-z0-9-]+\.)*([A-Za-z0-9-]+\.co.uk|\.com.br|\.co.jp|\.com.au)\b/);null!==o&&e.push(o[1]);var t=n.match(/(?:[A-Za-z0-9-]+\.)*([A-Za-z0-9-]+\.(?:[A-za-z]{2}|[A-Za-z]{3,}))\b/);return null!==t&&e.push(t[1]),e.push(n),this.normalizeDomains(e)}},{key:"normalizeDomains",value:function(e){return e.map((function(e){return e.startsWith(".")?e:".".concat(e)}))}}]),e}(),x=["-apple-system","BlinkMacSystemFont",'"Segoe UI"',"Roboto","Oxygen","Ubuntu","Cantarell",'"Fira Sans"','"Droid Sans"','"Helvetica Neue"',"Arial",'"Noto Sans"',"sans-serif",'"Apple Color Emoji"','"Segoe UI Emoji"','"Segoe UI Symbol"','"Noto Color Emoji"'],A=function(){function e(){o(this,e)}return i(e,null,[{key:"create",value:function(){var e,n=document.createElement("style");n.type="text/css",n.appendChild(document.createTextNode((e=h.notification.styles,"\n .hv-notification {\n align-items: center;\n background: ".concat(e.background,";\n box-sizing: border-box;\n color: ").concat(e.textColor,";\n display: flex;\n font-family: ").concat(x.join(", "),";\n font-size: 16px;\n justify-content: space-between;\n left: 0;\n line-height: 1.5;\n opacity: 1;\n overflow: hidden;\n padding: 16px 32px;\n position: fixed;\n right: 0;\n transition: opacity 1s ease;\n width: 100%;\n z-index: 9999;\n }\n\n .hv-notification--hidden {\n opacity: 0;\n }\n\n .hv-notification--top {\n top: 0;\n }\n\n .hv-notification--bottom {\n bottom: 0;\n }\n\n .hv-notification__message {\n margin: 0 16px 0 0;\n }\n\n .hv-notification__message a {\n color: ").concat(e.linkColor,";\n text-decoration: underline;\n }\n\n .hv-notification__message a:hover {\n color: ").concat(e.textColor,";\n }\n\n .hv-notification-button {\n align-items: center;\n border: 0;\n cursor: pointer;\n display: inline-flex;\n font-size: 14px;\n font-weight: 500;\n justify-content: center;\n outline: 0;\n padding: 8px 32px;\n transition: background-color 0.2s ease, color 0.2s ease;\n }\n\n .hv-notification__decline {\n background: transparent;\n color: ").concat(e.textColor,";\n }\n\n .hv-notification__decline:hover {\n text-decoration: underline;\n }\n\n .hv-notification__accept {\n background: ").concat(e.buttonBackgroundColor,";\n color: ").concat(e.buttonTextColor,";\n }\n\n .hv-notification__accept:hover {\n background: ").concat(e.buttonBackgroundColorHover,";\n }\n ")))),document.head.appendChild(n);var o=document.createElement("div");o.innerHTML=function(){var e=h.notification;return'\n \n ")}(),document.body.appendChild(o)}}]),e}(),j=!0,S=!1,_=function(){function e(){o(this,e),this.cookieNotification=null,this.cookiesAccept=null,this.cookiesDecline=null,this.cookieManager=new w(h.prefix,h.type,h.cookieAttributes)}return i(e,[{key:"init",value:function(){var e=this;this.cookieNotification=document.getElementById("cookie-notification"),null===this.cookieNotification&&(A.create(),this.cookieNotification=document.getElementById("cookie-notification")),this.cookiesAccept=document.getElementById("cookie-notification__accept"),this.cookiesDecline=document.getElementById("cookie-notification__decline"),null===this.cookieNotification||this.cookieManager.hasAllCookiesSet()||this.showCookieNotification(),null!==this.cookiesAccept&&this.cookiesAccept.addEventListener("click",(function(n){n.preventDefault(),e.cookieManager.enableAllCookies(),e.hideCookieNotification(),e.togglePreferences(j)})),null!==this.cookiesDecline&&this.cookiesDecline.addEventListener("click",(function(n){n.preventDefault(),e.cookieManager.disableAllCookies(),e.cookieManager.enableFunctionalCookie(),e.hideCookieNotification(),e.togglePreferences(S)}))}},{key:"showCookieNotification",value:function(){null!==this.cookieNotification&&(this.cookieNotification.style.display=this.cookieNotification.dataset.display||"block",this.cookieNotification.classList.remove("hv-notification--hidden"))}},{key:"hideCookieNotification",value:function(){null!==this.cookieNotification&&(this.cookieNotification.style.display="none")}},{key:"togglePreferences",value:function(e){var n,o=f(g());try{for(o.s();!(n=o.n()).done;){var t=n.value,i=document.getElementById("cookie-preferences--".concat(t));i&&(i.checked=e)}}catch(e){o.e(e)}finally{o.f()}}}]),e}(),E=["-apple-system","BlinkMacSystemFont",'"Segoe UI"',"Roboto","Oxygen","Ubuntu","Cantarell",'"Fira Sans"','"Droid Sans"','"Helvetica Neue"',"Arial",'"Noto Sans"',"sans-serif",'"Apple Color Emoji"','"Segoe UI Emoji"','"Segoe UI Symbol"','"Noto Color Emoji"'],I=function(){function e(){o(this,e)}return i(e,null,[{key:"create",value:function(e){var n,o=document.createElement("style");o.type="text/css",o.appendChild(document.createTextNode((n=h.preferences.styles,"\n .hv-preference {\n align-items: center;\n box-sizing: border-box;\n display: flex;\n font-family: ".concat(E.join(", "),";\n font-size: 16px;\n justify-content: space-between;\n line-height: 1.5;\n width: 100%;\n }\n\n .hv-preference__purpose {\n font-size: 20px;\n margin: 0;\n }\n\n .hv-preference__description {\n margin-top: 10px;\n width: 100%;\n }\n\n .hv-toggle {\n display: none;\n }\n\n .hv-toggle:checked + label::before {\n background: ").concat(n.toggleBackground,";\n left: auto;\n right: 20px;\n transform: translateX(16px);\n }\n\n .hv-toggle:disabled + label {\n cursor: not-allowed;\n opacity: .5;\n }\n\n .hv-toggle-label {\n border: 1px solid ").concat(n.toggleBorder,";\n border-radius: 9999px;\n cursor: pointer;\n display: inline-block;\n height: 24px;\n margin: 0;\n position: relative;\n width: 48px;\n }\n\n .hv-toggle-label::before {\n background: ").concat(n.toggleBorder,';\n border-radius: 9999px;\n content: "";\n height: 16px;\n left: 4px;\n position: absolute;\n transition: transform .3s ease, background-color .3s ease;\n top: 3px;\n width: 16px;\n }\n ')))),document.head.appendChild(o);var t,i=document.createElement("div");i.innerHTML=(t=["functional"].concat(s(g())),"\n

".concat(k("preferences.description"),"

\n ").concat(t.map((function(e){return'\n
\n

'.concat(k("purposes.".concat(e,".name")),'

\n \n \n
\n

').concat(k("purposes.".concat(e,".description")),"

\n ")})).join(""),"\n ")),e.appendChild(i)}}]),e}(),N=function(){function e(){o(this,e),this.saveButton=null,this.cookieManager=new w(h.prefix,h.type,h.cookieAttributes)}return i(e,[{key:"init",value:function(){var e=document.getElementById("cookie-preferences");null!==e&&I.create(e),this.attachListeners()}},{key:"attachListeners",value:function(){var e,n=this,o=g(),t={},i=f(o);try{var a=function(){var o=e.value,i=document.getElementById("cookie-preferences--".concat(o));null!==i&&(t[o]=i,i.checked=n.cookieManager.hasCookiesEnabled(o),i.addEventListener("change",(function(){n.cookieManager.enableFunctionalCookie(),i.checked?n.cookieManager.enableCookies(o):n.cookieManager.disableCookies(o)})))};for(i.s();!(e=i.n()).done;)a()}catch(e){i.e(e)}finally{i.f()}var r=document.getElementById("cookie-preferences__save");null!==r&&r.addEventListener("click",(function(){n.cookieManager.enableFunctionalCookie();var e,i=f(o);try{for(i.s();!(e=i.n()).done;){var a=e.value;t[a].checked?n.cookieManager.enableCookies(a):n.cookieManager.disableCookies(a)}}catch(e){i.e(e)}finally{i.f()}var r=document.getElementById("cookie-notification");null!==r&&(r.style.display="none")}))}}]),e}(),O=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};void 0!==e.id?(b("https://connect.facebook.net/en_US/fbevents.js")||B(),window.fbq("init",e.id),window.fbq("track","PageView")):console.error("FACEBOOK_PIXEL: No ID specified. Please specify an ID using `options.id`.")},B=function(){if(!window.fbq){var e=window.fbq=function(){e.callMethod?e.callMethod.apply(e,arguments):e.queue.push(arguments)};window._fbq||(window._fbq=e),e.push=e,e.loaded=!0,e.version="2.0",e.queue=[];var n=document.createElement("script");n.async=!0,n.src="https://connect.facebook.net/en_US/fbevents.js";var o=document.getElementsByTagName("script")[0];o.parentNode.insertBefore(n,o)}},D=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};void 0!==e.id?(b("https://www.google-analytics.com/analytics.js")||z(),void 0!==e.name?M(e):P(e)):console.error("GOOGLE_ANALYTICS: No ID specified. Please specify an ID using `options.id`.")},z=function(){window.ga=window.ga||function(){(window.ga.q=window.ga.q||[]).push(arguments)},window.ga.l=+new Date;var e=document.getElementsByTagName("script")[0],n=document.createElement("script");n.src="https://www.google-analytics.com/analytics.js",e.parentNode.insertBefore(n,e)},M=function(e){window.ga("create",e.id,"auto",e.name),!1!==e.anonymizeIp&&window.ga("".concat(e.name,".set"),"anonymizeIp",!0),window.ga("".concat(e.name,".send"),"pageview")},P=function(e){window.ga("create",e.id,"auto"),!1!==e.anonymizeIp&&window.ga("set","anonymizeIp",!0),window.ga("send","pageview")},F=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};void 0!==e.id?b("https://www.googletagmanager.com/gtm.js?id=".concat(e.id))||L(e):console.error("GOOGLE_TAG_MANAGER: No ID specified. Please specify an ID using `options.id`.")},L=function(e){window.dataLayer=window.dataLayer||[],window.dataLayer.push({event:"gtm.js","gtm.start":(new Date).getTime()});var n=document.getElementsByTagName("script")[0],o=document.createElement("script");o.src="https://www.googletagmanager.com/gtm.js?id=".concat(e.id),n.parentNode.insertBefore(o,n)},T=function(){function e(){o(this,e),this.injected={},this.cookieManager=new w(h.prefix,h.type,h.cookieAttributes)}return i(e,[{key:"injectServices",value:function(){var e,n=f(h.services);try{for(n.s();!(e=n.n()).done;){var o=e.value;this.injectService(o)}}catch(e){n.e(e)}finally{n.f()}}},{key:"injectService",value:function(e){if(this.shouldBeInjected(e)){var n=this.getInjectorFunction(e);void 0!==n&&(n(e.options||{}),p.emit("service-loaded",e.name)),this.injected[e.name]=!0}}},{key:"shouldBeInjected",value:function(e){return!1!==e.inject&&!this.injected[e.name]&&(e.required||this.cookieManager.hasAllNecessaryCookiesEnabled(e.purposes))}},{key:"getInjectorFunction",value:function(e){var n;if(!0===e.inject){var o=e.type||e.name;return void 0===(n=this.getDefaultInjector(o))?void console.error("No default injector found for ".concat(o,". Please specify your own implementation.")):n}if(e.inject)return e.inject}},{key:"getDefaultInjector",value:function(e){switch(e){case"google-analytics":return D;case"google-tag-manager":return F;case"facebook-pixel":return O;default:return}}},{key:"registerService",value:function(e,n,o){var t=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},i=c({name:e,purposes:n,inject:o},t);h.services.push(i),this.injectService(i)}}]),e}(),U=function(){function e(){o(this,e)}return i(e,null,[{key:"removeCookies",value:function(){var e,n=this,o=f(h.services);try{for(o.s();!(e=o.n()).done;){var t=e.value;this.removeCookiesSetByService(t)}}catch(e){o.e(e)}finally{o.f()}h.cookies&&Object.values(h.cookies).map((function(e){return n.removeSimpleCookies(e)})),window.location.reload()}},{key:"removeCookiesForPurpose",value:function(e){var n,o=f(h.services);try{for(o.s();!(n=o.n()).done;){var t=n.value;-1!==t.purposes.indexOf(e)&&this.removeCookiesSetByService(t)}}catch(e){o.e(e)}finally{o.f()}h.cookies&&h.cookies[e]&&this.removeSimpleCookies(h.cookies[e])}},{key:"removeCookiesSetByService",value:function(e){e.cookies&&e.cookies.length&&this.removeSimpleCookies(e.cookies);var n=e.type||e.name;"google-analytics"===n&&this.removeGoogleAnalyticsCookies(e.options),"facebook-pixel"===n&&this.removeFacebookPixelCookies(e.options)}},{key:"removeGoogleAnalyticsCookies",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=["_ga","_gid","_gat","AMP_TOKEN"],o=["_dc_gtm_","_gac_","_gat_gtag_","_gat_"];this.removeSimpleCookies(n),void 0!==e.id&&this.removeCompositeCookies(o,e.id),void 0!==e.name&&this.removeCompositeCookies(o,e.name)}},{key:"removeFacebookPixelCookies",value:function(){this.removeSimpleCookies(["_fbp"])}},{key:"removeSimpleCookies",value:function(e){var n,o=f(e);try{for(o.s();!(n=o.n()).done;){var t,i=n.value,a=f(h.domains);try{for(a.s();!(t=a.n()).done;){var r=t.value;w.removeCookie(i,{domain:r})}}catch(e){a.e(e)}finally{a.f()}w.removeCookie(i)}}catch(e){o.e(e)}finally{o.f()}}},{key:"removeCompositeCookies",value:function(e,n){var o,t=f(e);try{for(t.s();!(o=t.n()).done;){var i,a=o.value,r=f(h.domains);try{for(r.s();!(i=r.n()).done;){var c=i.value;w.removeCookie("".concat(a).concat(n),{domain:c})}}catch(e){r.e(e)}finally{r.f()}w.removeCookie("".concat(a).concat(n))}}catch(e){t.e(e)}finally{t.f()}}}]),e}(),q=function(){function e(n){o(this,e),C.resolve(n),this.cookieNotification=new _,this.cookiePreferences=new N,this.cookieManager=new w(h.prefix,h.type,h.cookieAttributes),this.serviceLoader=new T}return i(e,[{key:"init",value:function(){var e=this;/complete|interactive|loaded/.test(document.readyState)?(this.cookieNotification.init(),this.cookiePreferences.init()):document.addEventListener("DOMContentLoaded",(function(){e.cookieNotification.init(),e.cookiePreferences.init()})),this.registerDefaultListeners(),this.checkInitialState()}},{key:"checkInitialState",value:function(){var e,n=f(g());try{for(n.s();!(e=n.n()).done;){var o=e.value;this.cookieManager.hasCookiesEnabled(o)&&p.emit("".concat(o,"-enabled"))}}catch(e){n.e(e)}finally{n.f()}}},{key:"registerDefaultListeners",value:function(){var e,n=this,o=f(g());try{var t=function(){var o=e.value;p.on("".concat(o,"-enabled"),(function(){n.serviceLoader.injectServices()})),p.on("".concat(o,"-disabled"),(function(){U.removeCookiesForPurpose(o)}))};for(o.s();!(e=o.n()).done;)t()}catch(e){o.e(e)}finally{o.f()}}},{key:"registerService",value:function(e,n,o){var t=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};this.serviceLoader.registerService(e,n,o,t)}},{key:"preferences",get:function(){return this.cookiePreferences}},{key:"notification",get:function(){return this.cookieNotification}}],[{key:"on",value:function(e,n){return p.on(e,n)}},{key:"create",value:function(n){return e.instance&&console.warn("Replacing an existing Haven instance. Are you sure this behaviour is intended?"),e.instance=new e(n),e.instance.init(),e.instance}},{key:"getInstance",value:function(){if(e.instance)return e.instance;console.error("No Haven instance found. Make sure to create a Haven instance before attempting to access it.")}},{key:"removeCookies",value:function(e,n){var o,t=f(e);try{for(t.s();!(o=t.n()).done;){var i=o.value;w.removeCookie(i,n)}}catch(e){t.e(e)}finally{t.f()}}}]),e}();"undefined"!=typeof window&&(window.Haven=q),e.CookieManager=w,e.Haven=q,Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=haven.umd.min.js.map