PageSourceSearch

https://tryguys.com/cdn/shop/t/15/assets/component-filtering.js?v=96551305552662564561746490188

js tryguys.com collected 2026-10-02 03:30:52 UTC 18,089 bytes, 2 lines download raw bytes

1(()=>{"use strict";function throttle(callback,interval){let enableCall=!0,calledWhenDisabled=!1;return(...args)=>{const onTimeout=()=>{calledWhenDisabled?(callback.apply(this,args),setTimeout(onTimeout,interval)):enableCall=!0,calledWhenDisabled=!1};if(!enableCall){calledWhenDisabled=!0;return}enableCall=!1,callback.apply(this,args),setTimeout(onTimeout,interval)}}function formatMoney(cents,format){var moneyFormat=format||"${{amount}}";typeof cents=="string"&&(cents=cents.replace(".",""));var value="",placeholderRegex=/\{\{\s*(\w+)\s*\}\}/,formatString=moneyFormat;function formatWithDelimiters(number,precision,thousands,decimal){if(precision==null&&(precision=2),thousands=thousands||",",decimal=decimal||".",isNaN(number)||number==null)return"0";number=(number/100).toFixed(precision);var parts=number.split("."),dollarsAmount=parts[0].replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+thousands),centsAmount=parts[1]?decimal+parts[1]:"";return dollarsAmount+centsAmount}var match=formatString.match(placeholderRegex);if(!match)throw new Error(`Invalid format string: '${formatString}'. Expected '{{amount}}' or similar placeholders.`);switch(match[1]){case"amount":value=formatWithDelimiters(cents,2);break;case"amount_no_decimals":value=formatWithDelimiters(cents,0);break;case"amount_with_comma_separator":value=formatWithDelimiters(cents,2,".",",");break;case"amount_with_space_separator":value=formatWithDelimiters(cents,2," ",",");break;case"amount_no_decimals_with_comma_separator":value=formatWithDelimiters(cents,0,".",",");break;case"amount_no_decimals_with_space_separator":value=formatWithDelimiters(cents,0," ");break;default:throw new Error(`Unknown format type: ${match[1]}`)}return formatString.replace(placeholderRegex,value)}class FocusTrap{constructor(container,initialElement=null,onEscape=null){this.container=container,this.initialElement=initialElement,this.onEscape=onEscape,this.focusableElements=[],this.firstElement=null,this.lastElement=null,this.handleKeyDown=this.handleKeyDown.bind(this),this.updateFocusableElements=this.updateFocusableElements.bind(this),this.observer=new MutationObserver(this.updateFocusableElements),this.init()}init(){this.container&&(this.container.removeAttribute("inert"),this.updateFocusableElements(),this.initialElement&&this.isFocusable(this.initialElement)?this.initialElement.focus():this.firstElement&&this.firstElement.focus(),this.container.addEventListener("keydown",this.handleKeyDown),this.observer.observe(this.container,{childList:!0,subtree:!0,attributes:!0}))}isFocusable(el){return el?el.offsetParent!==null&&el.getAttribute("tabindex")!=="-1"&&!this.isInsideClosedDetails(el):!1}isInsideClosedDetails(el){let parent=el.parentElement;for(;parent;){if(parent.tagName.toLowerCase()==="details"&&!parent.hasAttribute("open"))return!(el.tagName.toLowerCase()==="summary"&&parent.querySelector("summary")===el);parent=parent.parentElement}return!1}updateFocusableElements(){this.focusableElements=Array.from(this.container.querySelectorAll('a[href], area[href], input:not([type=hidden]), select, textarea, button:not([disabled]), iframe, object, embed, [tabindex]:not([tabindex="-1"]), [contenteditable], summary')).filter(el=>this.isFocusable(el)),this.focusableElements.length>0?(this.firstElement=this.focusableElements[0],this.lastElement=this.focusableElements[this.focusableElements.length-1]):(this.firstElement=null,this.lastElement=null,console.warn("No focusable elements found within the container."))}handleKeyDown(e){if(e.key==="Tab"){if(this.focusableElements.length===0){e.preventDefault();return}e.shiftKey?document.activeElement===this.firstElement&&(e.preventDefault(),this.lastElement.focus()):document.activeElement===this.lastElement&&(e.preventDefault(),this.firstElement.focus())}else e.key==="Escape"&&this.onEscape&&this.onEscape()}destroy(){this.container.setAttribute("inert",""),this.container.removeEventListener("keydown",this.handleKeyDown),this.observer.disconnect()}}class CollectionFiltersForm extends HTMLElement{handleSortByChangeBound=this.handleSortByChange.bind(this);stopInputPropagationBound=this.stopInputPropagation.bind(this);constructor(){super(),this.filterData=[],this.onActiveFilterClick=this.onActiveFilterClick.bind(this),this.productGridId="CollectionProductGrid",this.filterFormsId="CollectionFiltersForm",this.searchTemplate=document.querySelector("body.template-search"),this.collectionTemplate=document.querySelector("body.template-collection"),this.sections=this.getSections(),this.buttonAriaLabel=this.getAttribute("data-button-aria-label"),this.filterForm=this.querySelector(`#${this.filterFormsId}`),this.sortByDesktop=this.querySelector("#SortBydesktop"),this.sortByMobile=this.querySelector("#SortBymobile"),this.sortByInput=this.querySelector("#sort_by_input"),this.prevWindowWidth=window.innerWidth,this.resizeThreshold=100,window.innerWidth<=991?document.body.classList.contains("js-drawer-open-filter")||this.filterForm.setAttribute("inert",""):this.filterForm.removeAttribute("inert"),this.debouncedOnSubmit=this.debounce(this.onSubmitHandler.bind(this),800),this.handleResize=this.handleResize.bind(this),this.sortByDesktop&&this.sortByMobile&&(this.sortByDesktop.addEventListener("change",this.handleSortByChangeBound),this.sortByMobile.addEventListener("change",this.handleSortByChangeBound),this.sortByDesktop.addEventListener("input",this.stopInputPropagationBound),this.sortByMobile.addEventListener("input",this.stopInputPropagationBound)),this.querySelector("form").addEventListener("input",this.debouncedOnSubmit),document.querySelector("[data-drawer-open-btn]").addEventListener("click",this.handleDrawerOpen.bind(this)),document.querySelector("[data-drawer-close-btn]").addEventListener("click",this.handleDrawerClose.bind(this));const drawerOverlay=document.querySelector("[data-filtering-drawer-overlay]");drawerOverlay&&drawerOverlay.addEventListener("click",this.handleDrawerClose.bind(this)),window.addEventListener("resize",this.handleResize),window.addEventListener("popstate",this.onHistoryChange.bind(this)),this.bindActiveFacetButtonEvents(),this.onDropDownBlur()}debounce=(fn,wait)=>{let timeout;return(...args)=>{clearTimeout(timeout),timeout=setTimeout(()=>fn(...args),wait)}};stopInputPropagation(event){event.stopPropagation()}onDropDownBlur(){const getDropDowns=document.querySelectorAll("details");for(let item of getDropDowns)document.addEventListener("click",function(event){var isCl
1ickInside=item.contains(event.target);isClickInside||item.removeAttribute("open")})}isHidden(el){return el.offsetParent===null}handleResize(){const currentWidth=window.innerWidth,widthDiff=Math.abs(currentWidth-this.prevWindowWidth),crossedBreakpoint=this.prevWindowWidth<=991&&currentWidth>991||this.prevWindowWidth>991&&currentWidth<=991;if(widthDiff>this.resizeThreshold||crossedBreakpoint){this.prevWindowWidth=currentWidth;const filterDrawer=document.querySelector("collection-filtering-form");if(!filterDrawer)return;filterDrawer.removeAttribute("role"),filterDrawer.removeAttribute("aria-modal"),filterDrawer.removeAttribute("aria-label"),currentWidth<=991?(document.body.classList.contains("js-drawer-open-filter")||this.filterForm.setAttribute("inert",""),filterDrawer.setAttribute("role","dialog"),filterDrawer.setAttribute("aria-modal","true"),filterDrawer.setAttribute("aria-label",this.buttonAriaLabel)):this.filterForm.removeAttribute("inert")}}handleDrawerOpen(){const filterDrawer=this.querySelector("#CollectionFiltersForm");window.innerWidth<=991&&this.filterForm&&this.filterForm.removeAttribute("inert"),document.body.classList.add("js-drawer-open-filter","js-drawer-open"),this.focusTrap=new FocusTrap(filterDrawer,null,this.handleDrawerClose.bind(this))}handleDrawerClose(){const filterBtn=document.querySelector("[data-drawer-open-btn]");document.body.classList.remove("js-drawer-open-filter","js-drawer-open"),window.innerWidth<=991&&this.filterForm&&this.filterForm.setAttribute("inert",""),filterBtn.setAttribute("tabIndex","0"),filterBtn.focus(),this.focusTrap&&(this.focusTrap.destroy(),this.focusTrap=null)}handleSortByChange(event){event.preventDefault(),event.stopPropagation();const newValue=event.target.value;if(!this.sortByInput){console.warn("Sort by input element not found");return}this.sortByInput.value=newValue,event.target===this.sortByDesktop?this.sortByMobile.value!==newValue&&(this.sortByMobile.value=newValue):event.target===this.sortByMobile&&this.sortByDesktop.value!==newValue&&(this.sortByDesktop.value=newValue),this.sortByInput.dispatchEvent(new Event("input",{bubbles:!0}))}onSubmitHandler(event){event.preventDefault();const processForm=(formData,uniqueFormData)=>{let priceGte=null,priceLte=null;event.target&&event.target.matches("input[data-price-range-min]")?priceGte=event.target.value:event.target&&event.target.matches("input[data-price-range-max]")&&(priceLte=event.target.value);const paramMap=new Map;for(const[key,value]of formData.entries())value!==""&&(paramMap.has(key)||paramMap.set(key,new Set),paramMap.get(key).add(value));event.target?.type==="checkbox"&&!event.target.checked&&paramMap.has(event.target.name)&&(paramMap.get(event.target.name).delete(event.target.value),paramMap.get(event.target.name).size===0&&paramMap.delete(event.target.name)),priceGte!==null&&(paramMap.set("filter.v.price.gte",new Set([priceGte])),this.filterForm.querySelectorAll("input[data-price-range-min]").forEach(input=>input.value=priceGte)),priceLte!==null&&(paramMap.set("filter.v.price.lte",new Set([priceLte])),this.filterForm.querySelectorAll("input[data-price-range-max]").forEach(input=>input.value=priceLte));for(const[key,values]of paramMap.entries())uniqueFormData.delete(key),values.forEach(value=>{uniqueFormData.append(key,value)})};if(this.collectionTemplate){const formData=new FormData(this.filterForm),uniqueFormData=new URLSearchParams;processForm(formData,uniqueFormData);const searchParams=uniqueFormData.toString();this.renderPage(searchParams,event)}else if(this.searchTemplate){const searchParamsInitial=new URLSearchParams(window.location.search),activeTypes=document.querySelector("#page-type-input").value,types=Array.from(activeTypes.split(",")),defaultTypes=document.querySelector('.search--header input[name="type"]');if(activeTypes===""){const getInput=document.querySelector("#page-type-input");getInput.value=defaultTypes.value}const formData=new FormData(this.filterForm),uniqueFormData=new URLSearchParams;if(processForm(formData,uniqueFormData),uniqueFormData.append("q",searchParamsInitial.get("q")),types.includes("article")&&!types.includes("product")||types.includes("page")&&!types.includes("product")){const getInputs=document.querySelectorAll(`#${this.filterFormsId} input:not(#page-type-input)`),getLabels=document.querySelectorAll(`#${this.filterFormsId} label:not(.collection-filters__label)`);for(let item of getInputs)item.setAttribute("disabled","disabled");for(let inputLabel of getLabels)inputLabel.classList.add("facet-checkbox--disabled");searchParamsInitial.has("filter.p.product_type")&&uniqueFormData.delete("filter.p.product_type"),searchParamsInitial.has("filter.p.vendor")&&uniqueFormData.delete("filter.p.vendor"),searchParamsInitial.has("filter.v.availability")&&uniqueFormData.delete("filter.v.availability"),searchParamsInitial.has("filter.v.price.gte")&&uniqueFormData.delete("filter.v.price.gte"),searchParamsInitial.has("filter.v.price.lte")&&uniqueFormData.delete("filter.v.price.lte")}else{const getInputs=document.querySelectorAll(`#${this.filterFormsId} input:not(#page-type-input)`),getLabels=document.querySelectorAll(`#${this.filterFormsId} label:not(.collection-filters__label)`);for(let item of getInputs)item.removeAttribute("disabled");for(let inputLabel of getLabels)inputLabel.classList.remove("facet-checkbox--disabled")}const searchParams=uniqueFormData.toString();this.renderPage(searchParams,event)}}onActiveFilterClick(event){event.preventDefault(),event.currentTarget.setAttribute("loading","true"),this.toggleActiveFacets(),(event.currentTarget.classList.contains("price-filter-reset")||event.currentTarget.classList.contains("js-clear-all-filters"))&&(this.filterForm.querySelectorAll("input[data-price-range-min]").forEach(input=>input.value=""),this.filterForm.querySelectorAll("input[data-price-range-max]").forEach(input=>input.value="")),this.renderPage(new URL(event.currentTarget.href).searchParams.toString())}onHistoryChange(event){const searchParams=event.state?.searchParams||"";this.renderPage(searchParams,null,!1)}toggleActiveFacets(disable=!0){document.querySelectorAll(".js-facet-remove").forEach(element=>{element.classList.toggle("disabled",disable)})}renderPage(searchParams,event,updateURLHash=!0){document.querySelector(`#${this.productGridId}>div`).classList.add("loading"),this.sections.forEach(section=>{if(this.collectionTemplate){const url=`${window.location.pathname}?section_id=${section.section}&${searchParams}`,filterDataUrl=element=>element.url===url;
1this.filterData.some(filterDataUrl)?this.renderSectionFromCache(filterDataUrl,section,event):this.renderSectionFromFetch(url,section,event)}else if(this.searchTemplate){const url=`${window.location.pathname}?${searchParams}`,filterDataUrl=element=>element.url===url;this.filterData.some(filterDataUrl)?this.renderSectionFromCache(filterDataUrl,section,event):this.renderSectionFromFetch(url,section,event)}}),updateURLHash&&this.updateURLHash(searchParams)}renderSectionFromFetch(url,section,event){fetch(url).then(response=>response.text()).then(responseText=>{const html=responseText;switch(this.filterData=[...this.filterData,{html,url}],section.id){case this.productGridId:this.renderProductGrid(html);break;case this.filterFormsId:this.renderFilters(html,event);break;default:return}})}renderSectionFromCache(filterDataUrl,section,event){const cachedData=this.filterData.find(filterDataUrl);if(!cachedData)return;const html=cachedData.html;this.renderFilters(html,event),this.renderProductGrid(html)}renderProductGrid(html){const innerHTML=new DOMParser().parseFromString(html,"text/html").getElementById(this.productGridId).innerHTML;document.getElementById(this.productGridId).innerHTML=innerHTML,window.scrollBy(0,1),window.scrollBy(0,-1);const event=new CustomEvent("paginate");document.dispatchEvent(event)}renderFilters(html){new DOMParser().parseFromString(html,"text/html").querySelectorAll("[data-filter-update]").forEach(newElement=>{const targetElement=document.querySelector(`[data-filter-update="${newElement.getAttribute("data-filter-update")}"]`);targetElement&&(targetElement.innerHTML=newElement.innerHTML)}),this.bindSortByEventListeners(),this.bindActiveFacetButtonEvents()}bindSortByEventListeners(){this.sortByDesktop=this.querySelector("#SortBydesktop"),this.sortByMobile=this.querySelector("#SortBymobile"),this.sortByDesktop&&this.sortByMobile&&(this.sortByDesktop.removeEventListener("change",this.handleSortByChangeBound),this.sortByMobile.removeEventListener("change",this.handleSortByChangeBound),this.sortByDesktop.removeEventListener("input",this.stopInputPropagationBound),this.sortByMobile.removeEventListener("input",this.stopInputPropagationBound),this.sortByDesktop.addEventListener("change",this.handleSortByChangeBound),this.sortByMobile.addEventListener("change",this.handleSortByChangeBound),this.sortByDesktop.addEventListener("input",this.stopInputPropagationBound),this.sortByMobile.addEventListener("input",this.stopInputPropagationBound))}bindActiveFacetButtonEvents(){document.querySelectorAll(".js-facet-remove").forEach(element=>{element.removeEventListener("click",this.onActiveFilterClick),element.addEventListener("click",this.onActiveFilterClick,{once:!0})})}updateURLHash(searchParams){history.pushState({searchParams},"",`${window.location.pathname}${searchParams?"?".concat(searchParams):""}`)}getSections(){return[{id:this.productGridId,section:document.getElementById(this.productGridId).dataset.sectionId},{id:this.filterFormsId,section:document.getElementById("main-collection-filters").dataset.id}]}disconnectedCallback(){window.removeEventListener("resize",this.handleResize),window.removeEventListener("popstate",this.onHistoryChange.bind(this))}}customElements.define("collection-filtering-form",CollectionFiltersForm);class PriceRange extends HTMLElement{constructor(){super(),this.querySelectorAll("input").forEach(element=>{element.addEventListener("change",this.onRangeChange.bind(this)),element.addEventListener("keydown",this.onKeyDown.bind(this))}),this.setMinAndMaxValues()}onRangeChange(event){this.adjustToValidValues(event.currentTarget),this.setMinAndMaxValues()}onKeyDown(event){if(event.metaKey)return;const pattern=/[0-9]|\.|,|'| |Tab|Backspace|Enter|ArrowUp|ArrowDown|ArrowLeft|ArrowRight|Delete|Escape/;event.key.match(pattern)||event.preventDefault()}setMinAndMaxValues(){const inputs=this.querySelectorAll("input"),minInput=inputs[0],maxInput=inputs[1];maxInput.value&&minInput.setAttribute("data-max",maxInput.value),minInput.value&&maxInput.setAttribute("data-min",minInput.value),minInput.value===""&&maxInput.setAttribute("data-min",0),maxInput.value===""&&minInput.setAttribute("data-max",maxInput.getAttribute("data-max"))}adjustToValidValues(input){const value=Number(input.value),min=Number(input.getAttribute("data-min")),max=Number(input.getAttribute("data-max"));value<min&&(input.value=min),value>max&&(input.value=max)}}customElements.define("price-range-selector",PriceRange);class PageType extends HTMLElement{constructor(){super(),this.selector=document.querySelector("[data-page-type-selector]"),this.selector.addEventListener("change",this.setValue)}setValue(e){const selectedTypes=e.currentTarget.querySelectorAll("input:checked"),types=Array.from(selectedTypes).map(option=>
1option.value).join(","),typeInput=document.querySelector("#page-type-input");typeInput.value=types;const event=new Event("input");typeInput.closest("form").dispatchEvent(event)}}customElements.define("page-type-selector",PageType)})();
2//# sourceMappingURL=/cdn/shop/t/15/assets/component-filtering.js.map?v=96551305552662564561746490188

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.