1const HB_GALLERY_PREFETCH_DWELL_MS=90,HB_GALLERY_MAX_CONCURRENT_PREFETCH=2,hbVariantGalleryCache={pdp:new Map,quickview:new Map},hbVariantGalleryPending={pdp:new Map,quickview:new Map};let hbGalleryPrefetchInFlight=0;const getVariantGalleryScope=element=>{const quickModal=element?.closest?.("quick-add-modal")||element?.closest?.(".quick-add-modal");return quickModal?{key:"quickview",root:quickModal,container:document.getElementById("product-gallery-container--quickview"),templateSuffix:"--quickview",productInfo:quickModal.querySelector("product-info")}:{key:"pdp",root:document.querySelector(".main-product"),container:document.getElementById("product-gallery-container"),templateSuffix:"",productInfo:document.querySelector("product-info[data-url]")}},getVariantIdFromSwatch=(swatch,isDropDown)=>swatch?isDropDown?swatch.dataset?.id||null:swatch.closest(".swatch-input__label__wrapper")?.querySelector("input")?.dataset?.variantId||null:null,buildVariantGalleryUrls=(variantId,scope)=>{const productUrl=(scope.productInfo?.dataset?.url||"").split("?")[0];if(!productUrl)return[];const id=encodeURIComponent(variantId),urls=[];if(scope.key==="quickview")return urls.push(`${productUrl}?view=quick-view&variant=${id}§ion_id=quick-view&hb_gallery=1`),urls.push(`${productUrl}?view=quick-view&variant=${id}§ion_id=quick-view`),urls.push(`${productUrl}?view=quick-view&variant=${id}`),urls;const sectionId=scope.productInfo?.dataset?.section;return sectionId?(urls.push(`${productUrl}?variant=${id}§ion_id=${encodeURIComponent(sectionId)}&hb_gallery=1`),urls.push(`${productUrl}?variant=${id}§ion_id=${encodeURIComponent(sectionId)}`)):urls.push(`${productUrl}?variant=${id}`),urls},extractVariantGallery=(html,variantId)=>{const doc=new DOMParser().parseFromString(html,"text/html"),gallery=Array.from(doc.querySelectorAll("#product-gallery-container .variant-gallery")).find(candidate=>candidate.dataset.variantId===String(variantId))||null;return gallery?document.importNode(gallery,!0):null},HB_GALLERY_BACKOFF_MS=6e4,HB_GALLERY_FAILED_TTL_MS=3e4;let hbGalleryBackoffUntil=0;const hbGalleryFailedAt=new Map,galleryBackgroundAllowed=()=>Date.now()>=hbGalleryBackoffUntil,noteGalleryFailure=key=>hbGalleryFailedAt.set(String(key),Date.now()),recentlyFailed=key=>Date.now()-(hbGalleryFailedAt.get(String(key))||0)<HB_GALLERY_FAILED_TTL_MS,fetchVariantGallery=async(variantId,scope,priority="auto")=>{const urls=buildVariantGalleryUrls(variantId,scope);for(const url of urls)try{const response=await fetch(url,{credentials:"same-origin",priority});if((response.status===429||response.status>=500)&&(hbGalleryBackoffUntil=Date.now()+HB_GALLERY_BACKOFF_MS),!response.ok)continue;const gallery=extractVariantGallery(await response.text(),variantId);if(gallery)return gallery}catch{}return null},getCachedVariantGallery=(variantId,scope)=>{const cached=hbVariantGalleryCache[scope.key].get(String(variantId));return cached?cached.cloneNode(!0):null},getTemplateVariantGallery=(variantId,scope)=>{const gallery=document.getElementById(`gallery-template-${variantId}${scope.templateSuffix}`)?.content?.querySelector?.(".variant-gallery");return gallery?gallery.cloneNode(!0):null},requestVariantGallery=(variantId,scope,priority="auto")=>{const key=String(variantId),pending=hbVariantGalleryPending[scope.key];if(pending.has(key))return pending.get(key);const promise=fetchVariantGallery(variantId,scope,priority).then(gallery=>(gallery?hbVariantGalleryCache[scope.key].set(key,gallery):noteGalleryFailure(key),gallery)).finally(()=>{pending.delete(key)});return pending.set(key,promise),promise},prefetchVariantGallery=(variantId,scope)=>{if(!variantId||!scope.container)return;const key=String(variantId);hbVariantGalleryCache[scope.key].has(key)||hbVariantGalleryPending[scope.key].has(key)||getTemplateVariantGallery(variantId,scope)||scope.container.querySelector(".variant-gallery")?.dataset.variantId!==key&&(hbGalleryPrefetchInFlight>=2||!galleryBackgroundAllowed()||recentlyFailed(key)||(hbGalleryPrefetchInFlight+=1,requestVariantGallery(variantId,scope,"low").finally(()=>{hbGalleryPrefetchInFlight-=1})))},HB_GALLERY_WARMUP_CONCURRENCY=2,HB_GALLERY_WARMUP_MAX=8,hbGalleryWarmupStarted={pdp:!1,quickview:!1},collectScopeVariantIds=scope=>{const root=scope.root||document,ids=[],push=id=>{id&&!ids.includes(String(id))&&ids.push(String(id))};return root.querySelectorAll(".custom-option[data-id]").forEach(option=>push(option.dataset.id)),root.querySelectorAll(".swatch-input__label__wrapper input[data-variant-id]").forEach(input=>push(input.dataset.variantId)),ids.slice(0,HB_GALLERY_WARMUP_MAX)},connectionAllowsWarmup=()=>{const connection=navigator.connection;return connection?connection.saveData?!1:!/(^|-)2g$/.test(connection.effectiveType||""):!0},warmVariantGalleries=async scope=>{if(!scope.container||hbGalleryWarmupStarted[scope.key]||(hbGalleryWarmupStarted[scope.key]=!0,!connectionAllowsWarmup()))return;const current=scope.container.querySelector(".variant-gallery")?.dataset.variantId,queue=collectScopeVariantIds(scope).filter(id=>
1id!==current&&!hbVariantGalleryCache[scope.key].has(id)&&!getTemplateVariantGallery(id,scope));if(!queue.length)return;const worker=async()=>{for(;queue.length;){if(!galleryBackgroundAllowed())return;const id=queue.shift();hbVariantGalleryCache[scope.key].has(id)||recentlyFailed(id)||await requestVariantGallery(id,scope,"low").catch(()=>null)}};await Promise.all(Array.from({length:HB_GALLERY_WARMUP_CONCURRENCY},worker))},whenIdleAfterLoad=(callback,delay)=>{const run=()=>{"requestIdleCallback"in window?window.requestIdleCallback(callback,{timeout:3e3}):window.setTimeout(callback,delay)};document.readyState==="complete"?window.setTimeout(run,delay):window.addEventListener("load",()=>window.setTimeout(run,delay),{once:!0})},applyVariantGallery=(gallery,scope)=>{const container=scope.container;if(!container||!gallery)return;const current=container.querySelector(".variant-gallery");if(current){const currentId=current.dataset.variantId;currentId&&!hbVariantGalleryCache[scope.key].has(currentId)&&hbVariantGalleryCache[scope.key].set(currentId,current.cloneNode(!0)),current.remove()}container.appendChild(gallery),typeof applyThumbnailSliderEnhancements=="function"&&applyThumbnailSliderEnhancements(gallery),typeof applyProductMediaEnhancements=="function"&&applyProductMediaEnhancements(gallery)},updateGalleryImages=async(swatch,isDropDown,element)=>{const swatchId=getVariantIdFromSwatch(swatch,isDropDown);if(!swatchId)return;const scope=getVariantGalleryScope(swatch),container=scope.container;if(!container||(container.dataset.hbPendingVariant=String(swatchId),container.querySelector(".variant-gallery")?.dataset.variantId===String(swatchId)))return;let gallery=getTemplateVariantGallery(swatchId,scope)||getCachedVariantGallery(swatchId,scope);if(!gallery){container.setAttribute("aria-busy","true");try{const requestedGallery=await requestVariantGallery(swatchId,scope,"high");gallery=requestedGallery?requestedGallery.cloneNode(!0):null}finally{container.dataset.hbPendingVariant===String(swatchId)&&container.removeAttribute("aria-busy")}}gallery&&container.dataset.hbPendingVariant===String(swatchId)&&applyVariantGallery(gallery,scope)},resolvePrefetchTarget=node=>{const el=node?.nodeType===1?node:node?.parentElement;if(!el||el.closest(".main-product")?.dataset?.is_bundled?.trim()==="true")return null;const option=el.closest(".custom-option");if(option)return option.closest(".main-product, .add-to-cart-panel, quick-add-modal, .quick-add-modal")?{variantId:getVariantIdFromSwatch(option,!0),scope:getVariantGalleryScope(option)}:null;const swatch=el.closest(".swatch");return swatch&&swatch.closest(".main-product, quick-add-modal, .quick-add-modal")?{variantId:getVariantIdFromSwatch(swatch,!1),scope:getVariantGalleryScope(swatch)}:null},installVariantGalleryPrefetch=()=>{if(window.__hbVariantGalleryPrefetchInstalled)return;window.__hbVariantGalleryPrefetchInstalled=!0;const timers=new WeakMap;document.addEventListener("pointerover",event=>{const target=resolvePrefetchTarget(event.target);if(!target?.variantId)return;const anchor=event.target.closest(".custom-option, .swatch");if(!anchor||timers.has(anchor))return;const timer=window.setTimeout(()=>{timers.delete(anchor),prefetchVariantGallery(target.variantId,target.scope)},90);timers.set(anchor,timer),anchor.addEventListener("pointerout",()=>{const pendingTimer=timers.get(anchor);pendingTimer&&(window.clearTimeout(pendingTimer),timers.delete(anchor))},{once:!0})},{passive:!0}),document.addEventListener("focusin",event=>{const target=resolvePrefetchTarget(event.target);target?.variantId&&prefetchVariantGallery(target.variantId,target.scope)},{passive:!0}),document.addEventListener("touchstart",event=>{const target=resolvePrefetchTarget(event.target);target?.variantId&&prefetchVariantGallery(target.variantId,target.scope)},{passive:!0})};document.addEventListener("DOMContentLoaded",function(){const mainProduct=document.querySelector(".main-product"),mainImage=mainProduct?.querySelector(".product__modal-opener");mainImage&&new MutationObserver(()=>{applyGalleryChange()}).observe(mainImage,{childList:!0,subtree:!0}
1),mainProduct&&(applyGalleryChange(),mainProduct.dataset?.is_bundled?.trim()!=="true"&&whenIdleAfterLoad(()=>warmVariantGalleries(getVariantGalleryScope(mainProduct)),800)),installVariantGalleryPrefetch()});const applyGalleryChange=()=>{const mainProduct=document.querySelector(".main-product"),stickyPanel=document.querySelector(".add-to-cart-panel"),swatches=mainProduct.querySelectorAll(".swatch"),options=mainProduct.querySelectorAll(".custom-option"),stickyOptions=stickyPanel?.querySelectorAll(".custom-option");mainProduct?.dataset?.is_bundled?.trim()=="true"||(swatches?.forEach(swatch=>{swatch.addEventListener("click",()=>{updateGalleryImages(swatch,!1,mainProduct)})}),options?.forEach(swatch=>{swatch.addEventListener("click",()=>{updateGalleryImages(swatch,!0,mainProduct)})}),stickyOptions?.forEach(swatch=>{swatch.addEventListener("click",()=>{updateGalleryImages(swatch,!0,mainProduct)})}))},applyQuickViewGalleryChange=quickViewModal=>{const mainProduct=quickViewModal.querySelector(".main-product"),swatches=quickViewModal.querySelectorAll(".swatch"),options=quickViewModal.querySelectorAll(".custom-option"),is_bundled=mainProduct?.dataset?.is_bundled?.trim()=="true";is_bundled||(swatches?.forEach(swatch=>{swatch.addEventListener("click",()=>{updateGalleryImages(swatch,!1,mainProduct)})}),options?.forEach(swatch=>{swatch.addEventListener("click",()=>{updateGalleryImages(swatch,!0,mainProduct)})})),installVariantGalleryPrefetch(),is_bundled||(hbGalleryWarmupStarted.quickview=!1,hbVariantGalleryCache.quickview.clear(),window.setTimeout(()=>warmVariantGalleries(getVariantGalleryScope(quickViewModal)),600))}; 2//# sourceMappingURL=/cdn/shop/t/339/assets/product-variants-gallery.js.map?v=145418877073708910171790669444
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.