1customElements.get("quick-order-list")||customElements.define("quick-order-list",class extends BulkAdd{cartUpdateUnsubscriber=void 0;hasPendingQuantityUpdate=!1;constructor(){super(),this.isListInsideModal=this.closest("bulk-modal"),this.stickyHeaderElement=document.querySelector("sticky-header"),this.stickyHeaderElement&&(this.stickyHeader={height:this.stickyHeaderElement.offsetHeight,type:`${this.stickyHeaderElement.getAttribute("data-sticky-type")}`}),this.totalBar=this.getTotalBar(),this.totalBar&&(this.totalBarPosition=window.innerHeight-this.totalBar.offsetHeight,this.handleResize=this.handleResize.bind(this),window.addEventListener("resize",this.handleResize)),this.querySelector("form").addEventListener("submit",event=>event.preventDefault())}connectedCallback(){this.cartUpdateUnsubscriber=subscribe(PUB_SUB_EVENTS.cartUpdate,async event=>{event.source!==this.id&&(this.toggleTableLoading(!0),await this.refresh(),this.toggleTableLoading(!1))}),this.initEventListeners()}disconnectedCallback(){this.cartUpdateUnsubscriber?.(),window.removeEventListener("resize",this.handleResize)}handleResize(){this.totalBarPosition=window.innerHeight-this.totalBar.offsetHeight,this.stickyHeader.height=this.stickyHeaderElement?this.stickyHeaderElement.offsetHeight:0}initEventListeners(){this.querySelectorAll(".pagination__item").forEach(link=>{link.addEventListener("click",async event=>{event.preventDefault(),event.stopPropagation();const url=new URL(event.currentTarget.href);this.toggleTableLoading(!0),await this.refresh(url.searchParams.get("page")||"1"),this.scrollTop(),this.toggleTableLoading(!1)})}),this.querySelector(".quick-order-list__contents").addEventListener("keyup",this.handleScrollIntoView.bind(this)),this.quickOrderListTable.addEventListener("keydown",this.handleSwitchVariantOnEnter.bind(this)),this.initVariantEventListeners()}initVariantEventListeners(){this.allInputsArray=Array.from(this.querySelectorAll('input[type="number"]')),this.querySelectorAll("quantity-input").forEach(qty=>{const debouncedOnChange=debounce(this.onChange.bind(this),BulkAdd.ASYNC_REQUEST_DELAY,!0);qty.addEventListener("change",event=>{this.hasPendingQuantityUpdate=!0,debouncedOnChange(event)})}),this.querySelectorAll(".quick-order-list-remove-button").forEach(button=>{button.addEventListener("click",event=>{event.preventDefault(),this.toggleLoading(!0),this.startQueue(button.dataset.index,0)})})}get currentPage(){return this.querySelector(".pagination-wrapper")?.dataset?.page??"1"}get cartVariantsForProduct(){return JSON.parse(this.querySelector("[data-cart-contents]")?.innerHTML||"[]")}onChange(event){const inputValue=parseInt(event.target.value);this.cleanErrorMessageOnType(event),inputValue==0?(event.target.setAttribute("value",inputValue),this.startQueue(event.target.dataset.index,inputValue)):this.validateQuantity(event)}cleanErrorMessageOnType(event){const handleKeydown=()=>{event.target.setCustomValidity(" "),event.target.reportValidity(),event.target.removeEventListener("keydown",handleKeydown)};event.target.addEventListener("keydown",handleKeydown)}validateInput(target){const targetValue=parseInt(target.value),targetMin=parseInt(target.dataset.min),targetStep=parseInt(target.step);return target.max?targetValue==0||targetValue>=targetMin&&targetValue<=parseInt(target.max)&&targetValue%targetStep==0:targetValue==0||targetValue>=targetMin&&targetValue%targetStep==0}get quickOrderListTable(){return this.querySelector(".quick-order-list__table")}getSectionsToRender(){return[{id:this.id,section:this.dataset.section,selector:`#${this.id}`},{id:"cart-icon-bubble",section:"cart-icon-bubble",selector:"#shopify-section-cart-icon-bubble"},{id:`quick-order-list-live-region-text-${this.dataset.productId}`,section:"cart-live-region-text",selector:".shopify-section"},{id:"CartDrawer",selector:".drawer__inner",section:"cart-drawer"}]}toggleTableLoading(enable){this.quickOrderListTable.classList.toggle("quick-order-list__container--disabled",enable),this.toggleLoading(enable)}async refresh(pageNumber=null){const url=this.dataset.url||window.location.pathname;return fetch(`${url}?section_id=${this.dataset.section}&page=${pageNumber||this.currentPage}`).then(response=>response.text()).then(responseText=>{const responseQuickOrderList=new DOMParser().parseFromString(responseText,"text/html").querySelector(`#${this.id}`);responseQuickOrderList&&(this.innerHTML=responseQuickOrderList.innerHTML,this.initEventListeners())}).catch(e=>{console.error(e)})}renderSections(parsedState){const{items,sections}=parsedState;
1this.getSectionsToRender().forEach(({id,selector,section})=>{const sectionElement=document.getElementById(id);if(!sectionElement)return;const newSection=new DOMParser().parseFromString(sections[section],"text/html").querySelector(selector);if(section===this.dataset.section){if(this.queue.length>0||this.hasPendingQuantityUpdate)return;const focusedElement=document.activeElement;let focusTarget=focusedElement?.dataset?.target;focusTarget?.includes("remove")&&(focusTarget=focusedElement.closest("quantity-popover")?.querySelector('[data-target*="increment-"]')?.dataset.target);const total=this.getTotalBar();total&&(total.innerHTML=newSection.querySelector(".quick-order-list__total").innerHTML);const table=this.quickOrderListTable,newTable=newSection.querySelector(".quick-order-list__table"),shouldUpdateVariants=this.currentPage===(newSection.querySelector(".pagination-wrapper")?.dataset.page??"1");if(newTable&&shouldUpdateVariants){table.innerHTML=newTable.innerHTML;const newFocusTarget=this.querySelector(`[data-target='${focusTarget}']`);newFocusTarget&&newFocusTarget?.focus({preventScroll:!0}),this.initVariantEventListeners()}}else section==="cart-drawer"?(sectionElement.closest("cart-drawer")?.classList.toggle("is-empty",items.length===0),sectionElement.querySelector(selector).innerHTML=newSection.innerHTML):sectionElement.innerHTML=newSection.innerHTML})}getTotalBar(){return this.querySelector(".quick-order-list__total")}scrollTop(){const{top}=this.getBoundingClientRect();this.isListInsideModal?this.scrollIntoView():window.scrollTo({top:top+window.scrollY-(this.stickyHeader?.height||0),behavior:"instant"})}scrollQuickOrderListTable(target){const inputTopBorder=target.getBoundingClientRect().top,inputBottomBorder=target.getBoundingClientRect().bottom;if(this.isListInsideModal){const totalBarCrossesInput=inputBottomBorder>this.totalBar.getBoundingClientRect().top,tableHeadCrossesInput=inputTopBorder<this.querySelector(".quick-order-list__table thead").getBoundingClientRect().bottom;(totalBarCrossesInput||tableHeadCrossesInput)&&this.scrollToCenter(target)}else{const stickyHeaderBottomBorder=this.stickyHeaderElement?.getBoundingClientRect().bottom,totalBarCrossesInput=inputBottomBorder>this.totalBarPosition,inputOutsideOfViewPort=inputBottomBorder<this.querySelector(".variant-item__quantity-wrapper").offsetHeight,stickyHeaderCrossesInput=this.stickyHeaderElement&&this.stickyHeader.type!=="on-scroll-up"&&this.stickyHeader.height>inputTopBorder,stickyHeaderScrollupCrossesInput=this.stickyHeaderElement&&this.stickyHeader.type==="on-scroll-up"&&this.stickyHeader.height>inputTopBorder&&stickyHeaderBottomBorder>0;(totalBarCrossesInput||inputOutsideOfViewPort||stickyHeaderCrossesInput||stickyHeaderScrollupCrossesInput)&&this.scrollToCenter(target)}}scrollToCenter(target){target.scrollIntoView({block:"center",behavior:"smooth"})}handleScrollIntoView(event){(event.key==="Tab"||event.key==="Enter")&&this.allInputsArray.length!==1&&this.scrollQuickOrderListTable(event.target)}handleSwitchVariantOnEnter(event){if(event.key!=="Enter"||event.target.tagName!=="INPUT"||(event.preventDefault(),event.target.blur(),!this.validateInput(event.target)||this.allInputsArray.length<=1))return;const currentIndex=this.allInputsArray.indexOf(event.target),offset=event.shiftKey?-1:1,nextIndex=(currentIndex+offset+this.allInputsArray.length)%this.allInputsArray.length;this.allInputsArray[nextIndex]?.select()}updateMultipleQty(items){this.queue.length==0&&(this.hasPendingQuantityUpdate=!1),this.toggleLoading(!0);const url=this.dataset.url||window.location.pathname,body=JSON.stringify({updates:items,sections:this.getSectionsToRender().map(({section})=>section),sections_url:`${url}?page=${this.currentPage}`});this.updateMessage(),this.setErrorMessage(),fetch(`${routes.cart_update_url}`,{...fetchConfig(),body}).then(response=>response.text()).then(async state=>{const parsedState=JSON.parse(state);this.renderSections(parsedState),publish(PUB_SUB_EVENTS.cartUpdate,{source:this.id,cartData:parsedState})}).catch(e=>{console.error(e),this.setErrorMessage(window.cartStrings.error)}).finally(()=>{this.queue.length===0&&this.toggleLoading(!1),this.setRequestStarted(!1)})}setErrorMessage(message=null){this.errorMessageTemplate=this.errorMessageTemplate??document.getElementById(`QuickOrderListErrorTemplate-${this.dataset.productId}`).cloneNode(!0),document.querySelectorAll(".quick-order-list-error").forEach(errorElement=>{if(errorElement.innerHTML="",!message)return;const updatedMessageElement=this.errorMessageTemplate.cloneNode(!0);updatedMessageElement.content.querySelector(".quick-order-list-error-message").innerText=message,errorElement.appendChild(updatedMessageElement.content)})}updateMessage(quantity=null){const messages=this.querySelectorAll(".quick-order-list__message-text"),icons=this.querySelectorAll(".quick-order-list__message-icon");
1if(quantity===null||isNaN(quantity)){messages.forEach(message=>message.innerHTML=""),icons.forEach(icon=>icon.classList.add("hidden"));return}const isQuantityNegative=quantity<0,absQuantity=Math.abs(quantity),textTemplate=isQuantityNegative?absQuantity===1?window.quickOrderListStrings.itemRemoved:window.quickOrderListStrings.itemsRemoved:quantity===1?window.quickOrderListStrings.itemAdded:window.quickOrderListStrings.itemsAdded;messages.forEach(msg=>msg.innerHTML=textTemplate.replace("[quantity]",absQuantity)),isQuantityNegative||icons.forEach(i=>i.classList.remove("hidden"))}updateError(updatedValue,id){let message="";typeof updatedValue>"u"?message=window.cartStrings.error:message=window.cartStrings.quantityError.replace("[quantity]",updatedValue),this.updateLiveRegions(id,message)}updateLiveRegions(id,message){const variantItemErrorDesktop=document.getElementById(`Quick-order-list-item-error-desktop-${id}`);variantItemErrorDesktop&&(variantItemErrorDesktop.querySelector(".variant-item__error-text").innerHTML=message,variantItemErrorDesktop.closest("tr").classList.remove("hidden")),variantItemErrorMobile&&(variantItemErrorMobile.querySelector(".variant-item__error-text").innerHTML=message),this.querySelector("#shopping-cart-variant-item-status").setAttribute("aria-hidden",!0);const cartStatus=document.getElementById("quick-order-list-live-region-text");cartStatus.setAttribute("aria-hidden",!1),setTimeout(()=>{cartStatus.setAttribute("aria-hidden",!0)},1e3)}toggleLoading(loading,target=this){target.querySelector("#shopping-cart-variant-item-status").toggleAttribute("aria-hidden",!loading),target.querySelectorAll(".variant-remove-total .loading__spinner")?.forEach(spinner=>spinner.classList.toggle("hidden",!loading))}}),customElements.get("quick-order-list-remove-all-button")||customElements.define("quick-order-list-remove-all-button",class extends HTMLElement{constructor(){super(),this.quickOrderList=this.closest("quick-order-list"),this.actions={confirm:"confirm",remove:"remove",cancel:"cancel"},this.addEventListener("click",event=>{if(event.preventDefault(),this.dataset.action===this.actions.confirm)this.toggleConfirmation(!1,!0);else if(this.dataset.action===this.actions.remove){const items=this.quickOrderList.cartVariantsForProduct.reduce((acc,variantId)=>({...acc,[variantId]:0}),{});this.quickOrderList.updateMultipleQty(items),this.toggleConfirmation(!0,!1)}else this.dataset.action===this.actions.cancel&&this.toggleConfirmation(!0,!1)})}toggleConfirmation(showConfirmation,showInfo){this.quickOrderList.querySelector(".quick-order-list-total__confirmation").classList.toggle("hidden",showConfirmation),this.quickOrderList.querySelector(".quick-order-list-total__info").classList.toggle("hidden",showInfo)}}); 2//# sourceMappingURL=/cdn/shop/t/36/assets/quick-order-list.js.map?v=178437612139447569671762223854
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.