@paroicms/public-menu-plugin
Version:
Public menu plugin for ParoiCMS
1 lines • 1.89 kB
JavaScript
import{insert as e,template as t}from"https://cdn.jsdelivr.net/npm/solid-js@1.9.12/web/+esm";import n from"https://cdn.jsdelivr.net/npm/@paroicms/tiny-modal@0.8.6/+esm";function r(e){let t=e.dataset.activateMenuItems?.trim();if(!t)return;let{id:n,parents:r}=JSON.parse(t),i=new Set(r);i.add(n);let a=e.querySelectorAll("[data-menu-item-id]");for(let e of a){let t=e.dataset.menuItemId;t!==void 0&&i.has(t)&&e.classList.add("active")}}var i=t("<div class=PaMobileMenu>"),a=t('<button class=PaMobileMenuButton type=button><svg xmlns=http://www.w3.org/2000/svg viewBox="0 0 24 24"fill=currentColor width=35 height=35><title>BurgerIcon</title><path d="M4 18h16c.55 0 1-.45 1-1s-.45-1-1-1H4c-.55 0-1 .45-1 1s.45 1 1 1zm0-5h16c.55 0 1-.45 1-1s-.45-1-1-1H4c-.55 0-1 .45-1 1s.45 1 1 1zM3 7c0 .55.45 1 1 1h16c.55 0 1-.45 1-1s-.45-1-1-1H4c-.55 0-1 .45-1 1z">');function o(t,r){if(!window.matchMedia("(max-width: 992px)").matches)return;let o=document.querySelector('[data-mobile-menu="button"]');if(!o)return;s(t);let c=(()=>{var n=i();return e(n,t),n})();t.style.display==="none"&&t.style.removeProperty("display");let l=a();o.appendChild(l);let u=n({openButton:l,dialogContent:c,modalClass:"_paMobileMenu",loadCss:!0});c.addEventListener("click",e=>{e.target.closest("a")&&u.close()}),window.paMobileMenu=u}function s(e){let t=document.querySelectorAll("[data-mobile-menu-part]");for(let n of t){let t=n.dataset.mobileMenuPart,r=n.dataset.mobileMenuAction!=="move",i=e.querySelector(`[data-inject="${t}"]`);i&&(i.appendChild(r?n.cloneNode(!0):n),n.removeAttribute("data-mobile-menu-action"))}}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",c):c();function c(){let e=document.documentElement.lang,t=document.querySelectorAll("[data-effect='paMobileMenu']");for(let n of t)o(n,{language:e});let n=document.querySelectorAll("[data-activate-menu-items]");for(let e of n)r(e)}