rumine-web/static/wagtailadmin/js/userbar.f7b6eb92f71b.js

1 line
6.2 KiB
JavaScript
Raw Permalink Normal View History

2024-03-13 07:49:06 +01:00
(()=>{"use strict";var e,t={4917:(e,t,r)=>{var o=r(9115),n=r.n(o),i=r(6599),a=r(5069),s=r(859),l=r(9633);class d extends HTMLElement{connectedCallback(){const e=document.querySelector("#wagtail-userbar-template");if(!e)return;const t=this.attachShadow({mode:"open"});t.appendChild(e.content.firstElementChild.cloneNode(!0)),e.remove();const r=t.querySelector("[data-wagtail-userbar]"),o=r?.querySelector("[data-wagtail-userbar-trigger]"),n=r?.querySelector("[role=menu]");if(!r||!o||!n)return;const i=n.querySelectorAll("li"),a="w-userbar--active";this.trigger=o,r.style.display="none";const s=e=>{r.classList.add(a),o.setAttribute("aria-expanded","true"),n.addEventListener("click",p,!1),window.addEventListener("click",f,!1),r.addEventListener("keydown",w,!1),e&&n.querySelector("a[href],\n button:not([disabled]),\n input:not([disabled])")&&setTimeout((()=>{u()}),300)},l=()=>{r.classList.remove(a),o.setAttribute("aria-expanded","false"),n.addEventListener("click",p,!1),window.removeEventListener("click",f,!1),r.removeEventListener("keydown",w,!1)},d=()=>{i.forEach((e=>{e.firstElementChild.tabIndex=-1}))},c=e=>{d(),e.tabIndex=0,setTimeout((()=>{e.focus()}),100)},u=()=>{i.length>0&&c(i[0].firstElementChild)},h=()=>{i.length>0&&c(i[i.length-1].firstElementChild)},w=e=>{if("true"===o.getAttribute("aria-expanded")){if("Escape"===e.key)return l(),o&&(setTimeout((()=>o.focus()),300),d()),!1;if(t.activeElement&&t.activeElement.closest(".w-userbar-nav"))switch(e.key){case"ArrowDown":return e.preventDefault(),i.forEach(((e,r)=>{e.firstElementChild===t.activeElement&&(r+1<i.length?c(i[r+1].firstElementChild):u())})),!1;case"ArrowUp":return e.preventDefault(),i.forEach(((e,r)=>{e.firstElementChild===t.activeElement&&(r>0?c(i[r-1].firstElementChild):h())})),!1;case"Home":return e.preventDefault(),u(),!1;case"End":return e.preventDefault(),h(),!1}}return!0},p=e=>{e.stopPropagation()},f=()=>{l()};o.addEventListener("click",(e=>{e.stopPropagation(),r.classList.contains(a)?l():s(!0)}),!1),window.addEventListener("pageshow",l,!1),r.addEventListener("keydown",(e=>{if(o===document.activeElement&&"false"===o.getAttribute("aria-expanded"))switch(e.key){case"ArrowUp":e.preventDefault(),s(!1),setTimeout((()=>h()),300);break;case"ArrowDown":e.preventDefault(),s(!1),setTimeout((()=>u()),300)}})),n.addEventListener("focusout",(e=>{e.relatedTarget&&!e.relatedTarget.closest(".w-userbar-nav")&&(d(),l())})),d(),document.addEventListener("DOMContentLoaded",(async()=>{await this.initialiseAxe()}))}async initialiseAxe(){const e=this.shadowRoot?.getElementById("accessibility-trigger"),t=(0,a.Ac)(this.shadowRoot);if(!this.shadowRoot||!e||!t)return;const r=await n().run(t.context,t.options),o=r.violations.reduce(((e,t)=>e+t.nodes.length),0);if(r.violations.length){const e=document.createElement("span");e.textContent=String(o),e.classList.add("w-userbar-axe-count"),this.trigger.appendChild(e)}const d=i.Application.start(this.shadowRoot.firstElementChild);d.register("w-dialog",s.Y),d.register("w-teleport",l.y);const c=new Promise((e=>{this.shadowRoot?.addEventListener("w-dialog:ready",(({detail:t})=>{const{body:r,dialog:o}=t;e({body:r,dialog:o})}),{once:!0,passive:!0})})),{body:u,dialog:h}=await c,w=this.shadowRoot.querySelector("#accessibility-results"),p=this.shadowRoot.querySelector("#w-a11y-result-row-template"),f=this.shadowRoot.querySelector("#w-a11y-result-selector-template"),g=this.shadowRoot.querySelector("#w-a11y-result-outline-template");if(!(w&&p&&f&&g))return;this.shadowRoot.querySelectorAll("[data-a11y-result-count]").forEach((e=>{e.textContent=String(o)||"0",e.classList.toggle("has-errors",r.violations.length>0)}));const v=e=>{const t=document.querySelector(e),r=this.shadowRoot?.querySelector("[data-a11y-result-outline-container]");r?.firstElementChild&&r.removeChild(r.firstElementChild),r?.appendChild(g.content.cloneNode(!0));const o=this.shadowRoot?.querySelector("[data-a11y-result-outline]");if(!(this.shadowRoot&&t&&o&&r))return;const n=()=>{const e=t.getBoundingClientRect();o.style.cssText=`\n top: ${e.height<5?e.top+window.scrollY-2.5