https://dz.diesel.com/on/demandware.static/Sites-DieselWW-Site/-/e…/js/component-AddToCart.chunks.js
1(self.webpackChunkapp_project=self.webpackChunkapp_project||[]).push([[2538,5645],{34096:(t,e,r)=>{"use strict";r.r(e),r.d(e,{default:()=>c});var a=r(12737);const o=r(8563).N,i=r(6583).default,n=r(14863).ZP,s=r(11253).Z;class c extends i{get isTile(){return"tile"===this.element.dataset.type}get isCartPage(){return!!document.querySelector('[data-component="CartPage"')}get SELECTORS(){return{attributeSize:".attribute-values.size",attributeLength:".attribute-values.length",addToCartButton:'.add-to-cart-section [data-action="add-to-cart"]',allAddToCartButtons:'[data-action="add-to-cart"]',addToCartButtonSticky:'.add-to-cart--wrapper .add-to-cart-section [data-action="add-to-cart"]',cartSwitcherPanel:".js-cart-switcher-panel",cartBoxes:".cart-box",giftcardSidebarPlaceholder:".giftcard-message__content",header:"header"}}get CLASSES(){return{noBackdrop:"no-backdrop"}}constructor(t){super(t),this.wishlistBadge=document.querySelector('[data-user-action="wishlist"] .button__badge'),this.addToCartWrapper=document.querySelector(".add-to-cart--wrapper"),this.attributeSize=document.querySelector(this.SELECTORS.attributeSize),this.attributeLength=document.querySelector(this.SELECTORS.length),this.addToCartButton=this.element.querySelector(this.SELECTORS.addToCartButton),this.allAddToCartButtons=this.element.querySelectorAll(this.SELECTORS.allAddToCartButtons),this.addToCartButtonSticky=document.querySelector(this.SELECTORS.addToCartButtonSticky),this.cartSwitcherPanel=document.querySelector(this.SELECTORS.cartSwitcherPanel),this.cartBoxes=this.element.querySelectorAll(this.SELECTORS.cartBoxes),this.navigationHeader=document.querySelector(this.SELECTORS.header),this.form.addEventListener("data",this.handleEventData.bind(this)),t.parentElement.classList.contains("add-to-cart--main")&&!0===window.matchMedia("(max-width: 1023px)").matches&&this.isInViewport(t),$(this.element.parentElement.classList).toArray().indexOf("add-to-cart--wrapper")>-1?this.addToCartButtonSticky.addEventListener("click",(t=>{"submit"!==t.currentTarget.type&&this.add()})):this.addToCartButton&&this.addToCartButton.addEventListener("click",(t=>{"submit"!==t.currentTarget.type&&this.add()})),[...this.cartBoxes].forEach((t=>{const e=t.dataset.basket,r=t.querySelector("#reservation-"+e+"-basket");t.addEventListener("click",(()=>{r.click()})),r.addEventListener("change",(e=>{[...this.cartBoxes].forEach((t=>{t.classList.remove("active-box")})),e.target.checked&&t.classList.add("active-box")}))})),this.sourceProductTile,a.Z.on("product:showInfoPanel",(t=>{let{productTile:e}=t;this.sourceProductTile=e}))}handleEventData(t){const{body:e,data:r}=t.detail;if(r.giftcardError)return this.handleGiftCardError(t),void a.Z.emit("body:loaded");if(r.handleWithCartSwitcher)return this.handlePreorderProductError(t),void a.Z.emit("body:loaded");if(r&&r.quantityTotal){const t=document.querySelector(".js-side-panel-size-selector.open");let o={stickyButton:!1};("add-to-cart--wrapper"===this.form.parentNode.classList.value||t)&&(o.stickyButton=!0),o.tile=this.sourceProductTile,o.type=this.element.dataset.type,o.pid=e.get("pid"),o.addToCartResponse=r,o.isFromCartSwitcher=r.cart.switcher,this.navigationHeader.classList.remove(this.CLASSES.noBackdrop),r.isCartPage=this.isCartPage,a.Z.emit("update:minicart",r),a.Z.emit("product:afterAddToCart",o),a.Z.emit("algolia:product:afterAddToCart",r)}a.Z.emit("body:loaded")}handleGiftCardError(t){if("missingValues"!==t.detail.data.message)"alreadyInCart"===t.detail.data.message&&this.callGiftcardShowSidebar();else{const e=document.querySelector('[data-component="GiftcardMessage"]');if(e&&e.componentInstance){const t=document.querySelector(".js-giftcard-input_name"),r=document.querySelector(".js-giftcard-input_email"),a=document.querySelector(".js-line-item-attributes-format"),o=document.querySelector(".js-line-item-attributes-color"),i=document.querySelector(".js-line-item-attributes-amount"),n=document.querySelector('input[name="giftcardAmount"]');t.setAttribute("required",""),r.setAttribute("required",""),a.innerText=document.querySelector(".js_attribute-giftcardType.selected span").textContent,o.innerText=document.querySelector(".js_attribute-color.selected").dataset.attrDisplayValue,i.innerText=n?n.value:"",e.componentInstance.open()}const{result:r}=t.detail.data;if(r&&r.giftcardErrorMessage){const t=this.element.querySelector("[name=dwfrm_giftcardProduct_giftcardRecipientMessage]"),e=this.element.querySelector("#giftCardRecipientMessage_error");t.classList.add("invalid"),e.innerText=r.giftcardErrorMessage}}}async getCartSwitcher(t){const e=t.callbackURL,r=JSON.stringify(t.data);if(e){const t=this.cartSwitcherPanel.querySelector(".side-panel__inner");this.cartSwitcherPanel.offsetWidth,this.cartSwitcherPanel.componentInstance.open();const o=this.cartSwitcherPanel.querySelector(".js-cart-switcher-body");o.innerHTML="";try{a.Z.emit("loader:start",{element:t});const i=await n(e,{method:"POST",body:r}),s=await i.json();if(s.error)throw new Error(s.message);o.innerHTML=s.renderedTemplate,a.Z.emit("loader:end",{element:t}),a.Z.emit("cartswitcher:open",{tile:this.element.queryParentsByClassName("product"),type:this.element.dataset.type}),a.Z.emit("sidepanel:contentLoaded")}catch(t){console.error(t)}}}handlePreorderProductError(t){const e=t.detail.data.cartSwitcher;if(e.enable){if(!this.cartSwitcherPanel){const r=document.createElement("div");return r.innerHTML=t.detail.data.cartSwitcher.template,document.body.appendChild(r),this.cartSwitcherPanel=document.querySelector(this.SELECTORS.cartSwitcherPanel),void a.Z.once("toggler:setup",(()=>{this.getCartSwitcher(e)}))}this.getCartSwitcher(e)}else console.error("Cart Switcher is not enabled")}setup(){this.form.addEventListener("submit",(t=>{t.preventDefault();var e=t.submitter;
1const r=e.closest(".js-side-panel-main-product-information");if(r){const t=r.querySelector(".product-tile__actions-content").dataset.pid,a=document.querySelector('.js-open-attributes[data-information-pid="'.concat(t,'"]'));a&&(e=a)}a.Z.emit("cart:addToCartTriggered",{focusTarget:e}),this.add()})),this.element.querySelector(".js_login-page-pdp-members")&&$(document).one("user:loggedIn",(()=>{this._isDelegatedAfterLogin()&&($('[data-action="add-to-cart"]').toggleClass("d-none"),this.add()),this.delegatedAfterLogin=!1}))}_isDelegatedAfterLogin(){return!!this.delegatedAfterLogin}async addReservationItem(t){const e="current"===t.chooseBasket;a.Z.emit("body:loading");const r=JSON.parse(t.pidsObj)[0].pid,o=e?JSON.stringify([r]):this.element.dataset.basketItems,i=new FormData,s={pids:o,variables:""};Object.keys(s).forEach((t=>i.append(t,s[t])));const c=await n("".concat(this.element.dataset.addToWishlist),{method:"POST",body:i});return{response:await c.json(),isCurrentBasket:e}}handleAddToWishlist(t){const e=t.items,r=t.count;r>0&&(this.wishlistBadge.textContent=r,this.wishlistBadge.classList.remove("hidden"));for(let t=0;e.length>t;t++){let r=e[t];if(r.success){let t=document.querySelector('.js_add-to-wish-list[data-variant-id="'.concat(r.pid,'"]'));t&&t.classList.add("is-full")}}}handleResponseAddReservationItem(t){this.cartSwitcherPanel&&this.cartSwitcherPanel.componentInstance&&this.cartSwitcherPanel.componentInstance.close();const e=t.isCurrentBasket?"cartswitcher:currentBasket":"cartswitcher:newBasket";a.Z.emit(e),this.handleAddToWishlist(t.response);let r=document.querySelector(".side-panel.js-side-panel-size-selector.open");if(r&&r.componentInstance.close(),t.isCurrentBasket)return void a.Z.emit("body:loaded");const o=new CustomEvent("beforeSubmit",{bubbles:!0,cancelable:!0,composed:!1});return this.form.dispatchEvent(o),this.submitHandler()}preAddToCart(){var t=this.element.parentNode.closest('[data-component="ProductInformations"]');null===t&&(t=document.querySelector('[data-component="ProductInformations"]'));const e=this.attributeSize.querySelector(".selected"),r=!!this.attributeLength&&this.attributeLength.querySelector(".selected"),o=document.querySelector(".js-side-panel-size-selector.open"),i=!!(!0!==window.matchMedia("(max-width: 1023px)").matches||this.isTile||o||r||e);if(t&&t.componentInstance){if(t.componentInstance.validate(i)){const t=new CustomEvent("beforeSubmit",{bubbles:!0,cancelable:!0,composed:!1});return this.form.dispatchEvent(t),a.Z.emit("body:loading"),this.form.dataset.setstore&&this.setStoreInSession(this.form.dataset.setstore,this.formData.sid),!0}$(".add-to-cart--wrapper").removeClass("d-none"),a.Z.emit("sticky:focusOnError"),this.isTile&&this.allAddToCartButtons.forEach((t=>{t.setAttribute("disabled",!0),t.classList.add("disabled")}))}return!1}showSidebarPanel(){if(this.preAddToCart())return this.callGiftcardShowSidebar()}add(){if(this.formData=o(this.form),"true"==this.formData.isReservationItem)return void this.addReservationItem(this.formData).then((t=>this.handleResponseAddReservationItem(t)));const t="GIFTCARD"===this.element.dataset.actionType,e=document.querySelector('.js_attribute-giftcardType[aria-checked="true"]');if(!t||!e||"digital"!==e.dataset.attrValue)return this.preAddToCart()?this.submitHandler():void 0;this.showSidebarPanel()}removeClassHeader(){let t=["large","xlarge"].indexOf(s.getCurrentBreakPoint())>=0?"mouseover":"toggler:clicked";document.querySelector("#menu-bag-panel").addEventListener(t,(()=>{const t=document.querySelector(".info-bag-menu");t&&t.classList.remove("minicart-header-new")}))}setStoreInSession(t,e){n("".concat(t,"?sid=").concat(e),{method:"GET"}).then((t=>t.json())).then((t=>{})).catch((t=>{}))}clearErrorMessage(){setTimeout((()=>{let t=document.querySelector(".jp-is-reservation-or-preorder-error");t&&t.style.setProperty("display","none")}),7e3)}isInViewport(t){var e=t.getBoundingClientRect();e.top>=0&&e.left>=0&&e.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&e.right<=(window.innerWidth||document.documentElement.clientWidth)?$(".add-to-cart--wrapper").attr("viewport",!1):$(".add-to-cart--wrapper").attr("viewport",!0),window.addEventListener("scroll",(function(){(e=t.getBoundingClientRect()).top>=0&&e.left>=0&&e.bottom<=(window.innerHeight||document.documentElement.clientHeight)?$(".add-to-cart--wrapper").attr("viewport",!1):$(".add-to-cart--wrapper").attr("viewport",!0)})),this.addToCartWrapper&&($(window).scroll((function(){var t,e=$(window).scrollTop()+$(window).height(),r=$(".product-recommendations-detail");r&&(t=(r.offset()?r.offset().top:0)<e),this.addToCartWrapper&&(r.toArray().length>0&&t?addToCartWrapper.classList.add("d-none"):addToCartWrapper.classList.remove("d-none"))})),$(window).scroll((function(){var t=$(window).scrollTop()+$(window).height(),e=$(".footer").offset().top;$(".footer").height(),e<t?this.addToCartWrapper.classList.add("d-none"):this.addToCartWrapper.classList.remove("d-none")})),$(window).scroll((function(){var t=$(window).scrollTop()+$(window).height(),e=$(".product-recommendations-detail").offset().top;$(".product-recommendations-detail").height(),e<t?this.addToCartWrapper.classList.add("d-none"):this.addToCartWrapper.classList.remove("d-none")})),$(window).scroll((function(){var t,e=$(window).scrollTop()+$(window).height(),r=$(".vue-module--style-with");r&&(t=(r.offset()?r.offset().top:0)<e),r.toArray().length>0&&(t?this.addToCartWrapper.classList.add("d-none"):this.addToCartWrapper.classList.remove("d-none"))})))}async callGiftcardShowSidebar(){const t=this.element.dataset.actionGiftcardUrl,e=this.element.querySelector('input[name="pid"]').value,r=this.element.querySelector('input[name="giftcardAmount"]').value,o=t.concat("?pid=",e,"&selectedValue=",r);try{const t=await n(o,{method:"GET",dataType:"text/html"}),e=await t.text();a.Z.emit("body:loaded"),this.panelProductInformation=document.querySelector(".side-panel-product-information.open"),this.panelProductInformation&&a.Z.emit("panel:closeProductInfo");var i=document.querySelector(this.SELECTORS.giftcardSidebarPlaceholder);
1i&&(i.innerHTML=e,a.Z.emit("gifcard:init",{element:this.element}));const r=document.querySelector('[data-component="GiftcardMessage"]');if(r&&r.componentInstance){const t=i.querySelector(".js-giftcard-input_name"),e=i.querySelector(".js-giftcard-input_email"),a=i.querySelector(".js-line-item-attributes-format"),o=i.querySelector(".js-line-item-attributes-color"),n=i.querySelector(".js-line-item-attributes-amount");if(!t)return r.componentInstance.buttonsEventHandler(),void r.componentInstance.open();t.setAttribute("required",""),e.setAttribute("required","");var s=document.querySelector(".js_attribute-giftcardType.selected span");a.innerText=s.textContent,o.innerText=document.querySelector(".js_attribute-color.selected").dataset.attrDisplayValue,n.innerText=document.querySelector('input[name="giftcardAmount"]').value,r.componentInstance.open()}}catch(t){a.Z.emit("body:loaded"),console.error("GIFT CARD SIDE PANEL API ERROR - Error: "+t)}}}},6583:(t,e,r)=>{"use strict";r.r(e),r.d(e,{default:()=>n});const a=r(8563).N,o=r(14863).ZP,i=r(38302).default;class n extends i{constructor(t){super(t),this.form=t,this.formData={},this.url=new URL(this.action(),window.location.origin),this.isSubmitting=!1,this.setup()}setup(){this.form.addEventListener("submit",(t=>{t.preventDefault(),this.submitHandler()})),[...this.form.querySelectorAll('[type="submit"]')].forEach((t=>{t.addEventListener("click",(t=>{this.isSubmitting=!0}))})),this.form.addEventListener("invalid",(t=>{this.isSubmitting&&(this.focusOnInvalidInput(),this.isSubmitting=!1)}),!0)}focusOnInvalidInput(t){if((t=t||this.form.querySelector("input:invalid, textarea:invalid, select:invalid"))&&document.activeElement!==t){t.focus({preventScroll:!0});let e=t.getBoundingClientRect(),r=window.scrollY+e.top-window.innerHeight/3;window.scrollTo({top:r,behavior:"auto"})}console.log("Focus on first invalid input:",t)}loadRecaptchaScript(t){const e=document.querySelector("#recaptcha-script");if(!e)return void(document.querySelector('script[src*="recaptcha"]')&&(this.recaptchaScriptLoaded=!0));const r=()=>{e.getAttribute("src")||(e.setAttribute("src",e.dataset.src),e.async=!0,e.onload=()=>{document.dispatchEvent(new CustomEvent("recaptcha-loaded"))},this.recaptchaScriptLoaded=!0)};t?r():this.recaptchaFocusBound||(this.form.addEventListener("mouseenter",r,{once:!0}),this.form.addEventListener("focusin",r,{once:!0}),this.form.addEventListener("click",r,{once:!0}),this.recaptchaFocusBound=!0)}getRecaptchaToken(t){const e=this.element.querySelector('input[name="googleRecaptchaClientSide"]'),r=this.element.querySelector('input[name="googleRecaptchaToken"]');if(!e)return;const a=()=>{window.grecaptcha.ready((()=>{this.performRecaptchaCall=async()=>window.grecaptcha.execute(e.value,{action:t}).then((t=>(r.value=t,t)))}))};window.grecaptcha?a():(document.addEventListener("recaptcha-loaded",(()=>{console.log("Lazy loading recaptcha."),a()}),{once:!0}),this.loadRecaptchaScript(!1))}action(){return this.form.getAttribute("action")}method(){return this.form.getAttribute("method")}async submitHandler(){this.isSubmitting=!0,this.url=new URL(this.action(),window.location.origin);const t=new CustomEvent("beforeSubmit",{bubbles:!0,cancelable:!0,composed:!1});this.form.dispatchEvent(t),this.performRecaptchaCall&&await this.performRecaptchaCall(),this.formData=a(this.form);const e={method:this.method()};if("get"===this.method().toLowerCase()){const t={},e=new FormData(this.form);for(const r of e.keys())t[r]=e.get(r);this.url.search=new URLSearchParams(t).toString()}else e.body=new FormData(this.form);o("".concat(this.url),e).then((t=>{const e=t.headers.get("content-type");if(!e)throw new TypeError("No content type defined in response/header");return e.includes("application/json")?t.json():e.includes("text/html")?t.text():void 0})).then((t=>{const r=new CustomEvent("data",{detail:{body:e.body,data:t},bubbles:!0,cancelable:!0,composed:!1});this.form.dispatchEvent(r)})).catch((t=>{console.error(t);const e=new CustomEvent("error",{detail:{data:t},bubbles:!0,cancelable:!0,composed:!1});this.form.dispatchEvent(e)}))}}},8563:(t,e,r)=>{"use strict";function a(t){const e={};
1return[...new FormData(t).entries()].forEach((t=>{if(e[t[0]]){let r;"string"==typeof e[t[0]]?r=[e[t[0]],t[1]]:Array.isArray(e[t[0]])&&(r=e[t[0]].push(t[1])),e[t[0]]=r}else e[t[0]]=t[1]})),e}r.d(e,{N:()=>a})}}]);
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.