Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ! function() {
- var e = function(e) {
- var t = {
- exports: {}
- };
- return e.call(t.exports, t, t.exports), t.exports
- },
- i = function() {
- function r(e, t) {
- for (var n = 0; n < t.length; n++) {
- var r = t[n];
- r.enumerable = r.enumerable || !1, r.configurable = !0, "value" in r && (r.writable = !0), Object.defineProperty(e, r.key, r)
- }
- }
- return function(e, t, n) {
- return t && r(e.prototype, t), n && r(e, n), e
- }
- }(),
- h = function(e, t) {
- if (!(e instanceof t)) throw new TypeError("Cannot call a class as a function")
- };
- e(function(e, t) {
- "use strict";
- function s(e) {
- for (var t = e.split("&"), n = 0; n < t.length; n++) {
- var r = t[n].split("=");
- if ("quantity" === r[0]) return r[1]
- }
- return 1
- }
- function c(e, t) {
- var n = u({
- variantId: e.id.to_s,
- productId: e.product_id,
- currency: window.ShopifyAnalytics.meta.currency,
- quantity: (t || 1).to_s,
- price: e.price / 100,
- name: e.title,
- sku: e.sku,
- brand: e.vendor,
- variant: e.variant_title,
- category: e.product_type
- }, d());
- window.ShopifyAnalytics.lib.track("Added Product", n), window.ShopifyAnalytics.lib.track("monorail://trekkie_storefront_track_added_product/1.0", n)
- }
- function d() {
- var e = {};
- return window.ShopifyAnalytics.meta.page && (e = {
- pageType: window.ShopifyAnalytics.meta.page.pageType,
- resourceType: window.ShopifyAnalytics.meta.page.resourceType,
- resourceId: window.ShopifyAnalytics.meta.page.resourceId
- }), e
- }
- function u(e, t) {
- for (var n in t) t.hasOwnProperty(n) && (e[n] = t[n]);
- return e
- }
- Object.defineProperty(t, "__esModule", {
- value: !0
- });
- var n, r, o, l = function() {
- function o(e, t, n, r) {
- h(this, o), this.xhr = e, this.url = t, this.method = n, this.body = r
- }
- return i(o, null, [{
- key: "handleXhrOpen",
- value: function e() {}
- }]), i(o, [{
- key: "onReadyStateChange",
- value: function t() {
- this.xhr.readyState === XMLHttpRequest.DONE && this.handleXhrDone({
- method: this.method,
- url: this.url,
- body: this.body,
- xhr: this.xhr
- }), this.oldOnReadyStateChange && this.oldOnReadyStateChange()
- }
- }, {
- key: "handleXhrDone",
- value: function n(e) {
- try {
- switch (e.url) {
- case "/cart/add.js":
- e.xhr.responseText && c(JSON.parse(e.xhr.responseText), s(e.body));
- break;
- case "/cart/change.js":
- case "/cart/clear.js":
- case "/cart.js":
- e.xhr.responseText && this.facebookMessengerPayment(JSON.parse(e.xhr.responseText))
- }
- } catch (t) {
- console && console.warn && console.warn("[shop_events_listener] Error in handleXhrDone: " + t.message)
- }
- }
- }, {
- key: "facebookMessengerPayment",
- value: function r(e) {
- window.MessengerExtensions && window.MessengerExtensions.isInExtension() && window.MessengerExtensions.updateCart(function() {}, function() {}, e.item_count, "https://" + this._hostName() + "/cart", 300)
- }
- }, {
- key: "_hostName",
- value: function a() {
- return window.location.hostname
- }
- }]), o
- }();
- t["default"] = l,
- function() {
- function r(e, t, n) {
- window.jQuery && window.jQuery(e).bind ? window.jQuery(e).bind(t, n) : e.addEventListener ? e.addEventListener(t, n) : e.attachEvent && e.attachEvent("on" + t, n)
- }
- function o(e) {
- if (!((e = e || window.event).defaultPrevented || e.isDefaultPrevented && e.isDefaultPrevented())) {
- var t = e.target || e.srcElement;
- if (t && (t.getAttribute("action") || t.getAttribute("href"))) try {
- var n = c((t.id.options ? t.id.options[t.id.selectedIndex] : t.id).value);
- n.quantity = (t.quantity ? t.quantity.value : 1).to_s, window.ShopifyAnalytics.lib.track("Added Product", n), window.ShopifyAnalytics.lib.track("monorail://trekkie_storefront_track_added_product/1.0", n)
- } catch (r) {
- console && console.warn && console.warn("[shop_events_listener] Error in handleSubmitCartAdd: " + r.message)
- }
- }
- }
- function a(e) {
- var t = (e = e || window.event).target || e.srcElement;
- if (t && t.getAttribute("action")) try {
- window.ShopifyAnalytics.lib.track("Added Payment", {
- currency: window.ShopifyAnalytics.meta.currency,
- total: window.ShopifyAnalytics.meta.checkout.payment_due / 100
- })
- } catch (n) {
- console && console.warn && console.warn("[shop_events_listener] Error in handleSubmitToPaymentAdd: " + n.message)
- }
- }
- function i(e) {
- s((e = e || window.event).currentTarget)
- }
- function s(e) {
- try {
- var t = void 0;
- if (!(t = e.id.options && e.id.options[e.id.selectedIndex] ? e.id.options[e.id.selectedIndex] : e.id)) return;
- var n = t.value;
- if (window.ShopifyAnalytics.meta.selectedVariantId && window.ShopifyAnalytics.meta.selectedVariantId == n) return;
- var r = c(window.ShopifyAnalytics.meta.selectedVariantId = n);
- window.ShopifyAnalytics.lib.track("Viewed Product Variant", r), window.ShopifyAnalytics.lib.track("monorail://trekkie_storefront_track_viewed_product_variant/1.0", r)
- } catch (o) {
- console && console.warn && console.warn("[shop_events_listener] Error in trackViewedProductVariant: " + o.message)
- }
- }
- function c(e) {
- var t = u(n(e), d());
- return t.currency = window.ShopifyAnalytics.meta.currency, t
- }
- function n(e) {
- var t = void 0,
- n = window.ShopifyAnalytics.meta.product;
- if (n) {
- t = {
- productId: n.id,
- brand: n.vendor,
- category: n.type
- };
- for (var r = 0; r < n.variants.length; r++)
- if (n.variants[r].id == e) {
- var o = n.variants[r];
- t = u(t, {
- variantId: e,
- price: o.price / 100,
- name: o.name,
- sku: o.sku,
- variant: o.public_title
- })
- }
- } else t = {
- variantId: e
- };
- return t
- }
- r(window, "load", function() {
- for (var e = 0; e < document.forms.length; e++) {
- var t = document.forms[e].getAttribute("action");
- t && 0 <= t.indexOf("/cart/add") && (r(document.forms[e], "submit", o), r(document.forms[e], "change", i), s(document.forms[e]));
- var n = document.forms[e].elements.previous_step;
- n && "payment_method" === n.value && r(document.forms[e], "submit", a)
- }
- })
- }(), n = XMLHttpRequest, r = n.prototype.open, o = n.prototype.send, n.prototype.open = function(e, t) {
- this._url = t, this._method = e, l.handleXhrOpen(), r.apply(this, arguments)
- }, n.prototype.send = function(e) {
- var t = new l(this, this._url, this._method, e);
- this.addEventListener ? this.addEventListener("readystatechange", t.onReadyStateChange.bind(t), !1) : (t.oldOnReadyStateChange = this.onreadystatechange, this.onreadystatechange = t.onReadyStateChange), o.call(this, e)
- },
- function(e, t) {
- function r(e) {
- e.clone().json().then(function(e) {
- return l.prototype.facebookMessengerPayment(e)
- })["catch"](a)
- }
- function o(e, t) {
- e.clone().json().then(function(e) {
- return c(e, t)
- })["catch"](a)
- }
- function a(e) {
- console && console.warn && console.warn("[shop_events_listener] Error in handleFetchRequest: " + e.message)
- }
- function i(e) {
- var t = void 0;
- try {
- t = JSON.parse(e).quantity || 1
- } catch (n) {
- t = s(e)
- }
- return t
- }
- "function" == typeof t && (e.fetch = function() {
- var n = arguments;
- return t.apply(this, Array.prototype.slice.call(arguments)).then(function(e) {
- if (!e.ok) return e;
- try {
- switch (!0) {
- case e.url.includes("/cart/add.js"):
- o(e, i(n[1].body));
- break;
- case e.url.includes("/cart/change.js"):
- case e.url.includes("/cart/clear.js"):
- case e.url.includes("/cart.js"):
- r(e)
- }
- } catch (t) {
- a(t)
- }
- return e
- })
- })
- }(window, window.fetch)
- })
- }("undefined" != typeof global ? global : "undefined" != typeof window && window);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement