From 1ccd3d5a91297e798759590aba03c93ab56749c3 Mon Sep 17 00:00:00 2001 From: Rogier Lankhorst Date: Fri, 12 May 2023 15:59:46 +0200 Subject: [PATCH] node= module support extended --- cookiebanner/js/complianz.js | 7 ++++++- cookiebanner/js/complianz.min.js | 2 +- languages/complianz-gdpr.pot | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cookiebanner/js/complianz.js b/cookiebanner/js/complianz.js index 14357966..7941952f 100644 --- a/cookiebanner/js/complianz.js +++ b/cookiebanner/js/complianz.js @@ -319,7 +319,7 @@ function cmplz_run_script( script, category, service, type, sourceObj ) { targetObj.innerHTML = [script, 'cmplzScriptLoaded();'].join('\n'); } - if (script.includes("import") ) { + if ( script.includes("import") ) { targetObj.setAttribute("type", "module"); } @@ -2229,6 +2229,11 @@ function cmplzCopyAttributes(source, target) { return Array.from(source.attributes).forEach(attribute => { //don't copy the type attribute let excludes = ['type', 'data-service', 'data-category', 'async']; + if ( attribute.nodeName === 'data-script-type' && attribute.nodeValue === 'module' ) { + target.setAttribute('type', 'module',); + target.removeAttribute('data-script-type'); + } + if ( !excludes.includes(attribute.nodeName) ) { target.setAttribute( attribute.nodeName, diff --git a/cookiebanner/js/complianz.min.js b/cookiebanner/js/complianz.min.js index a788decf..420c373c 100644 --- a/cookiebanner/js/complianz.min.js +++ b/cookiebanner/js/complianz.min.js @@ -1 +1 @@ -"use strict";function cmplz_create_element(e,t){e=document.createElement(e);return e.innerHtml=t,e}function cmplz_add_event(e,t,c){document.addEventListener(e,e=>{e.target.closest(t)&&c(e)})}function cmplz_is_hidden(e){return null===e.offsetParent}function cmplz_html_decode(e){return(new DOMParser).parseFromString(e,"text/html").documentElement.textContent}function cmplzLoadConsentAreaContent(i,l){document.querySelectorAll(".cmplz-consent-area.cmplz-placeholder").forEach(e=>{let t=e.getAttribute("data-category"),c=e.getAttribute("data-service");var n,o=e.getAttribute("data-post_id"),a=e.getAttribute("data-block_id");i!==t&&l!==c||((n=new XMLHttpRequest).open("GET",complianz.url+"consent-area/"+o+"/"+a,!0),n.setRequestHeader("Content-type","application/json"),n.send(),e.classList.remove("cmplz-placeholder"),n.onload=function(){e.innerHTML=JSON.parse(n.response),e.querySelectorAll("script").forEach(e=>{cmplz_run_script(e.innerHTML,t,c,"inline",e)})})})}document.querySelectorAll(".cmplz-consent-area.cmplz-placeholder").forEach(e=>{e.addEventListener("click",e=>{let t=e.target;(t=t.classList.contains("cmplz-consent-area")?t:e.target.closest(".cmplz-consent-area.cmplz-placeholder"))&&(cmplz_set_service_consent(e=t.getAttribute("data-service"),!0),cmplzLoadConsentAreaContent(!1,e),cmplz_enable_category(null,e),cmplz_set_banner_status("dismissed"))}),document.addEventListener("cmplz_enable_category",function(e){cmplzLoadConsentAreaContent(e.detail.category,e.detail.service)})}),document.addEventListener("cmplz_manage_consent_container_loaded",function(e){var t,c=window.location.href;-1!=c.indexOf("#")&&(t=-1!=c.lastIndexOf("?")?c.lastIndexOf("?"):void 0,c=c.substring(c.indexOf("#")+1,t),t=document.getElementById(c))&&(c=t.getBoundingClientRect().top+window.pageYOffset-200,window.scrollTo({top:c,behavior:"smooth"}))}),complianz.locale=complianz.locale+"&token="+Math.random().toString(36).replace(/[^a-z]+/g,"").substr(0,5),function(){function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var c=document.createEvent("CustomEvent");return c.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),c}"function"!=typeof window.CustomEvent&&(e.prototype=window.Event.prototype,window.CustomEvent=e)}();let cmplz_banner,cmplz_banner_container=document.getElementById("cmplz-cookiebanner-container"),cmplz_manage_consent_button,cmplz_waiting_inline_scripts=[],cmplz_waiting_scripts=[],cmplz_fired_scripts=[],cmplz_placeholder_class_index=0,cmplz_all_scripts_hook_fired=!1,cmplz_consent_stored_once=!1,cmplz_fired_category_events=["functional"],cmplz_fired_service_events=[],cmplz_categories=["functional","preferences","statistics","marketing"];function cmplz_set_category_as_body_class(){var t=document.body.className.split(/\s+/);for(let e=0;e{var t,c,n,o;e.classList.contains("cmplz-processed")||(e.classList.add("cmplz-processed"),t=e.getAttribute("data-service"),c=e.getAttribute("data-category"),(n=e.parentElement).classList.add("cmplz-blocked-content-container"),o=n.getAttribute("data-placeholder_class_index"),"lazy"===e.getAttribute("loading")&&(e.removeAttribute("loading"),e.setAttribute("data-deferlazy",1)),null==o&&(cmplz_placeholder_class_index++,n.classList.add("cmplz-placeholder-"+cmplz_placeholder_class_index),n.classList.add("cmplz-blocked-content-container"),n.setAttribute("data-placeholder_class_index",cmplz_placeholder_class_index),cmplz_insert_placeholder_text(n,c,t)))}),document.querySelectorAll(".cmplz-placeholder-element").forEach(c=>{if(!c.classList.contains("cmplz-processed")){c.classList.add("cmplz-processed");var n=c.getAttribute("data-service"),o=c.getAttribute("data-category");let t;if(null==(t=c.classList.contains("cmplz-iframe")?("lazy"===c.getAttribute("loading")&&(c.removeAttribute("loading"),c.setAttribute("data-deferlazy",1)),c.parentElement):c).getAttribute("data-placeholder_class_index")){cmplz_placeholder_class_index++,t.classList.add("cmplz-placeholder-"+cmplz_placeholder_class_index),t.classList.add("cmplz-blocked-content-container"),t.setAttribute("data-placeholder_class_index",cmplz_placeholder_class_index),cmplz_insert_placeholder_text(t,o,n);let e=c.getAttribute("data-placeholder-image");e&&void 0!==e&&e.length&&(e=e.replace("url(","").replace(")","").replace(/\"/gi,""),cmplz_append_css(".cmplz-placeholder-"+cmplz_placeholder_class_index+" {background-image: url("+e+") !important;}"),cmplz_set_blocked_content_container_aspect_ratio(c,e,cmplz_placeholder_class_index))}}}),cmplz_has_consent("statistics")&&cmplz_enable_category("statistics"),cmplz_has_consent("marketing")&&cmplz_enable_category("marketing")}function cmplz_insert_placeholder_text(e,n,o){if(!e.querySelector(".cmplz-blocked-content-notice")){let t=complianz.placeholdertext;n=n||"marketing";let c;if(void 0!==t){if(1==complianz.clean_cookies){let e=o?o.replace("-"," "):"";e=e.charAt(0).toUpperCase()+e.slice(1),t=t.replace("{service}",e),(c=cmplz_create_element("div",t)).innerHTML=t,c.classList.add("cmplz-blocked-content-notice");var a=c.querySelector("button"),a=(a.setAttribute("data-service",o),a.setAttribute("data-category",n),a.setAttribute("aria-label",complianz.aria_label.replace("{service}",e)),complianz.page_links[complianz.region]),i=c.querySelector(".cmplz-links a");a&&a.hasOwnProperty("cookie-statement")&&(i.setAttribute("href",a["cookie-statement"].url),"{title}"===i.innerText)&&(i.innerText=a["cookie-statement"].title)}else{i=cmplz_create_element("button","");let e="marketing";complianz.categories.hasOwnProperty(n)&&(e=complianz.categories[n]),t=t.replace("{category}",e),i.innerText=t,i.classList.add("cmplz-blocked-content-notice"),i.classList.add("cmplz-accept-category"),i.classList.add("cmplz-accept-"+n),i.setAttribute("data-service",o),i.setAttribute("data-category",n),i.setAttribute("aria-label",complianz.aria_label.replace("{category}",n)),c=i}("VIDEO"!==e.tagName?e:e.parentElement).appendChild(c)}}}function cmplz_set_blocked_content_container_aspect_ratio(e,a,i){if(null!=e){let o=e.parentElement;e=new Image;e.addEventListener("load",function(){let e=this.naturalWidth;var t=this.naturalHeight,c=(0===e&&(e=1),o.clientWidth),t=t*(c/e);let n="";-1===a.indexOf("placeholder.jpg")&&(n="height:"+t+"px;"),cmplz_append_css(".cmplz-placeholder-"+i+" {"+n+"}")}),e.src=a}}var cmplzResizeTimer;function cmplz_has_blocked_scripts(){return 0{var t=e.getAttribute("data-service");e.parentNode.classList.contains("cmplz-blocked-content-notice")&&(e=e.parentNode),cmplz_is_service_denied(t)||e.parentNode.removeChild(e)}),document.querySelectorAll('[data-category="'+o+'"], [data-service="'+a+'"]').forEach(t=>{var e=t.getAttribute("data-service");if(!cmplz_is_service_denied(e)&&"functional"!==t.getAttribute("data-category")&&!t.classList.contains("cmplz-activated")){var e=t.tagName;if("LINK"===e)t.classList.add("cmplz-activated"),cmplz_load_css(t.getAttribute("data-href"),o);else if("IMG"===e){t.classList.add("cmplz-activated");var c=t.getAttribute("data-src-cmplz");t.setAttribute("src",c),t.getAttribute("data-deferlazy")&&t.setAttribute("loading","lazy"),cmplz_remove_placeholder(t)}else if("IFRAME"===e){t.classList.add("cmplz-activated");let e=t.getAttribute("data-src-cmplz");c=t.getAttribute("data-cmplz-target")?t.getAttribute("data-cmplz-target"):"src";"1"===cmplz_get_url_parameter(t.getAttribute(c),"autoplay")&&(e+="&autoplay=1"),t.getAttribute("data-deferlazy")&&t.setAttribute("loading","lazy"),t.addEventListener("load",()=>{cmplz_remove_placeholder(t)}),t.setAttribute(c,e)}else t.classList.contains("cmplz-placeholder-element")&&(t.classList.add("cmplz-activated"),e=t.getAttribute("data-placeholder_class_index"),t.classList.remove("cmplz-blocked-content-container"),t.classList.remove("cmplz-placeholder-"+e))}});var t=document.querySelectorAll('script[data-category="'+o+'"], script[data-service="'+a+'"]');t.forEach(e=>{var t=e.getAttribute("data-waitfor"),c=e.getAttribute("data-cmplz-src");t&&(c?cmplz_waiting_scripts[t]=c:0{var t,c,n=e.getAttribute("type");!e.classList.contains("cmplz-activated")&&n&&"text/javascript"!==n&&(e.classList.add("cmplz-activated"),(n=e.getAttribute("data-cmplz-src"))?(e.removeAttribute("type"),cmplz_is_waiting_script(cmplz_waiting_scripts,n)||(e.getAttribute("data-post_scribe_id")?(t="#"+e.getAttribute("data-post_scribe_id"),(c=document.querySelector(t))&&(c.innerHtml(""),postscribe(t,"