diff --git a/dist/js/async/globalMenu.chunk.js b/dist/js/async/globalMenu.chunk.js deleted file mode 100644 index f129ce97b..000000000 --- a/dist/js/async/globalMenu.chunk.js +++ /dev/null @@ -1 +0,0 @@ -(self.webpackChunkhdbt=self.webpackChunkhdbt||[]).push([[595,854],{2858:function(t,e,n){"use strict";n.r(e),n.d(e,{default:function(){return B}});var r=Object.prototype.toString,i=Array.isArray||function(t){return"[object Array]"===r.call(t)};function s(t){return"function"==typeof t}function a(t){return t.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,"\\$&")}function o(t,e){return null!=t&&"object"==typeof t&&e in t}var l=RegExp.prototype.test;var u=/\S/;function c(t){return!function(t,e){return l.call(t,e)}(u,t)}var h={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/","`":"`","=":"="};var p=/\s*/,d=/\s+/,f=/\s*=/,m=/\s*\}/,g=/#|\^|\/|>|\{|&|=|!/;function v(t){this.string=t,this.tail=t,this.pos=0}function b(t,e){this.view=t,this.cache={".":this.view},this.parent=e}function _(){this.templateCache={_cache:{},set:function(t,e){this._cache[t]=e},get:function(t){return this._cache[t]},clear:function(){this._cache={}}}}v.prototype.eos=function(){return""===this.tail},v.prototype.scan=function(t){var e=this.tail.match(t);if(!e||0!==e.index)return"";var n=e[0];return this.tail=this.tail.substring(n.length),this.pos+=n.length,n},v.prototype.scanUntil=function(t){var e,n=this.tail.search(t);switch(n){case-1:e=this.tail,this.tail="";break;case 0:e="";break;default:e=this.tail.substring(0,n),this.tail=this.tail.substring(n)}return this.pos+=e.length,e},b.prototype.push=function(t){return new b(t,this)},b.prototype.lookup=function(t){var e,n,r,i=this.cache;if(i.hasOwnProperty(t))e=i[t];else{for(var a,l,u,c=this,h=!1;c;){if(t.indexOf(".")>0)for(a=c.view,l=t.split("."),u=0;null!=a&&u0?i[i.length-1][4]:n;break;default:r.push(e)}return n}(function(t){for(var e,n,r=[],i=0,s=t.length;i"===a?o=this.renderPartial(s,e,n,i):"&"===a?o=this.unescapedValue(s,e):"name"===a?o=this.escapedValue(s,e,i):"text"===a&&(o=this.rawValue(s)),void 0!==o&&(l+=o);return l},_.prototype.renderSection=function(t,e,n,r,a){var o=this,l="",u=e.lookup(t[1]);if(u){if(i(u))for(var c=0,h=u.length;c0||!n)&&(i[s]=r+i[s]);return i.join("\n")},_.prototype.renderPartial=function(t,e,n,r){if(n){var i=this.getConfigTags(r),a=s(n)?n(t[1]):n[t[1]];if(null!=a){var o=t[6],l=t[5],u=t[4],c=a;0==l&&u&&(c=this.indentPartial(a,u,o));var h=this.parse(c,i);return this.renderTokens(h,e,n,c,r)}}},_.prototype.unescapedValue=function(t,e){var n=e.lookup(t[1]);if(null!=n)return n},_.prototype.escapedValue=function(t,e,n){var r=this.getConfigEscape(n)||x.escape,i=e.lookup(t[1]);if(null!=i)return"number"==typeof i&&r===x.escape?String(i):r(i)},_.prototype.rawValue=function(t){return t[1]},_.prototype.getConfigTags=function(t){return i(t)?t:t&&"object"==typeof t?t.tags:void 0},_.prototype.getConfigEscape=function(t){return t&&"object"==typeof t&&!i(t)?t.escape:void 0};var x={name:"mustache.js",version:"4.2.0",tags:["{{","}}"],clearCache:void 0,escape:void 0,parse:void 0,render:void 0,Scanner:void 0,Context:void 0,Writer:void 0,set templateCache(t){k.templateCache=t},get templateCache(){return k.templateCache}},k=new _;x.clearCache=function(){return k.clearCache()},x.parse=function(t,e){return k.parse(t,e)},x.render=function(t,e,n,r){if("string"!=typeof t)throw new TypeError('Invalid template! Template should be a "string" but "'+((i(s=t)?"array":typeof s)+'" was given as the first argument for mustache#render(template, view, partials)'));var s;return k.render(t,e,n,r)},x.escape=function(t){return String(t).replace(/[&<>"'`=\/]/g,(function(t){return h[t]}))},x.Scanner=v,x.Context=b,x.Writer=_;var w=x,y=n(2485),I=n.n(y);const L=Drupal.t("Frontpage",{},{context:"Global navigation mobile menu top level"}),E=Drupal.t("Open submenu:",{},{context:"Mobile navigation menu prefix"}),P=Drupal.t("Open parent menu:",{},{context:"Mobile navigation menu prefix"});function C(){return this.sub_tree?.length>0}function S(){let t;try{t=new URL(this.url).pathname}catch(e){t=this.url}return!this.external&&this.url&&t===window.location.pathname}function A(){return!!this.active}function O(){return!!this.inPath}function T(){return!!this.is_injected}function j(){return{external:this.attributes["data-external"]||this.external||!1,protocol:this.attributes["data-protocol"]||!1}}function R(){return!!this.attributes?.lang}function U(){return!!this.external&&(U.ICONS[this.attributes["data-protocol"]]||U.ICONS.external)}Array.prototype.findRecursive=function(t,e){if(!e)throw new Error("findRecursive requires parameter `childrenPropertyName`");let n=[];n=this;const r=this.find(t),i=this.filter((t=>t[e]));if(r)return r;if(i.length){const n=[];return i.forEach((t=>{n.push(...t[e])})),n.findRecursive(t,e)}},U.ICONS={mailto:{class:"link__type link__type--mailto",text:Drupal.t("Link opens default mail program",{},{context:"Explanation for screen-reader software that the icon visible next to this link means that the link opens default mail program."})},tel:{class:"link__type link__type--tel",text:Drupal.t("Link starts a phone call",{},{context:"Explanation for screen-reader software that the icon visible next to this link means that the link starts a phone call."})},external:{class:"link__type link__type--external",text:Drupal.t("Link leads to external service",{},{context:"Explanation for screen-reader software that the icon visible next to this link means that the link leads to an external service."})}};var B={compileTemplates(){this.templates={panel:`\n {{#panels}}\n
\n \n ${document.querySelector(".js-mmenu__footer")?.outerHTML}\n
\n {{/panels}}\n\n {{^panels}}\n \n {{/panels}}\n `,list:'\n \n '}},menu:null,templates:null,SCROLL_TRESHOLD:100,size:10,running:!1,data:null,currentIndex:0,cacheKey:"hdbt-mobile-menu",enableCache:!1,selectors:{container:"#mmenu",rootId:"mmenu__panels",forward:"mmenu__forward",back:"mmenu__back"},getAPIUrl(){const t=new URL(drupalSettings?.helfi_navigation?.links?.api);return t.searchParams.set("_format","json"),t.searchParams.set("max-depth",drupalSettings?.menu_depth),t.toString()},getRoot(){return document.getElementById(this.selectors.rootId)},sortPanelsByPath(){const t=[],e=this.data,n=e.findRecursive((t=>S.call(t)),"sub_tree");let r=n?.sub_tree?.length?n.id:n?.parentId;for(;r;){e.findRecursive((({id:e,url:n,name:i,sub_tree:s,parentId:a,inPath:o,active:l})=>e===r&&(t.push({sub_tree:s,name:i,url:n,parentId:a,inPath:o,active:l}),r=a,!0)),"sub_tree")||(r=void 0)}t.push({sub_tree:e,inPath:!0}),t.reverse(),this.currentIndex=t.length-1,this.content=[...t]},content:[],getView(t){return this.content.map(((e,n)=>({...e,name:e?.name||L,url:e.url||drupalSettings.helfi_navigation.links.canonical,button:C,isActive:A,isInPath:O,isInjected:T,externalLinkAttributes:j,hasLang:R,externalLinkIcon:U,back:n>0&&(this.content.at(n-1)?.name??L),openSubMenuTranslation:E,openParentMenuTranslation:P,panel_class:I()({mmenu__panel:!0,"mmenu__panel--visible":!0,"mmenu__panel--current":n===this.currentIndex,"mmenu__panel--visible-right":"start"===t&&n>this.currentIndex||"up"===t&&n>=this.currentIndex||"down"===t&&n>this.currentIndex+1,"mmenu__panel--visible-left":"up"===t&&ne===t));if(!e)throw new Error(`ID mismatch in menu items${t}`);this.currentIndex=this.currentIndex+1=0?this.currentIndex-1:this.currentIndex,this.render("down"))},render(t){const e=this.getRoot();if(e.innerHTML=w.render(this.templates.panel,{panels:this.getView(t)},{sub_tree:this.templates.list}),"load"===t)return;const n=[...e.querySelectorAll(".mmenu__panel")],r=n.at(this.currentIndex);e.parentElement.scrollTop>this.SCROLL_TRESHOLD&&this.currentIndex>0&&r.querySelector(".mmenu__back").scrollIntoView({block:"start",behaviour:"smooth"}),setTimeout((()=>{switch(r.classList.remove("mmenu__panel--visible-right","mmenu__panel--visible-left"),t){case"up":n.at(this.currentIndex-1).classList.add("mmenu__panel--visible-left");break;case"down":n.at(this.currentIndex+1).classList.add("mmenu__panel--visible-right")}setTimeout((()=>{n.forEach((t=>{t.classList.contains("mmenu__panel--current")||(t.style.visibility="hidden")}))}),200)}),10)},async load(){const t=await fetch(this.getAPIUrl()),e=await t.json(),n=Object.getOwnPropertyNames(e);if(!n.length)throw new Error("No instances found in data",e);const r=n.map((t=>{const n=e[t].menu_tree[0];return n.parentId="",n})),i=r.findRecursive((t=>S.call(t)),"sub_tree");i&&(i.active=!0,i.inPath=!0);let s=i?.parentId;for(;s;){r.findRecursive((t=>t.id===s&&(s=t.parentId,t.inPath=!0,!0)),"sub_tree")||(s=void 0)}this.data=r},async start(){const t=document.querySelector(this.selectors.container);if(!this.getRoot()||!t)throw new Error("Panel root not found");t.classList.add("mmenu--visible"),this.render("load");try{await this.load()}catch(t){return console.error("Unable to load menu API, using fallback menu instead",t),void this.enableFallback()}this.sortPanelsByPath(),this.render("start"),this.getRoot().addEventListener("click",(t=>{const{target:{classList:e,value:n,parentElement:r}}=t;t.stopImmediatePropagation(),e&&e.contains(this.selectors.forward)?this.up(n):(e&&e.contains(this.selectors.back)||r?.classList&&r?.classList.contains(this.selectors.back))&&this.down()}))},isOpen(){return"#menu"===window.location.hash||"true"===this.toggleButton.getAttribute("aria-expanded")},disableFallback(){this.menu.dataset.js=!0},enableFallback(){this.menu.dataset.target="false",this.getRoot().innerHTML="",delete this.menu.dataset.js,window.location.hash="#menu"},close(){this.toggleButton.setAttribute("aria-expanded","false"),this.menu.dataset.target="false",this.onClose&&this.onClose()},open(){this.menu.dataset.target="true",this.toggleButton.setAttribute("aria-expanded","true"),this.onOpen&&this.onOpen()},toggle(){this.isOpen()?this.close():this.open(),this.toggleButton.focus()},init({onOpen:t,onClose:e}){if(this.running)return void console.warn("MobilePanel already initiated. Is it include more than once?");if(this.onOpen=t,this.onClose=e,this.toggleButton=document.querySelector(".js-menu-toggle-button"),!this.toggleButton)throw new Error("No toggle button for JS menu.");if(this.menu=document.querySelector("#menu"),!this.menu)return void console.error("Panel not present in DOM. Cannot start JS mobile menu");this.disableFallback(),document.addEventListener("keydown",(t=>{"Escape"!==t.key&&"Esc"!==t.key&&27!==t.keyCode||!this.isOpen()||(this.close(),this.toggleButton.focus())}));const n=()=>{this.compileTemplates(),this.toggleButton.removeEventListener("click",n),this.start()};this.toggleButton.addEventListener("click",n),this.toggleButton.addEventListener("click",(()=>this.toggle())),this.isOpen()&&(window.location.hash="",n(),this.open()),this.running=!0}}},2485:function(t,e){var n;!function(){"use strict";var r={}.hasOwnProperty;function i(){for(var t=[],e=0;e{"Escape"!==t.key&&"Esc"!==t.key&&27!==t.keyCode||!this.isOpen()||(this.close(),this.buttonInstance.focus())})),this.buttonInstance.addEventListener("click",(()=>{this.toggle()}))}init({name:t,buttonSelector:e,targetSelector:n,onOpen:s,onClose:i}){if(this.name=t,this.buttonSelector=e,this.buttonInstance=document.querySelector(this.buttonSelector),!this.buttonInstance)return this.running=!1,void console.warn(`${t} button missing. Looking for ${this.buttonSelector}`);if(this.running)console.warn(`${t} already initiated. Is it included more than once?`);else{if(this.HASH_ID=n,this.onOpen=s,this.onClose=i,this.targetNode=document.querySelector(this.HASH_ID),!this.targetNode)throw new Error(`${t} target node missing. Looking for ${this.HASH_ID}`);this.targetNode.dataset.js=!0,this.addListeners(),this.running=!0}}}t.exports=()=>new e}}]); \ No newline at end of file diff --git a/dist/js/async/toggleWidgets.chunk.js b/dist/js/async/toggleWidgets.chunk.js deleted file mode 100644 index 7d765d521..000000000 --- a/dist/js/async/toggleWidgets.chunk.js +++ /dev/null @@ -1 +0,0 @@ -(self.webpackChunkhdbt=self.webpackChunkhdbt||[]).push([[305,655],{3628:function(e){const t=["#chat-leijuke-wrapper",".si-toggle-container",".cx-theme-helsinki-blue",".aca--button--desktop, .aca--button--mobile, .aca--widget--mobile, .aca--widget--desktop, #aca--widget-button-close","#telia-ace-leijuke",".humany-trigger, .humany-widget","#ed11y-panel","#sliding-popup"],a=()=>{document.querySelectorAll(t.join(",")).forEach((e=>{e.dataset.cssmenuHide=!0}))},o=()=>{document.querySelectorAll(t.join(",")).forEach((e=>{delete e.dataset.cssmenuHide}))};e.exports={setHide:e=>{(!0===e?a:o)()},close:a,open:o,HIDE_SELECTORS:t}}}]); \ No newline at end of file diff --git a/dist/js/nav-toggle.min.js b/dist/js/nav-toggle.min.js index 00c96cbae..5cf1bac8b 100644 --- a/dist/js/nav-toggle.min.js +++ b/dist/js/nav-toggle.min.js @@ -1 +1 @@ -!function(){var e,t,n,r,o={},i={};function c(e){var t=i[e];if(void 0!==t)return t.exports;var n=i[e]={exports:{}};return o[e](n,n.exports,c),n.exports}c.m=o,c.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return c.d(t,{a:t}),t},t=Object.getPrototypeOf?function(e){return Object.getPrototypeOf(e)}:function(e){return e.__proto__},c.t=function(n,r){if(1&r&&(n=this(n)),8&r)return n;if("object"==typeof n&&n){if(4&r&&n.__esModule)return n;if(16&r&&"function"==typeof n.then)return n}var o=Object.create(null);c.r(o);var i={};e=e||[null,t({}),t([]),t(t)];for(var a=2&r&&n;"object"==typeof a&&!~e.indexOf(a);a=t(a))Object.getOwnPropertyNames(a).forEach((function(e){i[e]=function(){return n[e]}}));return i.default=function(){return n},c.d(o,i),o},c.d=function(e,t){for(var n in t)c.o(t,n)&&!c.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},c.f={},c.e=function(e){return Promise.all(Object.keys(c.f).reduce((function(t,n){return c.f[n](e,t),t}),[]))},c.u=function(e){return"js/async/"+{209:"navToggleDropdown",305:"toggleWidgets",595:"globalMenu"}[e]+".chunk.js"},c.miniCssF=function(e){},c.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),c.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n={},r="hdbt:",c.l=function(e,t,o,i){if(n[e])n[e].push(t);else{var a,u;if(void 0!==o)for(var s=document.getElementsByTagName("script"),l=0;l-1&&(!e||!/^http(s?):/.test(e));)e=n[r--].src}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),c.p=e+"../"}(),function(){var e={343:0};c.f.j=function(t,n){var r=c.o(e,t)?e[t]:void 0;if(0!==r)if(r)n.push(r[2]);else{var o=new Promise((function(n,o){r=e[t]=[n,o]}));n.push(r[2]=o);var i=c.p+c.u(t),a=new Error;c.l(i,(function(n){if(c.o(e,t)&&(0!==(r=e[t])&&(e[t]=void 0),r)){var o=n&&("load"===n.type?"missing":n.type),i=n&&n.target&&n.target.src;a.message="Loading chunk "+t+" failed.\n("+o+": "+i+")",a.name="ChunkLoadError",a.type=o,a.request=i,r[1](a)}}),"chunk-"+t,t)}};var t=function(t,n){var r,o,i=n[0],a=n[1],u=n[2],s=0;if(i.some((function(t){return 0!==e[t]}))){for(r in a)c.o(a,r)&&(c.m[r]=a[r]);if(u)u(c)}for(t&&t(n);s{const{close:e,open:t}=await c.e(305).then(c.t.bind(c,3628,23)),n=(await c.e(209).then(c.t.bind(c,9296,23))).default,r={};let o,i={};!0===drupalSettings.hdbt.profile_dropdown&&(r.ProfileDropdown="profile"),!0===drupalSettings.hdbt.search_dropdown&&(r.SearchDropdown="search"),!0===drupalSettings.hdbt.otherlangs_dropdown&&(r.OtherLangsDropdown="otherlangs"),!0===drupalSettings.hdbt.global_menu?(o=await c.e(595).then(c.bind(c,2858)),i=o.default):r.CssMenuDropdownDropdown="cssmenu";const a=r,u=Object.keys(a);u.forEach((r=>{const o=a[r];a[r]=n(),a[r].init({name:`${o} dropdown`,buttonSelector:`.js-${o}-button`,targetSelector:`#${o}`,onOpen:()=>{u.forEach((e=>{e!==r&&a[e].close()})),0!==Object.keys(i).length&&i.close(),e(),"SearchDropdown"===r&&window.setTimeout((()=>document.querySelector('.header-search-wrapper input[type="search"]')?.focus()),10)},onClose:t})})),0!==Object.keys(i).length&&i.init({onOpen:()=>{u.forEach((e=>{a[e].close()})),e()},onClose:t});const s=e=>{if(e.touches&&e.touches.length>1)return!0;const t=e.target.closest(".mmenu__panel--current, .nav-toggle-dropdown__content");var n;return window.matchMedia("(max-width: 768px)").matches&&(()=>{let e=!1;return u.forEach((t=>{void 0!==a[t].dataset&&a[t].isOpen()&&(e=!0)})),0!==Object.keys(i).length&&i.isOpen()&&(e=!0),e})()&&(null===e.target.closest(".nav-toggle-dropdown")||null!==t&&!((n=t).scrollWidth>n.clientWidth||n.scrollHeight>n.clientHeight))?(e.preventDefault(),e.stopPropagation(),!1):void 0};document.addEventListener("click",(({target:e})=>{(e.closest(".desktop-menu, .header-top")||null===e.closest(".header"))&&(u.forEach((e=>{a[e].close()})),0!==Object.keys(i).length&&i.close(),t())}));const l=document.querySelector("body");l.addEventListener("wheel",s,{passive:!1}),l.addEventListener("scroll",s,{passive:!1}),l.addEventListener("touchmove",s,{passive:!1})})()}(); \ No newline at end of file +!function(){var t={2858:function(t,e,n){"use strict";n.d(e,{A:function(){return H}});var r=Object.prototype.toString,s=Array.isArray||function(t){return"[object Array]"===r.call(t)};function i(t){return"function"==typeof t}function a(t){return t.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,"\\$&")}function o(t,e){return null!=t&&"object"==typeof t&&e in t}var l=RegExp.prototype.test;var c=/\S/;function u(t){return!function(t,e){return l.call(t,e)}(c,t)}var h={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/","`":"`","=":"="};var p=/\s*/,d=/\s+/,f=/\s*=/,g=/\s*\}/,m=/#|\^|\/|>|\{|&|=|!/;function v(t){this.string=t,this.tail=t,this.pos=0}function b(t,e){this.view=t,this.cache={".":this.view},this.parent=e}function _(){this.templateCache={_cache:{},set:function(t,e){this._cache[t]=e},get:function(t){return this._cache[t]},clear:function(){this._cache={}}}}v.prototype.eos=function(){return""===this.tail},v.prototype.scan=function(t){var e=this.tail.match(t);if(!e||0!==e.index)return"";var n=e[0];return this.tail=this.tail.substring(n.length),this.pos+=n.length,n},v.prototype.scanUntil=function(t){var e,n=this.tail.search(t);switch(n){case-1:e=this.tail,this.tail="";break;case 0:e="";break;default:e=this.tail.substring(0,n),this.tail=this.tail.substring(n)}return this.pos+=e.length,e},b.prototype.push=function(t){return new b(t,this)},b.prototype.lookup=function(t){var e,n,r,s=this.cache;if(s.hasOwnProperty(t))e=s[t];else{for(var a,l,c,u=this,h=!1;u;){if(t.indexOf(".")>0)for(a=u.view,l=t.split("."),c=0;null!=a&&c0?s[s.length-1][4]:n;break;default:r.push(e)}return n}(function(t){for(var e,n,r=[],s=0,i=t.length;s"===a?o=this.renderPartial(i,e,n,s):"&"===a?o=this.unescapedValue(i,e):"name"===a?o=this.escapedValue(i,e,s):"text"===a&&(o=this.rawValue(i)),void 0!==o&&(l+=o);return l},_.prototype.renderSection=function(t,e,n,r,a){var o=this,l="",c=e.lookup(t[1]);if(c){if(s(c))for(var u=0,h=c.length;u0||!n)&&(s[i]=r+s[i]);return s.join("\n")},_.prototype.renderPartial=function(t,e,n,r){if(n){var s=this.getConfigTags(r),a=i(n)?n(t[1]):n[t[1]];if(null!=a){var o=t[6],l=t[5],c=t[4],u=a;0==l&&c&&(u=this.indentPartial(a,c,o));var h=this.parse(u,s);return this.renderTokens(h,e,n,u,r)}}},_.prototype.unescapedValue=function(t,e){var n=e.lookup(t[1]);if(null!=n)return n},_.prototype.escapedValue=function(t,e,n){var r=this.getConfigEscape(n)||w.escape,s=e.lookup(t[1]);if(null!=s)return"number"==typeof s&&r===w.escape?String(s):r(s)},_.prototype.rawValue=function(t){return t[1]},_.prototype.getConfigTags=function(t){return s(t)?t:t&&"object"==typeof t?t.tags:void 0},_.prototype.getConfigEscape=function(t){return t&&"object"==typeof t&&!s(t)?t.escape:void 0};var w={name:"mustache.js",version:"4.2.0",tags:["{{","}}"],clearCache:void 0,escape:void 0,parse:void 0,render:void 0,Scanner:void 0,Context:void 0,Writer:void 0,set templateCache(t){x.templateCache=t},get templateCache(){return x.templateCache}},x=new _;w.clearCache=function(){return x.clearCache()},w.parse=function(t,e){return x.parse(t,e)},w.render=function(t,e,n,r){if("string"!=typeof t)throw new TypeError('Invalid template! Template should be a "string" but "'+((s(i=t)?"array":typeof i)+'" was given as the first argument for mustache#render(template, view, partials)'));var i;return x.render(t,e,n,r)},w.escape=function(t){return String(t).replace(/[&<>"'`=\/]/g,(function(t){return h[t]}))},w.Scanner=v,w.Context=b,w.Writer=_;var y=w,k=n(2485),I=n.n(k);const L=Drupal.t("Frontpage",{},{context:"Global navigation mobile menu top level"}),S=Drupal.t("Open submenu:",{},{context:"Mobile navigation menu prefix"}),E=Drupal.t("Open parent menu:",{},{context:"Mobile navigation menu prefix"});function A(){return this.sub_tree?.length>0}function O(){let t;try{t=new URL(this.url).pathname}catch(e){t=this.url}return!this.external&&this.url&&t===window.location.pathname}function C(){return!!this.active}function P(){return!!this.inPath}function j(){return!!this.is_injected}function T(){return{external:this.attributes["data-external"]||this.external||!1,protocol:this.attributes["data-protocol"]||!1}}function D(){return!!this.attributes?.lang}function R(){return!!this.external&&(R.ICONS[this.attributes["data-protocol"]]||R.ICONS.external)}Array.prototype.findRecursive=function(t,e){if(!e)throw new Error("findRecursive requires parameter `childrenPropertyName`");let n=[];n=this;const r=this.find(t),s=this.filter((t=>t[e]));if(r)return r;if(s.length){const n=[];return s.forEach((t=>{n.push(...t[e])})),n.findRecursive(t,e)}},R.ICONS={mailto:{class:"link__type link__type--mailto",text:Drupal.t("Link opens default mail program",{},{context:"Explanation for screen-reader software that the icon visible next to this link means that the link opens default mail program."})},tel:{class:"link__type link__type--tel",text:Drupal.t("Link starts a phone call",{},{context:"Explanation for screen-reader software that the icon visible next to this link means that the link starts a phone call."})},external:{class:"link__type link__type--external",text:Drupal.t("Link leads to external service",{},{context:"Explanation for screen-reader software that the icon visible next to this link means that the link leads to an external service."})}};var H={compileTemplates(){this.templates={panel:`\n {{#panels}}\n
\n \n ${document.querySelector(".js-mmenu__footer")?.outerHTML}\n
\n {{/panels}}\n\n {{^panels}}\n \n {{/panels}}\n `,list:'\n \n '}},menu:null,templates:null,SCROLL_TRESHOLD:100,size:10,running:!1,data:null,currentIndex:0,cacheKey:"hdbt-mobile-menu",enableCache:!1,selectors:{container:"#mmenu",rootId:"mmenu__panels",forward:"mmenu__forward",back:"mmenu__back"},getAPIUrl(){const t=new URL(drupalSettings?.helfi_navigation?.links?.api);return t.searchParams.set("_format","json"),t.searchParams.set("max-depth",drupalSettings?.menu_depth),t.toString()},getRoot(){return document.getElementById(this.selectors.rootId)},sortPanelsByPath(){const t=[],e=this.data,n=e.findRecursive((t=>O.call(t)),"sub_tree");let r=n?.sub_tree?.length?n.id:n?.parentId;for(;r;){e.findRecursive((({id:e,url:n,name:s,sub_tree:i,parentId:a,inPath:o,active:l})=>e===r&&(t.push({sub_tree:i,name:s,url:n,parentId:a,inPath:o,active:l}),r=a,!0)),"sub_tree")||(r=void 0)}t.push({sub_tree:e,inPath:!0}),t.reverse(),this.currentIndex=t.length-1,this.content=[...t]},content:[],getView(t){return this.content.map(((e,n)=>({...e,name:e?.name||L,url:e.url||drupalSettings.helfi_navigation.links.canonical,button:A,isActive:C,isInPath:P,isInjected:j,externalLinkAttributes:T,hasLang:D,externalLinkIcon:R,back:n>0&&(this.content.at(n-1)?.name??L),openSubMenuTranslation:S,openParentMenuTranslation:E,panel_class:I()({mmenu__panel:!0,"mmenu__panel--visible":!0,"mmenu__panel--current":n===this.currentIndex,"mmenu__panel--visible-right":"start"===t&&n>this.currentIndex||"up"===t&&n>=this.currentIndex||"down"===t&&n>this.currentIndex+1,"mmenu__panel--visible-left":"up"===t&&ne===t));if(!e)throw new Error(`ID mismatch in menu items${t}`);this.currentIndex=this.currentIndex+1=0?this.currentIndex-1:this.currentIndex,this.render("down"))},render(t){const e=this.getRoot();if(e.innerHTML=y.render(this.templates.panel,{panels:this.getView(t)},{sub_tree:this.templates.list}),"load"===t)return;const n=[...e.querySelectorAll(".mmenu__panel")],r=n.at(this.currentIndex);e.parentElement.scrollTop>this.SCROLL_TRESHOLD&&this.currentIndex>0&&r.querySelector(".mmenu__back").scrollIntoView({block:"start",behaviour:"smooth"}),setTimeout((()=>{switch(r.classList.remove("mmenu__panel--visible-right","mmenu__panel--visible-left"),t){case"up":n.at(this.currentIndex-1).classList.add("mmenu__panel--visible-left");break;case"down":n.at(this.currentIndex+1).classList.add("mmenu__panel--visible-right")}setTimeout((()=>{n.forEach((t=>{t.classList.contains("mmenu__panel--current")||(t.style.visibility="hidden")}))}),200)}),10)},async load(){const t=await fetch(this.getAPIUrl()),e=await t.json(),n=Object.getOwnPropertyNames(e);if(!n.length)throw new Error("No instances found in data",e);const r=n.map((t=>{const n=e[t].menu_tree[0];return n.parentId="",n})),s=r.findRecursive((t=>O.call(t)),"sub_tree");s&&(s.active=!0,s.inPath=!0);let i=s?.parentId;for(;i;){r.findRecursive((t=>t.id===i&&(i=t.parentId,t.inPath=!0,!0)),"sub_tree")||(i=void 0)}this.data=r},async start(){const t=document.querySelector(this.selectors.container);if(!this.getRoot()||!t)throw new Error("Panel root not found");t.classList.add("mmenu--visible"),this.render("load");try{await this.load()}catch(t){return console.error("Unable to load menu API, using fallback menu instead",t),void this.enableFallback()}this.sortPanelsByPath(),this.render("start"),this.getRoot().addEventListener("click",(t=>{const{target:{classList:e,value:n,parentElement:r}}=t;t.stopImmediatePropagation(),e&&e.contains(this.selectors.forward)?this.up(n):(e&&e.contains(this.selectors.back)||r?.classList&&r?.classList.contains(this.selectors.back))&&this.down()}))},isOpen(){return"#menu"===window.location.hash||"true"===this.toggleButton.getAttribute("aria-expanded")},disableFallback(){this.menu.dataset.js=!0},enableFallback(){this.menu.dataset.target="false",this.getRoot().innerHTML="",delete this.menu.dataset.js,window.location.hash="#menu"},close(){this.toggleButton.setAttribute("aria-expanded","false"),this.menu.dataset.target="false",this.onClose&&this.onClose()},open(){this.menu.dataset.target="true",this.toggleButton.setAttribute("aria-expanded","true"),this.onOpen&&this.onOpen()},toggle(){this.isOpen()?this.close():this.open(),this.toggleButton.focus()},init({onOpen:t,onClose:e}){if(this.running)return void console.warn("MobilePanel already initiated. Is it include more than once?");if(this.onOpen=t,this.onClose=e,this.toggleButton=document.querySelector(".js-menu-toggle-button"),!this.toggleButton)throw new Error("No toggle button for JS menu.");if(this.menu=document.querySelector("#menu"),!this.menu)return void console.error("Panel not present in DOM. Cannot start JS mobile menu");this.disableFallback(),document.addEventListener("keydown",(t=>{"Escape"!==t.key&&"Esc"!==t.key&&27!==t.keyCode||!this.isOpen()||(this.close(),this.toggleButton.focus())}));const n=()=>{this.compileTemplates(),this.toggleButton.removeEventListener("click",n),this.start()};this.toggleButton.addEventListener("click",n),this.toggleButton.addEventListener("click",(()=>this.toggle())),this.isOpen()&&(window.location.hash="",n(),this.open()),this.running=!0}}},9296:function(t){class e{constructor(){this.HASH_ID=null,this.buttonSelector=null,this.buttonInstance=null,this.running=!1,this.targetNode=null,this.onOpen=null}isOpen(){return window.location.hash===this.HASH_ID||"true"===this.targetNode.dataset.target}close(){this.running&&(this.buttonInstance.setAttribute("aria-expanded","false"),this.targetNode.dataset.target="false",this.onClose&&this.onClose())}open(){this.running&&(this.buttonInstance.setAttribute("aria-expanded","true"),this.targetNode.dataset.target="true",this.onOpen&&this.onOpen())}toggle(){this.isOpen()?this.close():this.open(),this.buttonInstance.focus()}addListeners(){document.addEventListener("keydown",(t=>{"Escape"!==t.key&&"Esc"!==t.key&&27!==t.keyCode||!this.isOpen()||(this.close(),this.buttonInstance.focus())})),this.buttonInstance.addEventListener("click",(()=>{this.toggle()}))}init({name:t,buttonSelector:e,targetSelector:n,onOpen:r,onClose:s}){if(this.name=t,this.buttonSelector=e,this.buttonInstance=document.querySelector(this.buttonSelector),!this.buttonInstance)return this.running=!1,void console.warn(`${t} button missing. Looking for ${this.buttonSelector}`);if(this.running)console.warn(`${t} already initiated. Is it included more than once?`);else{if(this.HASH_ID=n,this.onOpen=r,this.onClose=s,this.targetNode=document.querySelector(this.HASH_ID),!this.targetNode)throw new Error(`${t} target node missing. Looking for ${this.HASH_ID}`);this.targetNode.dataset.js=!0,this.addListeners(),this.running=!0}}}t.exports=()=>new e},3628:function(t){const e=["#chat-leijuke-wrapper",".si-toggle-container",".cx-theme-helsinki-blue",".aca--button--desktop, .aca--button--mobile, .aca--widget--mobile, .aca--widget--desktop, #aca--widget-button-close","#telia-ace-leijuke",".humany-trigger, .humany-widget","#ed11y-panel","#sliding-popup"],n=()=>{document.querySelectorAll(e.join(",")).forEach((t=>{t.dataset.cssmenuHide=!0}))},r=()=>{document.querySelectorAll(e.join(",")).forEach((t=>{delete t.dataset.cssmenuHide}))};t.exports={setHide:t=>{(!0===t?n:r)()},close:n,open:r,HIDE_SELECTORS:e}},2485:function(t,e){var n;!function(){"use strict";var r={}.hasOwnProperty;function s(){for(var t=[],e=0;e{const e={},n=drupalSettings.hdbt.global_menu?s.A:void 0;drupalSettings.hdbt.profile_dropdown&&(e.ProfileDropdown="profile"),drupalSettings.hdbt.search_dropdown&&(e.SearchDropdown="search"),drupalSettings.hdbt.otherlangs_dropdown&&(e.OtherLangsDropdown="otherlangs"),n||(e.CssMenuDropdownDropdown="cssmenu");const i=e,a=Object.keys(i);a.forEach((e=>{const n=i[e];i[e]=r()(),i[e].init({name:`${n} dropdown`,buttonSelector:`.js-${n}-button`,targetSelector:`#${n}`,onOpen:()=>{a.forEach((t=>{t!==e&&i[t].close()})),Object.keys(s.A).length&&s.A.close(),(0,t.close)(),"SearchDropdown"===e&&window.setTimeout((()=>document.querySelector('.header-search-wrapper input[type="search"]')?.focus()),10)},onClose:t.open})})),Object.keys(s.A).length&&s.A.init({onOpen:()=>{a.forEach((t=>{i[t].close()})),(0,t.close)()},onClose:t.open});const o=t=>{if(t.touches?.length>1)return!0;const e=t.target.closest(".mmenu__panel--current, .nav-toggle-dropdown__content");var n;return window.matchMedia("(max-width: 768px)").matches&&(a.some((t=>i[t].dataset&&i[t].isOpen()))||Object.keys(s.A).length&&s.A.isOpen())&&(!t.target.closest(".nav-toggle-dropdown")||e&&!((n=e).scrollWidth>n.clientWidth||n.scrollHeight>n.clientHeight))?(t.preventDefault(),t.stopPropagation(),!1):void 0};document.addEventListener("click",(({target:e})=>{!e.closest(".desktop-menu, .header-top")&&e.closest(".header")||(a.forEach((t=>{i[t].close()})),Object.keys(s.A).length&&s.A.close(),(0,t.open)())}));const l=document.querySelector("body");l.addEventListener("wheel",o,{passive:!1}),l.addEventListener("scroll",o,{passive:!1}),l.addEventListener("touchmove",o,{passive:!1})})()}()}(); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index df1145109..0d33887cd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10548,11 +10548,10 @@ } }, "node_modules/express": { - "version": "4.21.1", - "resolved": "https://registry.npmjs.org/express/-/express-4.21.1.tgz", - "integrity": "sha512-YSFlK1Ee0/GC8QaO91tHcDxJiE/X4FbpAyQWkxAvG6AXCuR65YzK8ua6D9hvi/TzUfZMpc+BwuM1IPw8fmQBiQ==", + "version": "4.21.2", + "resolved": "https://registry.npmjs.org/express/-/express-4.21.2.tgz", + "integrity": "sha512-28HqgMZAmih1Czt9ny7qr6ek2qddF4FclbMzwhCREB6OFfH+rXAnuNCwo1/wFvrtbgsQDb4kSbX9de9lFbrXnA==", "dev": true, - "license": "MIT", "dependencies": { "accepts": "~1.3.8", "array-flatten": "1.1.1", @@ -10573,7 +10572,7 @@ "methods": "~1.1.2", "on-finished": "2.4.1", "parseurl": "~1.3.3", - "path-to-regexp": "0.1.10", + "path-to-regexp": "0.1.12", "proxy-addr": "~2.0.7", "qs": "6.13.0", "range-parser": "~1.2.1", @@ -10588,6 +10587,10 @@ }, "engines": { "node": ">= 0.10.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" } }, "node_modules/express/node_modules/cookie": { @@ -14375,9 +14378,9 @@ } }, "node_modules/nanoid": { - "version": "3.3.7", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.7.tgz", - "integrity": "sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==", + "version": "3.3.8", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.8.tgz", + "integrity": "sha512-WNLf5Sd8oZxOm+TzppcYk8gVOgP+l58xNy58D0nbUnOxOWRWvlcCV4kUF7ltmI6PsrLl/BgKEyS4mqsGChFN0w==", "funding": [ { "type": "github", @@ -15026,9 +15029,9 @@ } }, "node_modules/path-to-regexp": { - "version": "0.1.10", - "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.10.tgz", - "integrity": "sha512-7lf7qcQidTku0Gu3YDPc8DJ1q7OOucfa/BSsIwjuh56VU7katFvuM8hULfkwB3Fns/rsVF7PwPKVw1sl5KQS9w==", + "version": "0.1.12", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.12.tgz", + "integrity": "sha512-RA1GjUVMnvYFxuqovrEqZoxxW5NUZqbwKtYz/Tt7nXerk0LbLblQmrsgdeOxV5SFHf0UDggjS/bSeOZwt1pmEQ==", "dev": true }, "node_modules/path-type": { diff --git a/src/js/nav-toggle.js b/src/js/nav-toggle.js index 796742a77..5b4850c0e 100644 --- a/src/js/nav-toggle.js +++ b/src/js/nav-toggle.js @@ -1,39 +1,35 @@ -(async () => { - const {close, open} = await import(/* webpackChunkName: "toggleWidgets" */ './nav-toggle/toggle-widgets'); - const NavToggle = await import(/* webpackChunkName: "navToggleDropdown" */ './nav-toggle/nav-toggle-dropdown'); - const NavToggleDropdown = NavToggle.default; +import { close, open } from './nav-toggle/toggle-widgets'; +import NavToggleDropdown from './nav-toggle/nav-toggle-dropdown'; +import MenuDropdown from './nav-global/menu'; - const BRANDING_ELEMENTS = {}; - let MENU; - let MenuDropdown = {}; +(() => { + const brandingElements = {}; + const menu = drupalSettings.hdbt.global_menu ? MenuDropdown : undefined; // Check what features on header branding region are on. - if (drupalSettings.hdbt.profile_dropdown === true) { - BRANDING_ELEMENTS.ProfileDropdown = 'profile'; + if (drupalSettings.hdbt.profile_dropdown) { + brandingElements.ProfileDropdown = 'profile'; } - if (drupalSettings.hdbt.search_dropdown === true) { - BRANDING_ELEMENTS.SearchDropdown = 'search'; + if (drupalSettings.hdbt.search_dropdown) { + brandingElements.SearchDropdown = 'search'; } - if (drupalSettings.hdbt.otherlangs_dropdown === true) { - BRANDING_ELEMENTS.OtherLangsDropdown = 'otherlangs'; + if (drupalSettings.hdbt.otherlangs_dropdown) { + brandingElements.OtherLangsDropdown = 'otherlangs'; } - if (drupalSettings.hdbt.global_menu === true) { - MENU = await import(/* webpackChunkName: "globalMenu" */ './nav-global/menu'); - MenuDropdown = MENU.default; - } else { - BRANDING_ELEMENTS.CssMenuDropdownDropdown = 'cssmenu'; + if (!menu) { + brandingElements.CssMenuDropdownDropdown = 'cssmenu'; } - function isScrollable(element) { - return element.scrollWidth > element.clientWidth || element.scrollHeight > element.clientHeight; - } + const isScrollable = (element) => element.scrollWidth > element.clientWidth || element.scrollHeight > element.clientHeight; - const isMobile = () => window.matchMedia('(max-width: 768px)').matches; // Needs to be 768px as after that breakpoint user can scroll header almost offscreen, open menu accidentally and not be able to scroll back up. + // Needs to be 768px as after that breakpoint user can scroll header + // almost offscreen, open menu accidentally and not be able to scroll back up. + const isMobile = () => window.matchMedia('(max-width: 768px)').matches; - const AllElements = BRANDING_ELEMENTS; + const AllElements = brandingElements; const keys = Object.keys(AllElements); @@ -51,19 +47,21 @@ AllElements[menuName].close(); } }); - if (Object.keys(MenuDropdown).length !== 0) { + if (Object.keys(MenuDropdown).length) { MenuDropdown.close(); } close(); if (key === 'SearchDropdown') { - // Focus search field on open. - window.setTimeout(() => document.querySelector('.header-search-wrapper input[type="search"]')?.focus(), 10); // Delay focus until element is focusable + // Focus search field on open and delay focus + // until element is focusable. + window.setTimeout(() => document.querySelector('.header-search-wrapper input[type="search"]')?.focus(), 10); } }, onClose: open }); }); - if (Object.keys(MenuDropdown).length !== 0) { + + if (Object.keys(MenuDropdown).length) { MenuDropdown.init({ onOpen: () => { keys.forEach((key) => { @@ -75,61 +73,38 @@ }); } - /** - * See if menu instance is open - * - * @return boolean - */ - - const isAnyMenuOpen = () => { - let isOpen = false; - - keys.forEach((key) => { - if (AllElements[key].dataset !== undefined && AllElements[key].isOpen()) { - isOpen = true; - } - }); - - if (Object.keys(MenuDropdown).length !== 0 && MenuDropdown.isOpen()) { - isOpen = true; - } - - return isOpen; - }; + // Check if any menu instance is open. + const isAnyMenuOpen = () => keys.some((key) => AllElements[key].dataset && AllElements[key].isOpen()) || (Object.keys(MenuDropdown).length && MenuDropdown.isOpen()); + // Close all open menus on click outside. const closeFromOutside = ({ target }) => { - if (target.closest('.desktop-menu, .header-top') || target.closest('.header') === null) { + if (target.closest('.desktop-menu, .header-top') || !target.closest('.header')) { keys.forEach((key) => { AllElements[key].close(); }); - if (Object.keys(MenuDropdown).length !== 0) { + if (Object.keys(MenuDropdown).length) { MenuDropdown.close(); } open(); } }; - /** - * Blocks body scroll events when full screen menus are open. - * @param e - * @return boolean - */ - + // Prevent body scrolling when menus are open. const blockBrandingScroll = (e) => { - // gesture actions are excluded - if (e.touches && e.touches.length >1) { - return true; - } + // Ignore touch events. + if (e.touches?.length > 1) return true; const scrolledPanel = e.target.closest('.mmenu__panel--current, .nav-toggle-dropdown__content'); + + // Prevent scrolling when menu is open. const preventBodyScrolling = isMobile() && isAnyMenuOpen() && - // Don't scroll body from shared header - (e.target.closest('.nav-toggle-dropdown') === null || - // If element has no overflow, it has no overscroll containment. - // See overscroll-behavour CSS specs - (scrolledPanel !== null && !isScrollable(scrolledPanel))); + // Don't scroll body from shared header. + (!e.target.closest('.nav-toggle-dropdown') || + // If element has no overflow, it has no overscroll containment. + // See overscroll-behavour CSS specs. + (scrolledPanel && !isScrollable(scrolledPanel))); if (preventBodyScrolling) { e.preventDefault(); @@ -139,17 +114,14 @@ }; - /** - * Attach outside click listener to the whole header branding region area - * so that OtherLangs Menu and Mega menu - * can be closed when clicking outside of header branding region - */ - - // This used to load after DOM was loaded, but we added defer for the javascript. + // Attach outside click listener to the whole header branding region area, + // so that other languages menu and mega menu can be closed when clicking + // outside of header branding region. document.addEventListener('click', closeFromOutside); - // Prevent body scroll through shared header element when full screen menu is open. - const body = document.querySelector('body'); + // Prevent body scroll through shared header element when + // full screen menu is open. + const body = document.querySelector('body'); body.addEventListener('wheel', blockBrandingScroll, { passive: false }); body.addEventListener('scroll', blockBrandingScroll, { passive: false }); body.addEventListener('touchmove', blockBrandingScroll, { passive: false }); diff --git a/webpack.config.js b/webpack.config.js index bb3372485..2b76aa472 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -70,7 +70,6 @@ module.exports = (env, argv) => { }, output: { path: path.resolve(__dirname, 'dist'), - chunkFilename: 'js/async/[name].chunk.js', pathinfo: isDev, filename: 'js/[name].min.js', publicPath: 'auto', @@ -232,6 +231,7 @@ module.exports = (env, argv) => { mode: 'production', devtool: false, optimization: { + splitChunks: false, minimize: true, minimizer: [ new TerserPlugin({