1class CustomSelect extends HTMLElement{static get observedAttributes(){return["selected"]}constructor(){super(),this.referenceElement=document.getElementById(this.dataset.referenceId),this.currentLabel=this.querySelector("[ custom-select-current]"),this.mainTrigger=this.querySelector("[custom-select-trigger]")}connectedCallback(){this.init()}disconectedCallback(){}attributeChangedCallback(name,oldValue,newValue){const onChangeEvent=new CustomEvent("wtSelectChange",{detail:{prevValue:oldValue,value:newValue}});this.dispatchEvent(onChangeEvent)}getFocusableElements(){const focusableElementsSelector="[role='option']",focusableElements=()=>Array.from(this.querySelectorAll(focusableElementsSelector)).filter(el=>!el.hasAttribute("disabled")&&el.tabIndex>=0);return{focusableElements,first:focusableElements()[0],last:focusableElements()[focusableElements().length-1]}}setSelectedLabel(){const selectedLabel=this.querySelector("[custom-select-list] [selected]")?.textContent;this.setAttribute("selected-label",selectedLabel),this.currentLabel.textContent=selectedLabel}getAttrVal(attr,elem){return elem.hasAttribute(attr)?elem.getAttribute(attr):null}unselectAll(){this.querySelectorAll("[custom-select-list] li").forEach(item=>item.removeAttribute("selected"))}onSelect(val,elem){this.unselectAll(),this.setAttribute("selected",val),elem.setAttribute("selected",""),this.setSelectedLabel(),this.updateReferenceValue(),this.toggleState()}createOverlay(){if(!document.querySelector("[custom-select-overlay]")){const overlay=document.createElement("div");overlay.setAttribute("custom-select-overlay",""),document.body.appendChild(overlay),overlay.addEventListener("click",()=>this.toggleState())}}handleClick(e){const clickedElem=e.target;(clickedElem.hasAttribute("custom-select-drawer")||clickedElem===this||clickedElem.classList.contains("wt-options__close"))&&this.toggleState(),this.getAttrVal("value",clickedElem)&&this.onSelect(this.getAttrVal("value",e.target),clickedElem)}init(){this.createOverlay(),this.mainTrigger.addEventListener("click",()=>this.toggleState()),this.addEventListener("keydown",e=>{const isTabPressed=e.key==="Tab"||e.keyCode===9||e.code==="Tab",{first,last}=this.getFocusableElements();(e.key==="Escape"||e.keyCode===27||e.code==="Escape")&&this.hasAttribute("open")&&this.toggleState(),isTabPressed&&this.hasAttribute("open")&&(e.shiftKey&&document.activeElement===first?(last.focus(),e.preventDefault()):!e.shiftKey&&document.activeElement===last&&(first.focus(),e.preventDefault()))}),this.addEventListener("click",this.handleClick),this.setSelectedLabel()}updateReferenceValue(){this.referenceElement.value=this.getAttribute("selected");const inputEvent=new Event("input",{bubbles:!0,cancelable:!0});this.referenceElement.dispatchEvent(inputEvent)}toggleState(){const body=document.body,openBodyAttr="custom-select-opened",header=document.querySelector("header.page-header"),liItems=this.querySelectorAll("li"),trigger=this.querySelector("[custom-select-trigger]"),isOpen=trigger.getAttribute("aria-expanded")==="true";if(trigger.setAttribute("aria-expanded",!isOpen),this.hasAttribute("open")){this.removeAttribute("open"),body.removeAttribute(openBodyAttr),body.classList.contains("page-header-sticky")&&header.classList.remove("hide");for(const item of liItems)item.setAttribute("tabindex","-1");this.mainTrigger.focus()}else{this.setAttribute("open",""),body.setAttribute(openBodyAttr,""),body.classList.contains("page-header-sticky")&&header.classList.add("hide");for(const item of liItems)item.setAttribute("tabindex","0");window.matchMedia("(max-width: 1199px)").matches&&this.querySelector("[custom-select-list] [selected]").focus()}}}customElements.define("custom-select",CustomSelect); 2//# sourceMappingURL=/cdn/shop/t/6/assets/custom-select.js.map?v=65733485544084563901757377856
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.