From 5328ad80918b9bd0247cf8b4cbb091c6ab958bdf Mon Sep 17 00:00:00 2001 From: Anna Lonka Date: Fri, 10 Jan 2025 09:49:43 +0200 Subject: [PATCH 1/2] UHF-10467: Added check if survey exists --- dist/js/closable-surveys.min.js | 2 +- src/js/closable-surveys.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/js/closable-surveys.min.js b/dist/js/closable-surveys.min.js index ea694e144..6e793279b 100644 --- a/dist/js/closable-surveys.min.js +++ b/dist/js/closable-surveys.min.js @@ -1 +1 @@ -!function(){"use strict";class t{constructor(t){this.data={},this.storageKey=t,this.loadData()}loadData(){let e=null;try{e=localStorage.getItem(this.storageKey)}catch(e){t.handleError(e)}this.data=e?JSON.parse(e):{}}saveData(){try{localStorage.setItem(this.storageKey,JSON.stringify(this.data))}catch(e){t.handleError(e)}}setValue(t,e){this.data[t]=e,this.saveData()}getValue(t){return this.data[t]||null}addValue(t,e){this.data[t]||(this.data[t]=[]),"string"!=typeof e||this.data[t].includes(e)||(this.data[t].push(e),this.saveData())}getValues(t){return this.data[t]||null}removeValue(t,e){if(this.data[t]){const a=this.data[t].indexOf(e);a>-1&&(this.data[t].splice(a,1),this.saveData())}}static handleError(t){if(!(t instanceof ReferenceError))throw t}}!function(Drupal){Drupal.behaviors.closable_surveys={attach:function(){const e=document.getElementById("block-surveys"),a=document.getElementById("skip-to-main");e&&(a?a.parentNode.insertBefore(e,a.nextSibling):document.body.insertBefore(e,document.body.firstChild));const n=document.getElementById("helfi-survey__container");if(!n)return;const i=document.documentElement,o=document.getElementById("helfi-survey__close-button"),s="hidden-helfi-surveys",r=new t("helfi-settings");let d=null,c=null;try{d=JSON.parse(window.localStorage.getItem("helfi-settings"))}catch(t){console.error("Error parsing local storage data:",t)}function l(t){i.classList.toggle("noscroll",t)}function u(t){if(t){const t=window.innerWidth-document.documentElement.clientWidth+"px";document.body.style.paddingRight=t}else document.body.style.removeProperty("padding-right")}function h(){const t=document.querySelector(".hds-cc__target"),e=t?.shadowRoot,a=e?.querySelector(".hds-cc__all-cookies-button");t&&a&&a.focus()}function f(){const t=document.querySelector(".dialog-off-canvas-main-canvas"),e=document.querySelector(".hds-cc__target");t&&!t.hasAttribute("aria-hidden")?t.setAttribute("aria-hidden","true"):t&&t.removeAttribute("aria-hidden"),e&&!e.hasAttribute("aria-hidden")?e.setAttribute("aria-hidden","true"):e&&e.removeAttribute("aria-hidden")}function y(){!function(){const{uuid:t}=n.dataset;t&&r.addValue(s,t)}(),c.deactivate(),n.remove(),l(!1),u(!1),h(),f()}o&&o.addEventListener("click",y),document.body.addEventListener("keydown",(function(t){"Escape"===t.key&&y()})),setTimeout((function(){const{uuid:t}=n.dataset;!t||!(d?.[s]||[]).includes(t)?(n.style.display="flex",u(!0),l(!0),c=window.focusTrap.createFocusTrap("#helfi-survey",{initialFocus:()=>"#helfi-survey__title"}),c.activate(),f()):(n.remove(),f(),h())}),2e3)}}}(Drupal)}(); \ No newline at end of file +!function(){"use strict";class t{constructor(t){this.data={},this.storageKey=t,this.loadData()}loadData(){let e=null;try{e=localStorage.getItem(this.storageKey)}catch(e){t.handleError(e)}this.data=e?JSON.parse(e):{}}saveData(){try{localStorage.setItem(this.storageKey,JSON.stringify(this.data))}catch(e){t.handleError(e)}}setValue(t,e){this.data[t]=e,this.saveData()}getValue(t){return this.data[t]||null}addValue(t,e){this.data[t]||(this.data[t]=[]),"string"!=typeof e||this.data[t].includes(e)||(this.data[t].push(e),this.saveData())}getValues(t){return this.data[t]||null}removeValue(t,e){if(this.data[t]){const a=this.data[t].indexOf(e);a>-1&&(this.data[t].splice(a,1),this.saveData())}}static handleError(t){if(!(t instanceof ReferenceError))throw t}}!function(Drupal){Drupal.behaviors.closable_surveys={attach:function(){const e=document.getElementById("block-surveys"),a=document.getElementById("skip-to-main");e&&(a?a.parentNode.insertBefore(e,a.nextSibling):document.body.insertBefore(e,document.body.firstChild));const n=document.getElementById("helfi-survey__container");if(!n)return;const i=document.documentElement,o=document.getElementById("helfi-survey__close-button"),s="hidden-helfi-surveys",r=new t("helfi-settings");let d=null,c=null;try{d=JSON.parse(window.localStorage.getItem("helfi-settings"))}catch(t){console.error("Error parsing local storage data:",t)}function l(t){i.classList.toggle("noscroll",t)}function u(t){if(t){const t=window.innerWidth-document.documentElement.clientWidth+"px";document.body.style.paddingRight=t}else document.body.style.removeProperty("padding-right")}function h(){const t=document.querySelector(".hds-cc__target"),e=t?.shadowRoot,a=e?.querySelector(".hds-cc__all-cookies-button");t&&a&&a.focus()}function f(){const t=document.querySelector(".dialog-off-canvas-main-canvas"),e=document.querySelector(".hds-cc__target");t&&!t.hasAttribute("aria-hidden")&&n?t.setAttribute("aria-hidden","true"):t&&t.removeAttribute("aria-hidden"),e&&!e.hasAttribute("aria-hidden")&&n?e.setAttribute("aria-hidden","true"):e&&e.removeAttribute("aria-hidden")}function y(){!function(){const{uuid:t}=n.dataset;t&&r.addValue(s,t)}(),c.deactivate(),n.remove(),l(!1),u(!1),h(),f()}o&&o.addEventListener("click",y),document.body.addEventListener("keydown",(function(t){"Escape"===t.key&&y()})),setTimeout((function(){const{uuid:t}=n.dataset;!t||!(d?.[s]||[]).includes(t)?(n.style.display="flex",u(!0),l(!0),c=window.focusTrap.createFocusTrap("#helfi-survey",{initialFocus:()=>"#helfi-survey__title"}),c.activate(),f()):(n.remove(),f(),h())}),2e3)}}}(Drupal)}(); \ No newline at end of file diff --git a/src/js/closable-surveys.js b/src/js/closable-surveys.js index 02abbddcc..a8a607258 100644 --- a/src/js/closable-surveys.js +++ b/src/js/closable-surveys.js @@ -75,14 +75,14 @@ import LocalStorageManager from './localStorageManager'; const mainContent = document.querySelector('.dialog-off-canvas-main-canvas'); const cookieBanner = document.querySelector('.hds-cc__target'); - if (mainContent && !mainContent.hasAttribute('aria-hidden')) { + if (mainContent && !mainContent.hasAttribute('aria-hidden') && survey) { mainContent.setAttribute('aria-hidden', 'true'); } else { // eslint-disable-next-line no-unused-expressions mainContent && mainContent.removeAttribute('aria-hidden'); } - if (cookieBanner && !cookieBanner.hasAttribute('aria-hidden')) { + if (cookieBanner && !cookieBanner.hasAttribute('aria-hidden') && survey) { cookieBanner.setAttribute('aria-hidden', 'true'); } else { // eslint-disable-next-line no-unused-expressions From d1c839210d3bb232b0845eb10dc967016cb474ba Mon Sep 17 00:00:00 2001 From: Anna Lonka Date: Fri, 10 Jan 2025 09:58:48 +0200 Subject: [PATCH 2/2] UHF-10467: Fixed survey element --- dist/js/closable-surveys.min.js | 2 +- src/js/closable-surveys.js | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/dist/js/closable-surveys.min.js b/dist/js/closable-surveys.min.js index 6e793279b..7f1db97f4 100644 --- a/dist/js/closable-surveys.min.js +++ b/dist/js/closable-surveys.min.js @@ -1 +1 @@ -!function(){"use strict";class t{constructor(t){this.data={},this.storageKey=t,this.loadData()}loadData(){let e=null;try{e=localStorage.getItem(this.storageKey)}catch(e){t.handleError(e)}this.data=e?JSON.parse(e):{}}saveData(){try{localStorage.setItem(this.storageKey,JSON.stringify(this.data))}catch(e){t.handleError(e)}}setValue(t,e){this.data[t]=e,this.saveData()}getValue(t){return this.data[t]||null}addValue(t,e){this.data[t]||(this.data[t]=[]),"string"!=typeof e||this.data[t].includes(e)||(this.data[t].push(e),this.saveData())}getValues(t){return this.data[t]||null}removeValue(t,e){if(this.data[t]){const a=this.data[t].indexOf(e);a>-1&&(this.data[t].splice(a,1),this.saveData())}}static handleError(t){if(!(t instanceof ReferenceError))throw t}}!function(Drupal){Drupal.behaviors.closable_surveys={attach:function(){const e=document.getElementById("block-surveys"),a=document.getElementById("skip-to-main");e&&(a?a.parentNode.insertBefore(e,a.nextSibling):document.body.insertBefore(e,document.body.firstChild));const n=document.getElementById("helfi-survey__container");if(!n)return;const i=document.documentElement,o=document.getElementById("helfi-survey__close-button"),s="hidden-helfi-surveys",r=new t("helfi-settings");let d=null,c=null;try{d=JSON.parse(window.localStorage.getItem("helfi-settings"))}catch(t){console.error("Error parsing local storage data:",t)}function l(t){i.classList.toggle("noscroll",t)}function u(t){if(t){const t=window.innerWidth-document.documentElement.clientWidth+"px";document.body.style.paddingRight=t}else document.body.style.removeProperty("padding-right")}function h(){const t=document.querySelector(".hds-cc__target"),e=t?.shadowRoot,a=e?.querySelector(".hds-cc__all-cookies-button");t&&a&&a.focus()}function f(){const t=document.querySelector(".dialog-off-canvas-main-canvas"),e=document.querySelector(".hds-cc__target");t&&!t.hasAttribute("aria-hidden")&&n?t.setAttribute("aria-hidden","true"):t&&t.removeAttribute("aria-hidden"),e&&!e.hasAttribute("aria-hidden")&&n?e.setAttribute("aria-hidden","true"):e&&e.removeAttribute("aria-hidden")}function y(){!function(){const{uuid:t}=n.dataset;t&&r.addValue(s,t)}(),c.deactivate(),n.remove(),l(!1),u(!1),h(),f()}o&&o.addEventListener("click",y),document.body.addEventListener("keydown",(function(t){"Escape"===t.key&&y()})),setTimeout((function(){const{uuid:t}=n.dataset;!t||!(d?.[s]||[]).includes(t)?(n.style.display="flex",u(!0),l(!0),c=window.focusTrap.createFocusTrap("#helfi-survey",{initialFocus:()=>"#helfi-survey__title"}),c.activate(),f()):(n.remove(),f(),h())}),2e3)}}}(Drupal)}(); \ No newline at end of file +!function(){"use strict";class t{constructor(t){this.data={},this.storageKey=t,this.loadData()}loadData(){let e=null;try{e=localStorage.getItem(this.storageKey)}catch(e){t.handleError(e)}this.data=e?JSON.parse(e):{}}saveData(){try{localStorage.setItem(this.storageKey,JSON.stringify(this.data))}catch(e){t.handleError(e)}}setValue(t,e){this.data[t]=e,this.saveData()}getValue(t){return this.data[t]||null}addValue(t,e){this.data[t]||(this.data[t]=[]),"string"!=typeof e||this.data[t].includes(e)||(this.data[t].push(e),this.saveData())}getValues(t){return this.data[t]||null}removeValue(t,e){if(this.data[t]){const a=this.data[t].indexOf(e);a>-1&&(this.data[t].splice(a,1),this.saveData())}}static handleError(t){if(!(t instanceof ReferenceError))throw t}}!function(Drupal){Drupal.behaviors.closable_surveys={attach:function(){const e=document.getElementById("block-surveys"),a=document.getElementById("skip-to-main");e&&(a?a.parentNode.insertBefore(e,a.nextSibling):document.body.insertBefore(e,document.body.firstChild));const n=document.getElementById("helfi-survey__container");if(!n)return;const i=document.documentElement,o=document.getElementById("helfi-survey__close-button"),s="hidden-helfi-surveys",r=new t("helfi-settings");let d=null,c=null;try{d=JSON.parse(window.localStorage.getItem("helfi-settings"))}catch(t){console.error("Error parsing local storage data:",t)}function l(t){i.classList.toggle("noscroll",t)}function u(t){if(t){const t=window.innerWidth-document.documentElement.clientWidth+"px";document.body.style.paddingRight=t}else document.body.style.removeProperty("padding-right")}function h(){const t=document.querySelector(".hds-cc__target"),e=t?.shadowRoot,a=e?.querySelector(".hds-cc__all-cookies-button");t&&a&&a.focus()}function y(){const t=document.querySelector(".dialog-off-canvas-main-canvas"),e=document.querySelector(".hds-cc__target"),a=document.getElementById("helfi-survey__container");t&&!t.hasAttribute("aria-hidden")&&a?t.setAttribute("aria-hidden","true"):t&&t.removeAttribute("aria-hidden"),e&&!e.hasAttribute("aria-hidden")&&a?e.setAttribute("aria-hidden","true"):e&&e.removeAttribute("aria-hidden")}function f(){!function(){const{uuid:t}=n.dataset;t&&r.addValue(s,t)}(),c.deactivate(),n.remove(),l(!1),u(!1),h(),y()}o&&o.addEventListener("click",f),document.body.addEventListener("keydown",(function(t){"Escape"===t.key&&f()})),setTimeout((function(){const{uuid:t}=n.dataset;!t||!(d?.[s]||[]).includes(t)?(n.style.display="flex",u(!0),l(!0),c=window.focusTrap.createFocusTrap("#helfi-survey",{initialFocus:()=>"#helfi-survey__title"}),c.activate(),y()):(n.remove(),y(),h())}),2e3)}}}(Drupal)}(); \ No newline at end of file diff --git a/src/js/closable-surveys.js b/src/js/closable-surveys.js index a8a607258..850a83f45 100644 --- a/src/js/closable-surveys.js +++ b/src/js/closable-surveys.js @@ -74,15 +74,16 @@ import LocalStorageManager from './localStorageManager'; function toggleOtherContentVisibility() { const mainContent = document.querySelector('.dialog-off-canvas-main-canvas'); const cookieBanner = document.querySelector('.hds-cc__target'); + const surveyContainer = document.getElementById('helfi-survey__container'); - if (mainContent && !mainContent.hasAttribute('aria-hidden') && survey) { + if (mainContent && !mainContent.hasAttribute('aria-hidden') && surveyContainer) { mainContent.setAttribute('aria-hidden', 'true'); } else { // eslint-disable-next-line no-unused-expressions mainContent && mainContent.removeAttribute('aria-hidden'); } - if (cookieBanner && !cookieBanner.hasAttribute('aria-hidden') && survey) { + if (cookieBanner && !cookieBanner.hasAttribute('aria-hidden') && surveyContainer) { cookieBanner.setAttribute('aria-hidden', 'true'); } else { // eslint-disable-next-line no-unused-expressions