Current File : /home/digitaw/www/wp-content/plugins/event-tickets/build/js/v2/tickets-commerce.js
window.tribe.tickets=window.tribe.tickets||{},window.tribe.tickets.commerce={},function(e,t,o){const c=e(document);t.customEvents={showLoader:"showLoader.tecTicketsCommerce",hideLoader:"hideLoader.tecTicketsCommerce"},t.selectors={checkoutContainer:".tribe-tickets__commerce-checkout",checkoutItem:".tribe-tickets__commerce-checkout-cart-item",checkoutItemDescription:".tribe-tickets__commerce-checkout-cart-item-details-description",checkoutItemDescriptionOpen:".tribe-tickets__commerce-checkout-cart-item-details--open",checkoutItemDescriptionButtonMore:".tribe-tickets__commerce-checkout-cart-item-details-button--more",checkoutItemDescriptionButtonLess:".tribe-tickets__commerce-checkout-cart-item-details-button--less",hiddenElement:".tribe-common-a11y-hidden",nonce:"#tec-tc-checkout-nonce",purchaserFormContainer:".tribe-tickets__commerce-checkout-purchaser-info-wrapper",purchaserName:".tribe-tickets__commerce-checkout-purchaser-info-form-field-name",purchaserEmail:".tribe-tickets__commerce-checkout-purchaser-info-form-field-email",couponAddLink:".tec-tickets-commerce-checkout-cart__coupons-add-link",couponAppliedDiscount:".tec-tickets-commerce-checkout-cart__coupons-discount-amount",couponAppliedLabel:".tec-tickets-commerce-checkout-cart__coupons-applied-label",couponAppliedSection:".tec-tickets-commerce-checkout-cart__coupons-applied-container",couponApplyButton:".tec-tickets-commerce-checkout-cart__coupons-apply-button",couponError:".tec-tickets-commerce-checkout-cart__coupons-input-error",couponInput:".tec-tickets-commerce-checkout-cart__coupons-input-field",couponInputContainer:".tec-tickets-commerce-checkout-cart__coupons-input-container",couponInputErrorClass:"tribe-tickets__form-field-input--error",couponRemoveButton:".tec-tickets-commerce-checkout-cart__coupons-remove-button"},t.loaderShow=function(){tribe.tickets.loader.show(e(t.selectors.checkoutContainer))},t.loaderHide=function(){tribe.tickets.loader.hide(e(t.selectors.checkoutContainer))},t.bindLoaderEvents=function(){c.on(t.customEvents.showLoader,t.loaderShow),c.on(t.customEvents.hideLoader,t.loaderHide)},t.checkoutItemDescriptionToggle=function(o){if("keydown"===o.type&&13!==o.keyCode)return;const c=o.currentTarget;if(!c)return;const n=e(c);if(!n.hasClass(t.selectors.checkoutItemDescriptionButtonMore.className())&&!n.hasClass(t.selectors.checkoutItemDescriptionButtonLess.className()))return;const s=n.closest(t.selectors.checkoutItem),r=e("#"+n.attr("aria-controls"));if(!r.length||!s.length)return;const i=!s.hasClass(t.selectors.checkoutItemDescriptionOpen.className());s.toggleClass(t.selectors.checkoutItemDescriptionOpen.className(),i),r.toggleClass(t.selectors.checkoutItemDescriptionOpen.className(),i),r.toggleClass(t.selectors.hiddenElement.className())},t.bindCheckoutItemDescriptionToggle=function(e){e.find(t.selectors.checkoutItemDescriptionButtonMore+", "+t.selectors.checkoutItemDescriptionButtonLess).on("keydown",t.checkoutItemDescriptionToggle).on("click",t.checkoutItemDescriptionToggle)},t.unbindCheckoutItemDescriptionToggle=function(e){e.find(t.selectors.checkoutItemDescriptionButtonMore+", "+t.selectors.checkoutItemDescriptionButtonLess).off()},t.bindCheckoutEvents=function(e){c.trigger("beforeSetup.tecTicketsCommerce",[e]),t.bindAddCouponLink(),t.bindCouponApply(),t.bindCouponRemove(),t.bindCheckoutItemDescriptionToggle(e),t.bindLoaderEvents(),c.trigger("afterSetup.tecTicketsCommerce",[e])},t.getPurchaserData=e=>{const o={};return e.length?(o.name=e.find(t.selectors.purchaserName).val(),o.email=e.find(t.selectors.purchaserEmail).val(),o):o},t.ready=function(){c.find(t.selectors.checkoutContainer).each((function(o,c){t.bindCheckoutEvents(e(c))}))},t.updateTotalPrice=function(t){const o=e(".tribe-tickets__commerce-checkout-cart-footer-total-wrap"),c=(new DOMParser).parseFromString(`<!doctype html><body>${t}`,"text/html").body.textContent;o.text(c)},t.updateCouponDiscount=function(o){const c=e(t.selectors.couponAppliedDiscount),n=(new DOMParser).parseFromString(`<!doctype html><body>${o}`,"text/html").body.textContent;c.text(n)},t.updateCouponLabel=function(o){const c=e(t.selectors.couponAppliedLabel),n=(new DOMParser).parseFromString(`<!doctype html><body>${o}`,"text/html").body.textContent;c.text(n)},t.bindAddCouponLink=function(){const o=t.selectors.hiddenElement.className();c.on("click",t.selectors.couponAddLink,(function(){e(t.selectors.couponAddLink).addClass(o),e(t.selectors.couponInputContainer).removeClass(o)}))},t.getStripeIntentId=function(){return window.tecTicketsCommerceGatewayStripeCheckout?.paymentIntentData?.id},t.disableInterruption=()=>{const e=window.tec.tickets?.seating?.frontend?.session?.setIsInterruptable;"function"==typeof e&&e(!1)},t.bindCouponApply=function(){let n=!1;function s(){if(n)return;const c=e(t.selectors.couponInput),s=c.val().trim(),r=e(t.selectors.couponError),i=t.selectors.hiddenElement.className(),a=e(t.selectors.couponInputContainer),u=e(t.selectors.nonce).val(),l=t.getStripeIntentId();if(r.addClass(i),!s)return r.text(o.i18n.couponCodeEmpty),r.removeClass(i),void c.addClass(t.selectors.couponInputErrorClass);n=!0,t.loaderShow();const p=window.location.search.match(/tec-tc-cookie=([^&]*)/),d={coupon:s,nonce:u,purchaser_data:t.getPurchaserData(e(t.selectors.purchaserFormContainer)),cart_hash:p[1]};void 0!==l&&(d.payment_intent_id=l),e.ajax({url:`${o.restUrl}coupons/apply`,method:"POST",data:d,success(n){n.success?(c.removeClass(t.selectors.couponInputErrorClass),a.addClass(i),t.updateCouponDiscount(n.discount),t.updateCouponLabel(n.label),t.updateTotalPrice(n.cartAmount),e(t.selectors.couponAppliedSection).removeClass(i),n.doReload&&(t.disableInterruption(),window.location.reload())):(r.text(n.message||o.i18n.invalidCoupon).removeClass(i),c.addClass(t.selectors.couponInputErrorClass),a.removeClass(i))},error(e){const n=e?.responseJSON?.message||o.i18n.couponApplyError;r.text(n).removeClass(i),c.addClass(t.selectors.couponInputErrorClass),a.removeClass(i)},complete(){t.loaderHide(),n=!1}})}c.on("click",t.selectors.couponApplyButton,s),c.on("keydown",t.selectors.couponInput,(function(e){"Enter"===e.key&&(e.preventDefault(),s())}))},t.bindCouponRemove=function(){c.on("click",t.selectors.couponRemoveButton,(function(){let c=!1;if(c)return;const n=e(t.selectors.couponInput).val().trim(),s=e(t.selectors.couponError),r=t.selectors.hiddenElement.className(),i=e(t.selectors.nonce).val(),a=t.getStripeIntentId();if(s.addClass(r),!n)return void s.text(o.i18n.cantDetermineCoupon).removeClass(r);c=!0,t.loaderShow();const u={nonce:i,coupon:n,cart_hash:window.location.search.match(/tec-tc-cookie=([^&]*)/)[1]};void 0!==a&&(u.payment_intent_id=a),e.ajax({url:`${window.tecTicketsCommerce.restUrl}coupons/remove`,method:"POST",data:u,beforeSend(){t.loaderShow()},success(c){c.success?(e(t.selectors.couponAddLink).removeClass(r),e(t.selectors.couponInput).val(""),e(t.selectors.couponAppliedSection).addClass(r),t.updateTotalPrice(c.cartAmount),c.doReload&&(t.disableInterruption(),window.location.reload())):s.text(c.message||o.i18n.couponRemoveFail).removeClass(r)},error(){s.text(o.i18n.couponRemoveError).removeClass(r)},complete(){t.loaderHide(),c=!1}})}))},e(t.ready)}(jQuery,window.tribe.tickets.commerce,window.tecTicketsCommerce||{}),window.tec=window.tec||{},window.tec.tickets=window.tec.tickets||{},window.tec.tickets.v2=window.tec.tickets.v2||{},window.tec.tickets.v2.ticketsCommerce={};