!function(){var t=function(t){var e={exports:{}};return t.call(e.exports,e,e.exports),e.exports},e=function(){function t(t,e){for(var n=0;n=400))try{var n=document.createElement("a");n.href=e.url;var r=n.pathname?n.pathname:e.url;t.ADD_TO_CART_REGEX.test(r)&&t._parsePayloadResponse(e,(function(t){var n=Object.keys(t);if(1===n.length&&"items"===n[0]){var r=t.items,a=void 0;try{a=JSON.parse(e.body).items}catch(t){a=i(e.body,r.length)}o(r,a,"add-xhr-bulk")}else u(t,d(e.body),"add-xhr")}))}catch(t){console&&console.warn&&console.warn("[shop_events_listener] Error in handleXhrDone: "+t.message)}}},{key:"parseBlobToJson",value:function(t,e){var n=new FileReader;n.addEventListener("loadend",(function(){return e(JSON.parse(String.fromCharCode.apply(String,r(new Uint8Array(n.result)))))})),n.readAsArrayBuffer(t)}},{key:"_parsePayloadResponse",value:function(e,n){e.xhr.response instanceof Blob?t.parseBlobToJson(e.xhr.response,n):e.xhr.responseText&&n(JSON.parse(e.xhr.responseText))}}]),t}();m.ADD_TO_CART_REGEX=/^(?:\/[a-zA-Z]+(?:-[a-zA-Z]+)?)?\/+cart\/+add(?:\.js|\.json)?\/*$/,m.XHR_FALLBACK_STATE={UNSENT:0,OPENED:1,HEADERS_RECEIVED:2,LOADING:3,DONE:4},a.default=m,function(){function t(t,e,n){window.jQuery&&window.jQuery(t).bind?window.jQuery(t).bind(e,n):t.addEventListener?t.addEventListener(e,n):t.attachEvent&&t.attachEvent("on"+e,n)}function e(t){if(!((t=t||window.event).defaultPrevented||t.isDefaultPrevented&&t.isDefaultPrevented())){var e=t.target||t.srcElement;if(e&&(e.getAttribute("action")||e.getAttribute("href")))try{var n=void 0,r=e.id||e.elements.id;n=r.options?r.options[r.selectedIndex]:r;var a=f("cart"),i=o(n.value);i.quantity=String(e.quantity?e.quantity.value:1);var d=y({cartToken:a},i),c=y({referer:window.location.href},i);window.ShopifyAnalytics.lib.track("Added Product",d,void 0,void 0,{addApiSource:"add-form",shopifyEmitted:!0}),window.ShopifyAnalytics.lib.track("monorail://trekkie_storefront_track_added_product/1.1",c)}catch(t){console&&console.warn&&console.warn("[shop_events_listener] Error in handleSubmitCartAdd: "+t.message)}}}function n(t){var e=(t=t||window.event).target||t.srcElement;if(e&&e.getAttribute("action")&&null!==e.getAttribute("data-payment-form"))try{window.ShopifyAnalytics.lib.track("Added Payment",{currency:window.ShopifyAnalytics.meta.currency,total:window.ShopifyAnalytics.meta.checkout.payment_due/100},void 0,void 0,{shopifyEmitted:!0})}catch(t){console&&console.warn&&console.warn("[shop_events_listener] Error in handleSubmitToPaymentAdd: "+t.message)}}function r(t){a((t=t||window.event).currentTarget)}function a(t){try{var e=void 0,n=t.id||t.elements.id;if(!(e=n.options&&n.options[n.selectedIndex]?n.options[n.selectedIndex]:n))return;var r=e.value;if(window.ShopifyAnalytics.meta.selectedVariantId&&window.ShopifyAnalytics.meta.selectedVariantId==r)return;window.ShopifyAnalytics.meta.selectedVariantId=r;var a=o(r);window.ShopifyAnalytics.lib.track("Viewed Product Variant",a,void 0,void 0,{shopifyEmitted:!0})}catch(t){console&&console.warn&&console.warn("[shop_events_listener] Error in trackViewedProductVariant: "+t.message)}}function o(t){var e=y(c(t),l());return e.currency=window.ShopifyAnalytics.meta.currency,e}function i(t,e){var n=!0,r=!1,a=void 0;try{for(var o,i=e[Symbol.iterator]();!(n=(o=i.next()).done);n=!0){var c=o.value,s=d(t,c);if(s)return{product:c,variant:s}}}catch(t){r=!0,a=t}finally{try{!n&&i.return&&i.return()}finally{if(r)throw a}}}function d(t,e){var n=!0,r=!1,a=void 0;try{for(var o,i=e.variants[Symbol.iterator]();!(n=(o=i.next()).done);n=!0){var d=o.value;if(d.id==t)return d}}catch(t){r=!0,a=t}finally{try{!n&&i.return&&i.return()}finally{if(r)throw a}}}function c(t){var e=void 0,n=void 0,r=void 0;if(window.ShopifyAnalytics.meta.products){var a=i(t,window.ShopifyAnalytics.meta.products);e=a.product,n=a.variant}else window.ShopifyAnalytics.meta.product&&(n=d(t,e=window.ShopifyAnalytics.meta.product));return e?(r={productId:e.id,productGid:e.gid,brand:e.vendor,category:e.type},n&&(r=y(r,{variantId:t,price:n.price/100,name:n.name,sku:n.sku,variant:n.public_title}))):r={variantId:t},r}t(window,"load",(function(){for(var o=0;o=0&&(t(document.forms[o],"submit",e),t(document.forms[o],"change",r),a(document.forms[o]));var d=document.forms[o].elements.previous_step;d&&"payment_method"===d.value&&t(document.body,"submit",n)}}))}(),h=XMLHttpRequest,p=h.prototype.open,v=h.prototype.send,h.prototype.open=function(t,e){this._url=e,this._method=t,m.handleXhrOpen(),p.apply(this,arguments)},h.prototype.send=function(t){var e=new m(this,this._url,this._method,t);this.addEventListener?this.addEventListener("readystatechange",e.onReadyStateChange.bind(e),!1):(e.oldOnReadyStateChange=this.onreadystatechange,this.onreadystatechange=e.onReadyStateChange),v.call(this,t)},function(t,e){function n(t,e){t.clone().json().then((function(t){if("[object Object]"===Object.prototype.toString.call(t))if(t.items){var n=c(e).items;o(t.items,n,"add-fetch-bulk")}else{u(t,d(e),"add-fetch")}})).catch(r)}function r(t){console&&console.warn&&console.warn("[shop_events_listener] Error in handleFetchRequest: "+t.message)}"function"==typeof e&&(t.fetch=function(){var t=arguments;return e.apply(this,Array.prototype.slice.call(arguments)).then((function(e){if(!e.ok)return e;var a=document.createElement("a");a.href=e.url;var o=a.pathname?a.pathname:e.url;try{if(m.ADD_TO_CART_REGEX.test(o))try{n(e,t[1].body)}catch(t){}}catch(t){r(t)}return e}))})}(window,window.fetch)}))}("undefined"!=typeof global?global:"undefined"!=typeof window&&window);