diff --git a/dist/js/closable-surveys.min.js b/dist/js/closable-surveys.min.js index 07bef8e0d..f3a281695 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 n=this.data[t].indexOf(e);n>-1&&(this.data[t].splice(n,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"),n=document.getElementById("skip-to-main");e&&(n?n.parentNode.insertBefore(e,n.nextSibling):document.body.insertBefore(e,document.body.firstChild));const a=document.getElementById("helfi-survey__container");if(!a)return;const i=document.documentElement,o=document.getElementById("helfi-survey__close-button"),s="hidden-helfi-surveys",r=new t("helfi-settings");let c=null,d=null;try{c=JSON.parse(window.localStorage.getItem("helfi-settings"))}catch(t){console.error("Error parsing local storage data:",t)}function u(t){i.classList.toggle("noscroll",t)}function l(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,n=e?.querySelector(".hds-cc__all-cookies-button");t&&n&&n.focus()}function m(){const t=document.querySelector(".dialog-off-canvas-main-canvas"),e=document.querySelector(".hds-cc__target"),n=document.querySelector(".skip-link--skip-to-main"),a=document.getElementById("helfi-survey__container");t&&!t.hasAttribute("inert")&&a?t.setAttribute("inert",""):t&&t.removeAttribute("inert"),n&&!n.hasAttribute("inert")&&n?n.setAttribute("inert",""):n&&n.removeAttribute("inert"),e&&!e.hasAttribute("inert")&&a?e.setAttribute("inert",""):e&&e.removeAttribute("inert")}function y(){!function(){const{uuid:t}=a.dataset;t&&r.addValue(s,t)}(),d.deactivate(),a.remove(),u(!1),l(!1),h(),m()}o&&o.addEventListener("click",y),document.body.addEventListener("keydown",(function(t){"Escape"===t.key&&y()})),setTimeout((function(){const{uuid:t}=a.dataset;!t||!(c?.[s]||[]).includes(t)?(a.style.display="flex",l(!0),u(!0),d=window.focusTrap.createFocusTrap("#helfi-survey",{initialFocus:()=>"#helfi-survey__title"}),d.activate(),m()):(a.remove(),m(),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 n=this.data[t].indexOf(e);n>-1&&(this.data[t].splice(n,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"),n=document.getElementById("skip-to-main");e&&(n?n.parentNode.insertBefore(e,n.nextSibling):document.body.insertBefore(e,document.body.firstChild));const a=document.getElementById("helfi-survey__container");if(!a)return;const i=document.documentElement,o=document.getElementById("helfi-survey__close-button"),s="hidden-helfi-surveys",r=new t("helfi-settings");let c=null,d=null;try{c=JSON.parse(window.localStorage.getItem("helfi-settings"))}catch(t){console.error("Error parsing local storage data:",t)}function u(t){i.classList.toggle("noscroll",t)}function l(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,n=e?.querySelector(".hds-cc__all-cookies-button");t&&n&&n.focus()}function m(){const t=document.querySelector(".dialog-off-canvas-main-canvas"),e=document.querySelector(".hds-cc__target"),n=document.querySelector(".skip-link--skip-to-main"),a=document.getElementById("helfi-survey__container");t&&!t.hasAttribute("inert")&&a?t.setAttribute("inert",""):t&&t.removeAttribute("inert"),n&&!n.hasAttribute("inert")&&a?n.setAttribute("inert",""):n&&n.removeAttribute("inert"),e&&!e.hasAttribute("inert")&&a?e.setAttribute("inert",""):e&&e.removeAttribute("inert")}function y(){!function(){const{uuid:t}=a.dataset;t&&r.addValue(s,t)}(),d.deactivate(),a.remove(),u(!1),l(!1),h(),m()}o&&o.addEventListener("click",y),document.body.addEventListener("keydown",(function(t){"Escape"===t.key&&y()})),setTimeout((function(){const{uuid:t}=a.dataset;!t||!(c?.[s]||[]).includes(t)?(a.style.display="flex",l(!0),u(!0),d=window.focusTrap.createFocusTrap("#helfi-survey",{initialFocus:()=>"#helfi-survey__title"}),d.activate(),m()):(a.remove(),m(),h())}),2e3)}}}(Drupal)}(); \ No newline at end of file diff --git a/src/js/closable-surveys.js b/src/js/closable-surveys.js index 3113fbeb8..7c2d8c611 100644 --- a/src/js/closable-surveys.js +++ b/src/js/closable-surveys.js @@ -84,7 +84,7 @@ import LocalStorageManager from './localStorageManager'; mainContent && mainContent.removeAttribute('inert'); } - if (skipToMain && !skipToMain.hasAttribute('inert') && skipToMain) { + if (skipToMain && !skipToMain.hasAttribute('inert') && surveyContainer) { skipToMain.setAttribute('inert', ''); } else { // eslint-disable-next-line no-unused-expressions