1(()=>{function moveSelectorIntoProductForm(){const parking=document.getElementById("avd-driver-selector-parking"),parkedSelector=parking?parking.querySelector("[data-avd-driver-selector]"):null;if(!parking||!parkedSelector)return;const hulkOptions=document.querySelector('[id^="hulkapps_custom_options_"]'),addButton=document.querySelector('button[name="add"], [id^="AddToCart-"]'),target=hulkOptions||addButton;!target||!target.parentNode||(target.parentNode.insertBefore(parkedSelector,target),parking.remove())}moveSelectorIntoProductForm();const selectorRoot=document.querySelector("[data-avd-driver-selector]");if(!selectorRoot)return;const productForm=selectorRoot.closest('form[action*="/cart/add"]')||document.querySelector('form[action*="/cart/add"]');if(!productForm)return;const routeRoot=window.Shopify&&window.Shopify.routes&&window.Shopify.routes.root?window.Shopify.routes.root:"/",addUrl=`${routeRoot}cart/add.js`,cartUrl=`${routeRoot}cart`,productCache={};function parseJsonAttribute(el,attrName){if(!el)return[];try{return JSON.parse(el.getAttribute(attrName)||"[]")}catch{return[]}}function formatMoney(cents){return cents=Number(cents||0),new Intl.NumberFormat("en-GB",{style:"currency",currency:"GBP"}).format(cents/100)}function isIncludedDriverOption(option){return option?option.value==="included"||option.value==="included-g10-vintage":!1}function getDriverSelects(){return Array.from(selectorRoot.querySelectorAll("[data-avd-driver-select]"))}function getSelectedDriverOptions(){return getDriverSelects().filter(select=>select.offsetParent!==null).map(select=>select.options[select.selectedIndex]).filter(Boolean)}function getCabVariantId(){const idInput=productForm.querySelector('[name="id"]');return idInput?idInput.value:null}function getQuantity(){const quantityInput=productForm.querySelector('[name="quantity"]'),quantity=quantityInput?parseInt(quantityInput.value,10):1;return Number.isFinite(quantity)&&quantity>0?quantity:1}function getSelectedCabOptions(){const formData=new FormData(productForm),options={};for(const[key,value]of formData.entries())(key.startsWith("options[")||key==="option1"||key==="option2"||key==="option3")&&(options[key]=value);return options}function buildPairId(){return`avd-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}function getCurrentCabVariant(){const cabVariantId=getCabVariantId();return parseJsonAttribute(selectorRoot,"data-cab-variants").find(variant=>String(variant.id)===String(cabVariantId))||null}function getCabVariantText(){const cabVariant=getCurrentCabVariant();return cabVariant?[cabVariant.title,cabVariant.option1,cabVariant.option2,cabVariant.option3].filter(Boolean).join(" ").toLowerCase():""}function getAllSelectedProductText(){let text=getCabVariantText();return document.querySelectorAll("select").forEach(select=>{if(select.closest("[data-avd-driver-selector]"))return;const selectedOption=select.options[select.selectedIndex];selectedOption&&(text+=" "+selectedOption.textContent,text+=" "+selectedOption.value)}),document.querySelectorAll('input[type="radio"]:checked').forEach(input=>{if(input.closest("[data-avd-driver-selector]"))return;text+=" "+input.value;const label=input.closest("label");label&&(text+=" "+label.textContent)}),text.toLowerCase().replace(/\s+/g," ").trim()}function getRequiredDriverSizes(){const configText=getCabVariantText().toLowerCase().replace(/\s+/g," ").trim().replace(/uk/g,"").replace(/usa/g,"").replace(/canada/g,"").replace(/europe/g,"").replace(/australia/g,"").replace(/new zealand/g,"").replace(/japan/g,"").replace(/rest of the world/g,"").replace(/rest of world/g,"").replace(/everywhere else/g,"").trim();return configText.includes("1215")||configText.includes("12/15")||configText.includes("12 15")?["12","15"]:configText.includes("2x10")||configText.includes("2 x 10")||configText.includes("210")||configText.includes("two 10")?["10","10"]:configText.includes("2x12")||configText.includes("2 x 12")||configText.includes("212")||configText.includes("two 8 ohm drivers")||configText.includes("two 16 ohm drivers")||configText.includes("two drivers")?["12","12"]:configText.includes("2x15")||configText.includes("2 x 15")||configText.includes("215")||configText.includes("two 15")?["15","15"]:configText.includes("1x10")||configText.includes("1 x 10")||configText.includes("110")?["10"]:configText.includes("1x15")||configText.includes("1 x 15")||configText.includes("115")?["15"]:configText.includes("1x12")||configText.includes("1 x 12")||configText.includes("112sw")||configText.includes("112 sw")||configText.includes("112")?["12"]:["12"]}function cabNeedsTwoDrivers(){return getRequiredDriverSizes().length>1}
1function getCabRegion(){const cabVariant=getCurrentCabVariant();if(!cabVariant)return"UK";const regionOption=[cabVariant.option1,cabVariant.option2,cabVariant.option3].filter(Boolean).find(option=>{const text=String(option).toLowerCase();return text==="uk"||text.includes("europe")||text.includes("usa")||text.includes("canada")||text.includes("australia")||text.includes("new zealand")||text.includes("japan")||text.includes("everywhere")||text.includes("rest of the world")||text.includes("rest of world")});return!regionOption||String(regionOption).toLowerCase()==="uk"?"UK":"Everywhere else"}function cabNeedsFourOhm(){const text=getCabVariantText().toLowerCase();return text.includes("4ohm")||text.includes("4 ohm")}async function getDriverProduct(handle){if(!handle)return null;if(Object.prototype.hasOwnProperty.call(productCache,handle))return productCache[handle];const urls=[`${routeRoot}products/${handle}.js`,`/products/${handle}.js`];for(const url of urls)try{const response=await fetch(url,{headers:{Accept:"application/json"}});if(response.ok){const product=await response.json();return productCache[handle]=product,product}console.warn("AVD driver product fetch failed:",handle,response.status,url)}catch(error){console.warn("AVD driver product fetch error:",handle,url,error)}return null}async function findMatchingDriverVariant(driverOption){if(!driverOption||isIncludedDriverOption(driverOption))return null;const handle=driverOption.dataset.driverProductHandle,product=await getDriverProduct(handle);if(!product||!product.variants||!product.variants.length)return null;const variants=product.variants,wantsUk=getCabRegion().toLowerCase().includes("uk"),wantsFourOhm=cabNeedsFourOhm();let candidates=variants.filter(variant=>{const title=String(variant.title||"").toLowerCase();return wantsUk?title.includes("uk"):title.includes("everywhere")||title.includes("europe")||title.includes("usa")||title.includes("canada")||title.includes("rest of world")||title.includes("rest of the world")||title.includes("non uk")||title.includes("non-uk")});candidates.length||(candidates=variants);let match=null;return wantsFourOhm&&(match=candidates.find(variant=>String(variant.title||"").toLowerCase().includes("4 ohm"))),match||(match=candidates.find(variant=>{const title=String(variant.title||"").toLowerCase();return title.includes("as chosen")||!title.includes("4 ohm")})),match||(match=candidates[0]),match}function updateVisibleDriverFields(){const requiredSizes=getRequiredDriverSizes();getDriverSelects().forEach((select,index)=>{const field=select.closest("[data-avd-driver-field]"),requiredSize=requiredSizes[index];if(field)if(requiredSize){field.style.display="",select.dataset.requiredDriverSize=requiredSize;const label=field.querySelector("label");label&&(requiredSizes.length>1?label.textContent=`Speaker / Driver ${index+1} (${requiredSize}")`:label.textContent=`Speaker / Driver (${requiredSize}")`)}else field.style.display="none",select.dataset.requiredDriverSize="",select.value="included"})}function filterDriverOptionsBySize(){const requiredSizes=getRequiredDriverSizes();getDriverSelects().forEach((select,index)=>{const requiredSize=requiredSizes[index]||requiredSizes[0]||"12",options=Array.from(select.options);options.forEach(option=>{const optionSize=option.dataset.driverSize||"12",shouldShow=optionSize===requiredSize||optionSize==="any";option.hidden=!shouldShow,option.disabled=!shouldShow});const selectedOption=select.options[select.selectedIndex];if(!(selectedOption&&!selectedOption.hidden&&!selectedOption.disabled)){let preferredIncludedOption=null;requiredSize==="10"?preferredIncludedOption=options.find(option=>option.value==="included-g10-vintage"):requiredSize==="12"&&(preferredIncludedOption=options.find(option=>option.value==="included"));const fallbackOption=options.find(option=>!option.hidden&&!option.disabled),optionToSelect=preferredIncludedOption&&!preferredIncludedOption.hidden&&!preferredIncludedOption.disabled?preferredIncludedOption:fallbackOption;optionToSelect&&(select.value=optionToSelect.value)}})}
1function findMainPriceEls(){const selectors=["[data-product-price]","[data-price]",".product__price",".product-price__price",".product-single__price",".product-single__prices",".price-item--regular",".price__regular .price-item",".ecom-product-single__price",".ecom-product-single__price-wrapper","#ProductPrice","#ProductPrice-product-template"],found=[];return selectors.forEach(selector=>{document.querySelectorAll(selector).forEach(el=>{if(selectorRoot.contains(el)||found.includes(el))return;const rect=el.getBoundingClientRect();rect.width>0&&rect.height>0&&found.push(el)})}),found.slice(0,3)}const mainPriceEls=findMainPriceEls();mainPriceEls.forEach(el=>{el.dataset.avdOriginalPriceHtml||(el.dataset.avdOriginalPriceHtml=el.innerHTML)});let updateToken=0;async function refreshDropdownOptionPrices(currentToken){filterDriverOptionsBySize();const selects=getDriverSelects();await Promise.all(selects.map(async select=>{const options=Array.from(select.options);await Promise.all(options.map(async option=>{const cleanBaseLabel=option.dataset.driverBaseLabel||option.dataset.driverLabel||option.value;if(option.textContent=cleanBaseLabel,option.hidden||option.disabled){option.dataset.driverPrice="0",option.dataset.driverVariantId="";return}if(isIncludedDriverOption(option)){option.textContent=`${cleanBaseLabel} \u2014 included`,option.dataset.driverPrice="0",option.dataset.driverVariantId="";return}const variant=await findMatchingDriverVariant(option);if(currentToken!==updateToken)return;if(!variant){option.textContent=`${cleanBaseLabel}`,option.dataset.driverPrice="0",option.dataset.driverVariantId="";return}const price=Number(variant.price||0);option.textContent=`${cleanBaseLabel} \u2014 +${formatMoney(price)}`,option.dataset.driverPrice=String(price),option.dataset.driverVariantId=String(variant.id)}))}))}async function updateDisplayedPrices(){const currentToken=++updateToken;if(updateVisibleDriverFields(),await refreshDropdownOptionPrices(currentToken),currentToken!==updateToken)return;const cabVariant=getCurrentCabVariant(),cabPrice=cabVariant?Number(cabVariant.price||0):0,selectedDriverOptions=getSelectedDriverOptions(),driverTotal=selectedDriverOptions.reduce((total,option)=>!option||isIncludedDriverOption(option)?total:total+Number(option.dataset.driverPrice||0),0),hasCustomDriver=selectedDriverOptions.some(option=>option&&!isIncludedDriverOption(option)&&option.dataset.driverVariantId),totalPrice=cabPrice+driverTotal;mainPriceEls.forEach(el=>
1{if(!hasCustomDriver)el.innerHTML=formatMoney(cabPrice);else{const speakerWord=cabNeedsTwoDrivers()?"speakers":"speaker";el.innerHTML=`${formatMoney(totalPrice)} <small style="font-size:0.65em;font-weight:normal;">with selected ${speakerWord}</small>`}})}selectorRoot.addEventListener("change",function(){updateDisplayedPrices()}),document.addEventListener("change",function(event){(event.target.matches('[name="id"]')||event.target.matches("select")||event.target.matches('input[type="radio"]'))&&(window.setTimeout(updateDisplayedPrices,100),window.setTimeout(updateDisplayedPrices,300))}),document.addEventListener("click",function(){window.setTimeout(updateDisplayedPrices,150)});function setLoading(isLoading){const submitButton=productForm.querySelector('[type="submit"], button[name="add"]');submitButton&&(isLoading?(submitButton.setAttribute("aria-busy","true"),submitButton.dataset.originalText=submitButton.textContent,submitButton.textContent="Adding\u2026",submitButton.disabled=!0):(submitButton.removeAttribute("aria-busy"),submitButton.dataset.originalText&&(submitButton.textContent=submitButton.dataset.originalText),submitButton.disabled=!1))}function showError(message){let errorEl=selectorRoot.querySelector("[data-avd-driver-error]");errorEl||(errorEl=document.createElement("p"),errorEl.className="avd-driver-selector__error",errorEl.setAttribute("data-avd-driver-error",""),selectorRoot.appendChild(errorEl)),errorEl.textContent=message}function clearError(){const errorEl=selectorRoot.querySelector("[data-avd-driver-error]");errorEl&&(errorEl.textContent="")}function groupDriverLineItems(selectedDriverOptions,quantity,driverPropertiesBase){const grouped={};return selectedDriverOptions.forEach((option,index)=>{if(!option||isIncludedDriverOption(option))return;const variantId=option.dataset.driverVariantId;if(!variantId)return;const label=option.dataset.driverLabel||"Custom driver",position=index+1;grouped[variantId]||(grouped[variantId]={id:Number(variantId),quantity:0,properties:{...driverPropertiesBase,"Speaker choice":label,"Driver position":`Driver ${position}`}}),grouped[variantId].quantity+=quantity}),Object.values(grouped)}productForm.addEventListener("submit",async function(event){await updateDisplayedPrices();const selectedDriverOptions=getSelectedDriverOptions();if(!selectedDriverOptions.some(option=>option&&!isIncludedDriverOption(option)&&option.dataset.driverVariantId))return;event.preventDefault(),event.stopImmediatePropagation(),clearError();const cabVariantId=getCabVariantId(),quantity=getQuantity();if(!cabVariantId){showError("Sorry, we could not identify the selected cab variant. Please refresh and try again.");return}const cabTitle=selectorRoot.dataset.productTitle||document.title,cabOptions=getSelectedCabOptions(),pairId=buildPairId(),cabProperties={"Speaker choice":selectedDriverOptions.map((option,index)=>{if(!option||isIncludedDriverOption(option)){const label=option&&option.dataset.driverBaseLabel?option.dataset.driverBaseLabel:"Included speaker";return`Driver ${index+1}: ${label}`}return`Driver ${index+1}: ${option.dataset.driverLabel||"Custom driver"}`}).join(" / "),"_AVD pair ID":pairId};Object.entries(cabOptions).forEach(([key,value])=>{cabProperties[key]=value});const driverPropertiesBase={"For cab":cabTitle,"_AVD pair ID":pairId};Object.entries(cabOptions).forEach(([key,value])=>{driverPropertiesBase[key]=value});const driverLineItems=groupDriverLineItems(selectedDriverOptions,quantity,driverPropertiesBase),payload={items:[{id:Number(cabVariantId),quantity,properties:cabProperties},...driverLineItems]};try{setLoading(!0);const response=await fetch(addUrl,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(payload)}),data=await response.json();if(!response.ok){const message=data&&data.description?data.description:"Sorry, something went wrong adding this cab and driver to your basket.";throw new Error(message)}window.location.href=cartUrl}catch(error){showError(error.message),setLoading(!1)}},!0),updateDisplayedPrices()})(); 2//# sourceMappingURL=/cdn/shop/t/16/assets/avd-driver-selector.js.map?v=4499088545204825661780491608
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.