PageSourceSearch

https://www.belladinotte.com/cdn/shop/t/2/assets/variant-picker.js?v=121949851136929086161784107014

js belladinotte.com collected 2026-10-08 09:47:29 UTC 7,580 bytes, 2 lines download raw bytes

1import{Component}from"@theme/component";import{VariantSelectedEvent,VariantUpdateEvent}from"@theme/events";import{morph}from"@theme/morph";export default class VariantPicker extends Component{static#NO_PRESELECT_SELECTOR="fieldset[data-no-preselect]";#pendingRequestUrl;#abortController;connectedCallback(){super.connectedCallback(),this.addEventListener("change",this.variantChanged.bind(this))}variantChanged(event){if(!(event.target instanceof HTMLElement))return;this.updateSelectedOption(event.target),this.dispatchEvent(new VariantSelectedEvent({id:event.target.dataset.optionValueId??""}));const isOnProductPage=Theme.template.name==="product"&&!event.target.closest("product-card")&&!event.target.closest("quick-add-dialog"),currentUrl=this.dataset.productUrl?.split("?")[0],newUrl=event.target.dataset.connectedProductUrl?.split("?")[0],loadsNewProduct=isOnProductPage&&!!newUrl&&newUrl!==currentUrl;this.fetchUpdatedSection(this.buildRequestUrl(event.target),loadsNewProduct);const url=new URL(window.location.href);isOnProductPage&&(event.target.dataset.variantId?url.searchParams.set("variant",event.target.dataset.variantId):url.searchParams.delete("variant")),loadsNewProduct&&(url.pathname=newUrl),url.href!==window.location.href&&history.replaceState({},"",url.toString())}updateSelectedOption(target){if(typeof target=="string"){const targetElement=this.querySelector(`[data-option-value-id="${target}"]`);if(!targetElement)throw new Error("Target element not found");target=targetElement}if(target instanceof HTMLInputElement&&(target.checked=!0),target instanceof HTMLSelectElement){const newValue=target.value,newSelectedOption=Array.from(target.options).find(option=>option.value===newValue);if(!newSelectedOption)throw new Error("Option not found");for(const option of target.options)option.removeAttribute("selected");newSelectedOption.setAttribute("selected","selected")}}buildRequestUrl(selectedOption,source=null,sourceSelectedOptionsValues=[]){let productUrl=(selectedOption.dataset.connectedProductUrl||this.#pendingRequestUrl||this.dataset.productUrl)?.split("?")[0];this.#pendingRequestUrl=productUrl;const params=[];return this.selectedOptionsValues.length&&!source&&!selectedOption.dataset.connectedProductUrl?params.push(`option_values=${this.selectedOptionsValues.join(",")}`):source==="product-card"&&(this.selectedOptionsValues.length?params.push(`option_values=${sourceSelectedOptionsValues.join(",")}`):params.push(`option_values=${selectedOption.dataset.optionValueId}`)),this.closest("quick-add-component")||this.closest("swatches-variant-picker-component")?`${productUrl}?section_id=section-rendering-product-card&${params.join("&")}`:`${productUrl}?${params.join("&")}`}fetchUpdatedSection(requestUrl,shouldMorphMain=!1){this.#abortController?.abort(),this.#abortController=new AbortController,fetch(requestUrl,{signal:this.#abortController.signal}).then(response=>response.text()).then(responseText=>{this.#pendingRequestUrl=void 0;const html=new DOMParser().parseFromString(responseText,"text/html"),textContent=html.querySelector('variant-picker script[type="application/json"]')?.textContent;if(textContent)if(shouldMorphMain)this.updateMain(html);else{const newProduct=this.updateVariantPicker(html);document.querySelector("product-price").innerHTML=html.querySelector("product-price").innerHTML,this.selectedOptionId&&this.dispatchEvent(new VariantUpdateEvent(JSON.parse(textContent),this.selectedOptionId,{html,productId:this.dataset.productId??"",newProduct,allOptionsSelected:this.allRequiredOptionsSelected}))}}).catch(error=>{error.name==="AbortError"?console.log("Fetch aborted by user"):console.error(error)})}updateVariantPicker(newHtml){let newProduct;const newVariantPickerSource=newHtml.querySelector(this.tagName.toLowerCase());if(!newVariantPickerSource)throw new Error("No new variant picker source found");if(newVariantPickerSource instanceof HTMLElement){const newProductId=newVariantPickerSource.dataset.productId,newProductUrl=newVariantPickerSource.dataset.productUrl;newProductId&&newProductUrl&&this.dataset.productId!==newProductId&&(newProduct={id:newProductId,url:newProductUrl}),this.dataset.productId=newProductId,this.dataset.productUrl=newProductUrl}const checkedIds=Array.from(this.querySelectorAll("fieldset input:checked")).map(el=>
1el.dataset.optionValueId).filter(Boolean);return newVariantPickerSource instanceof HTMLElement&&this.discardGuessedSelections(newVariantPickerSource,checkedIds),morph(this,newVariantPickerSource),checkedIds.forEach(id=>this.updateSelectedOption(id)),newProduct}discardGuessedSelections(root,checkedIds){root.querySelectorAll(VariantPicker.#NO_PRESELECT_SELECTOR).forEach(fieldset=>{const guessedInput=fieldset.querySelector("input:checked");if(!(guessedInput instanceof HTMLInputElement)||checkedIds.includes(guessedInput.dataset.optionValueId??""))return;guessedInput.removeAttribute("checked");const isDisabled=guessedInput.classList.contains("disabled"),unselectedInput=Array.from(fieldset.querySelectorAll("input")).find(input=>input!==guessedInput&&input.classList.contains("disabled")===isDisabled),guessedSwatch=guessedInput.nextElementSibling?.querySelector(".swatch-element"),unselectedSwatch=unselectedInput?.nextElementSibling?.querySelector(".swatch-element");guessedSwatch&&unselectedSwatch&&(guessedSwatch.className=unselectedSwatch.className);const selectedValueLabel=fieldset.querySelector("[data-selected-value]");selectedValueLabel&&(selectedValueLabel.textContent="")})}updateMain(newHtml){const main=document.querySelector("main"),newMain=newHtml.querySelector("main");if(!main||!newMain)throw new Error("No new main source found");const oldProductRecommendations=Array.from(main.querySelectorAll("product-recommendations")),oldProductIds=new Map;oldProductRecommendations.forEach(el=>{el.id&&el.dataset.productId&&oldProductIds.set(el.id,el.dataset.productId)}),morph(main,newMain),window.Alpine&&typeof Alpine.initTree=="function"&&Alpine.initTree(main),Array.from(main.querySelectorAll("product-recommendations")).forEach(el=>{if(!el.id||!el.dataset.productId)return;const oldProductId=oldProductIds.get(el.id),newProductId=el.dataset.productId;oldProductId&&oldProductId!==newProductId?(el.removeAttribute("data-recommendations-performed"),requestAnimationFrame(()=>{el.setAttribute("data-trigger-reload","true"),requestAnimationFrame(()=>{el.removeAttribute("data-trigger-reload")})})):!oldProductId&&el.dataset.recommendationsPerformed==="true"&&el.removeAttribute("data-recommendations-performed")})}get selectedOption(){const selectedOption=this.querySelector("select option[selected], fieldset input:checked");if(selectedOption instanceof HTMLInputElement||selectedOption instanceof HTMLOptionElement)return selectedOption}get selectedOptionId(){const{selectedOption}=this;if(!selectedOption)return;const{optionValueId}=selectedOption.dataset;if(!optionValueId)throw new Error("No option value ID found");return optionValueId}get selectedOptionsValues(){return Array.from(this.querySelectorAll("select option[selected], fieldset input:checked")).map(option=>{const{optionValueId}=option.dataset;if(!optionValueId)throw new Error("No option value ID found");return optionValueId})}get allRequiredOptionsSelected(){return Array.from(this.querySelectorAll(VariantPicker.#NO_PRESELECT_SELECTOR)).every(fieldset=>fieldset.querySelector("input:checked"))}}customElements.get("variant-picker")||customElements.define("variant-picker",VariantPicker);
2//# sourceMappingURL=/cdn/shop/t/2/assets/variant-picker.js.map?v=121949851136929086161784107014

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.