1(function(){"use strict";var CONFIG={variantChangeEvent:"variant:change",addToCartSelector:".add-to-cart",cartFormSelector:'form[action*="/cart/add"]',afterAddDispatch:function(cart,form,btn){form.dispatchEvent(new CustomEvent("ajaxProduct:added",{detail:{product:cart,addToCartBtn:btn},bubbles:!0})),document.dispatchEvent(new Event("ajaxProduct:added")),document.dispatchEvent(new CustomEvent("cart:updated",{detail:{cart:cart}}))},onError:function(data,form){form.dispatchEvent(new CustomEvent("ajaxProduct:error",{detail:{error:data},bubbles:!0})),console.error("[variant-add-on] \u52A0\u8D2D\u5931\u8D25",data)},mainItemPropertyName:"_\u30B5\u30FC\u30D3\u30B9",priceSuffix:"\uFF08\u7A0E\u8FBC\uFF09"};function shopRoot(){return window.Shopify&&Shopify.routes&&Shopify.routes.root||"/"}function initBlock(root){if(root.__vaoInit)return;root.__vaoInit=!0;var dataEl=root.querySelector("[data-variant-add-on-data]"),select=root.querySelector("[data-variant-add-on-select]");if(!dataEl||!select)return;var map={};try{map=JSON.parse(dataEl.textContent||"{}")}catch(e){map={}}var placeholder=select.getAttribute("data-placeholder")||"",form=root.closest(CONFIG.cartFormSelector)||document.querySelector(CONFIG.cartFormSelector);function currentVariantId(){var master=form&&form.querySelector('[name="id"]');return master&&master.value?String(master.value):root.getAttribute("data-default-variant")||""}function render(variantId){var list=map[String(variantId)]||[],prev=select.value;select.innerHTML="";var opt0=document.createElement("option");opt0.value="",opt0.textContent=placeholder,select.appendChild(opt0),list.forEach(function(item){var o=document.createElement("option");o.value=String(item.id),o.setAttribute("data-label",item.label||""),o.textContent=(item.name||item.label)+(item.price?" \uFF0B "+item.price+CONFIG.priceSuffix:""),item.available===!1&&(o.disabled=!0),select.appendChild(o)}),prev&&list.some(function(i){return String(i.id)===prev})&&(select.value=prev),root.style.display=list.length?"":"none"}render(currentVariantId()),document.addEventListener(CONFIG.variantChangeEvent,function(e){var v=e.detail&&e.detail.variant;render(v?v.id:"")})}function gatherProperties(form){var props={};return form.querySelectorAll('[name^="properties["]').forEach(function(el){if(!((el.type==="checkbox"||el.type==="radio")&&!el.checked)&&!(el.value===""||el.value==null)){var name=el.getAttribute("name"),key=name.slice(name.indexOf("[")+1,name.lastIndexOf("]"));props[key]=el.value}}),props}function selectedAddOns(scope){var seen={},out=[];return scope.querySelectorAll("[data-variant-add-on-select]").forEach(function(sel){if(sel.value&&!seen[sel.value]){seen[sel.value]=!0;var opt=sel.options[sel.selectedIndex];out.push({id:parseInt(sel.value,10),label:opt?opt.getAttribute("data-label")||opt.textContent.trim():""})}}),out}function onAddToCart(e){var btn=e.target.closest(CONFIG.addToCartSelector);if(btn){var form=btn.closest(CONFIG.cartFormSelector)||document.querySelector(CONFIG.cartFormSelector);if(form){var idField=form.querySelector('[name="id"]'),mainId=idField&&idField.value;if(mainId){e.preventDefault(),e.stopImmediatePropagation();var qtyField=form.querySelector('[name="quantity"]'),qty=qtyField&&parseInt(qtyField.value,10)||1,properties=gatherProperties(form),scope=form.closest('[id^="shopify-section"]')||form.closest("section")||document,addOns=selectedAddOns(scope),items=[];addOns.forEach(function(a){items.push({id:a.id,quantity:qty})}),addOns.length&&CONFIG.mainItemPropertyName&&(properties[CONFIG.mainItemPropertyName]=addOns.map(function(a){return a.label}).join(" / "));var mainItem={id:parseInt(mainId,10),quantity:qty};Object.keys(properties).length&&(mainItem.properties=properties);var sp=form.querySelector('[name="selling_plan"]');sp&&sp.value&&(mainItem.selling_plan=sp.value),items.push(mainItem),btn.classList.add("btn--loading"),fetch(shopRoot()+"cart/add.js",{method:"POST",headers:{"Content-Type":"application/json","X-Requested-With":"XMLHttpRequest"},body:JSON.stringify({items:items})}).then(function(r){return r.json().then(function(d){return{ok:r.ok,data:d}})}).then(function(res){if(btn.classList.remove("btn--loading"),!res.ok||res.data&&res.data.status>=400){CONFIG.onError(res.data,form);return}return fetch(shopRoot()+"cart.js",{headers:{"X-Requested-With":"XMLHttpRequest"}}).then(function(r){return r.json()}
1).then(function(cart){CONFIG.afterAddDispatch(cart,form,btn)})}).catch(function(err){btn.classList.remove("btn--loading"),console.error("[variant-add-on] \u7F51\u7EDC\u9519\u8BEF",err)})}}}}function openModal(modal){modal&&(modal.hidden=!1,modal.setAttribute("aria-hidden","false"),document.body.classList.add("variant-add-on--modal-open"))}function closeModal(modal){modal&&(modal.hidden=!0,modal.setAttribute("aria-hidden","true"),document.body.classList.remove("variant-add-on--modal-open"))}function modalFor(trigger){if(trigger.__vaoModal)return trigger.__vaoModal;var block=trigger.closest("[data-variant-add-on]"),modal=block&&block.querySelector("[data-variant-add-on-modal]");return modal&&modal.parentNode!==document.body&&document.body.appendChild(modal),trigger.__vaoModal=modal,modal}function onModalClick(e){var trigger=e.target.closest("[data-variant-add-on-info]");if(trigger){e.preventDefault(),openModal(modalFor(trigger));return}var closer=e.target.closest("[data-variant-add-on-modal-close]");closer&&(e.preventDefault(),closeModal(closer.closest("[data-variant-add-on-modal]")))}function onModalKey(e){if(e.key==="Escape"){document.querySelectorAll("[data-variant-add-on-modal]:not([hidden])").forEach(closeModal);return}if(e.key==="Enter"||e.key===" "||e.key==="Spacebar"){var trigger=e.target.closest&&e.target.closest("[data-variant-add-on-info]");trigger&&(e.preventDefault(),openModal(modalFor(trigger)))}}function boot(){document.querySelectorAll("[data-variant-add-on]").forEach(initBlock),window.__variantAddOnBound||(window.__variantAddOnBound=!0,document.addEventListener("click",onAddToCart,!0),document.addEventListener("click",onModalClick,!1),document.addEventListener("keydown",onModalKey,!1))}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",boot):boot()})(); 2//# sourceMappingURL=/cdn/shop/t/2/assets/variant-add-on.js.map?v=101196344937121915081786689506
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.