1(function(root){"use strict";const FAC_BASE_SELECTOR='input[data-fac-is-base="1"][data-fac-cart-group-id]',quantityTimers=new WeakMap;function itemProperties(item){return item&&item.properties&&typeof item.properties=="object"?item.properties:{}}function buildFacRemoveUpdates(cart,removeData){const items=Array.isArray(cart?.items)?cart.items:[],key=String(removeData?.key||""),line=Number.parseInt(removeData?.line,10),clickedItem=items.find(item=>key&&item.key===key)||items[line-1],properties=itemProperties(clickedItem);if(properties._fac_is_base!=="1"||!properties._fac_cart_group_id)return null;const groupId=properties._fac_cart_group_id,updates=items.map(item=>{const candidateProperties=itemProperties(item),isSameGroup=candidateProperties._fac_cart_group_id===groupId,isBase=candidateProperties._fac_is_base==="1",isSurcharge=candidateProperties._fac_is_surcharge==="1";return isSameGroup&&(isBase||isSurcharge)?0:item.quantity});return updates.some((quantity,index)=>quantity===0&&items[index].quantity!==0)?updates:null}function cartSurface(element){const container=element?.closest?.("theme-cart, cart-drawer");return container?{container,origin:container.matches("cart-drawer")?"cart-drawer":"cart-page"}:null}function sectionsForOrigin(origin){return origin==="cart-drawer"?["cart-drawer","cart-bubble"]:["main-cart","cart-drawer","cart-bubble"]}function sectionTargets(){return{"main-cart":{id:"Cart",selector:".thb-cart-form"},"cart-drawer":{id:"Cart-Drawer",selector:".cart-drawer"},"cart-bubble":{id:"cart-drawer-toggle",selector:".thb-item-count"}}}
1function renderSections(sections,names){if(!sections||typeof DOMParser>"u")return;const targets=sectionTargets();names.forEach(name=>{const html=sections[name],target=targets[name],rootElement=target&&document.getElementById(target.id);if(!html||!target||!rootElement)return;const sourceElement=new DOMParser().parseFromString(html,"text/html").querySelector(target.selector),destination=rootElement.matches?.(target.selector)?rootElement:rootElement.querySelector(target.selector)||rootElement;sourceElement&&destination&&(destination.innerHTML=sourceElement.innerHTML)})}function dispatchLineEvent(name,quantity,cart){if(typeof root.dispatchCustomEvent=="function"){root.dispatchCustomEvent(name,{quantity,cart});return}document.dispatchEvent(new CustomEvent(name,{detail:{quantity,cart}}))}function showQuantityError(surface,input,error){console.error("[FAC_CART] Failed to update FAC cart group quantity",error),typeof surface.container.displayErrors=="function"&&surface.container.displayErrors(input.dataset.line||input.dataset.index,error instanceof Error?error.message:"Die Menge konnte nicht aktualisiert werden. Bitte versuche es erneut.")}async function updateFacQuantity(surface,input){const updateService=root.FacDynamicPricingCartUpdate;if(!updateService||typeof updateService.updateQuantity!="function"){showQuantityError(surface,input,new Error("Die Menge konnte nicht aktualisiert werden. Bitte versuche es erneut."));return}const line=input.dataset.line||input.dataset.index,loadingItem=surface.container.querySelector(surface.origin==="cart-drawer"?`#CartDrawerItem-${line}`:`#CartItem-${line}`);loadingItem?.classList.add(surface.origin==="cart-drawer"?"thb-loading":"loading");try{dispatchLineEvent("line-item:change:start",input.value);const result=await updateService.updateQuantity({origin:surface.origin,cartGroupId:input.dataset.facCartGroupId,baseKey:input.dataset.key,quantity:input.value});if(result.ignored)return;dispatchLineEvent("line-item:change:end",input.value,result.cart)}catch(error){showQuantityError(surface,input,error)}finally{loadingItem?.classList.remove(surface.origin==="cart-drawer"?"thb-loading":"loading")}}function handleQuantityChange(event){const input=event.target;if(!input?.matches?.(FAC_BASE_SELECTOR))return;const surface=cartSurface(input);surface&&(event.stopImmediatePropagation(),root.FacDynamicPricingCartUpdate?.markPending?.(),clearTimeout(quantityTimers.get(surface.container)),quantityTimers.set(surface.container,setTimeout(()=>{updateFacQuantity(surface,input)},300)))}async function getCartState(){const response=await fetch(`${root.theme.routes.cart_url}.js`,{headers:{Accept:"application/json"}});if(!response.ok)throw new Error("Cart could not be loaded.");return response.json()}async function removeCartLine(surface,removeData){let cart;try{cart=await getCartState()}catch(error){console.error("[FAC_CART] Failed to load cart before removal",error),surface.container.updateQuantity(removeData.line,"0");return}const updates=buildFacRemoveUpdates(cart,removeData);if(!updates){surface.container.updateQuantity(removeData.line,"0");return}const sectionNames=sectionsForOrigin(surface.origin);surface.container.classList.add("cart-disabled");try{dispatchLineEvent("line-item:change:start","0");const response=await fetch(`${root.theme.routes.cart_update_url}.js`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({updates,sections:sectionNames,sections_url:root.location.pathname})}),updatedCart=await response.json();if(!response.ok||updatedCart.errors)throw new Error(updatedCart.errors||"Der Artikel konnte nicht entfernt werden. Bitte versuche es erneut.");renderSections(updatedCart.sections,sectionNames),dispatchLineEvent("line-item:change:end","0",updatedCart)}catch(error){console.error("[FAC_CART] Failed to remove FAC cart group",error),typeof surface.container.displayErrors=="function"&&surface.container.displayErrors(removeData.line,error.message)}finally{surface.container.classList.remove("cart-disabled")}}function handleCartRemove(event){const removeElement=event.target?.closest?.("cart-remove"),surface=cartSurface(removeElement);!removeElement||!surface||(event.stopImmediatePropagation(),removeCartLine(surface,{line:removeElement.dataset.line||removeElement.dataset.index,key:removeElement.dataset.key}))}function install(){typeof document>"u"||root.MomeryFacCartBridgeInstalled||(root.MomeryFacCartBridgeInstalled=!0,document.addEventListener("change",handleQuantityChange,!0),document.addEventListener("cart:remove",handleCartRemove,!0))}
1const api={buildFacRemoveUpdates,sectionsForOrigin,handleQuantityChange,removeCartLine,install};root.MomeryFacCartBridge=api,install(),typeof module<"u"&&module.exports&&(module.exports=api)})(typeof window<"u"?window:globalThis); 2//# sourceMappingURL=/cdn/shop/t/54/assets/momery-fac-cart-bridge.js.map?v=122009192238254472951790770303
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.