1(function() { 2 3 const shippingSelects = document.querySelectorAll(".shipping-selector--item"); 4 let firstSelectPrevAddress = null; 5 6 function initAddressSelects() { 7 for (let s of shippingSelects) { 8 updateMailInSame(s) 9 s.addEventListener("change", (e) => updateMailInSame(e.target)); 10 } 11 useFirstAddressForAll(shippingSelects[0]); 12 shippingSelects[0].addEventListener("change", (e) => useFirstAddressForAll(e.target)); 13 } 14 15 // Update Mail-in address selection to match the item's shipping address 16 function updateMailInSame(el) { 17 let mail_in = el.parentElement.querySelector("select.shipping-selector--mail-in"); 18 19 if (!mail_in) { 20 return; 21 } 22 23 let shipping_val = el.value; 24 let mail_in_val = mail_in.value; 25 26 let same = mail_in.querySelector(".option--same"); 27 28 if (!shipping_val || el.selectedOptions[0].disabled) { 29 same.hidden = true; 30 same.disabled = true; 31 } else { 32 same.hidden = false; 33 same.disabled = false; 34 same.value = shipping_val; 35 } 36 37 if (same.value == mail_in_val) { 38 mail_in.selectedIndex = Array.from(mail_in.options).indexOf(same); 39 } 40 41 for (let child of mail_in.querySelectorAll(".option--real")) { 42 child.disabled = false; 43 child.hidden = false; 44 45 if (child.value == shipping_val) { 46 child.disabled = true; 47 child.hidden = true; 48 } 49 50 if (child.value == mail_in_val && !child.disabled) { 51 mail_in.selectedIndex = Array.from(mail_in.options).indexOf(child); 52 } 53 } 54 } 55 56 // Use the address chosen in the first shipping selection in all others, if appropriate 57 function useFirstAddressForAll(el) { 58 if (el.selectedOptions[0].disabled) { 59 return; 60 } 61 const selectedFirstAddress = el.value; 62 // Update others if they are untouched (disabled) or the same as the first select (before it changed) 63 const otherSelectsAreEqual = Array.from(shippingSelects).slice(1).every( 64 (s) => s.selectedOptions[0].disabled || s.value === firstSelectPrevAddress 65 ); 66 if (otherSelectsAreEqual) { 67 for (let s of shippingSelects) { 68 s.value = selectedFirstAddress; 69 updateMailInSame(s); 70 } 71 } 72 firstSelectPrevAddress = selectedFirstAddress; 73 } 74 75 initAddressSelects(); 76 77 // Override the edit item button to submit the form with a fetch and then client-side redirect 78 // This is faster, and allows the button to work even if saving the cart times out 79 function initEditCartItem() { 80 const cartForm = document.getElementById('destination-form'); 81 document.querySelectorAll('.item-edit').forEach(function (item) { 82 item.addEventListener('click', function (event) { 83 event.preventDefault(); 84 const saveUrl = item.getAttribute('formaction'); 85 const formData = new FormData(cartForm); 86 fetch(saveUrl, { 87 method: 'POST', 88 redirect: 'manual', 89 body: formData, 90 }); 91 const editUrl = item.getAttribute('value'); 92 // Give cart some time to save before redirecting in case quantity changed 93 setTimeout(() => { 94 location.href = editUrl; 95 }, 1000); 96 }); 97 }); 98 } 99 100 initEditCartItem(); 101})();
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.