{"size": 23811, "ext": "js", "max_stars_repo_path": "public/javascripts/expressCart.min.js", "max_stars_repo_name": "GomezAgustin12/zencast-ecommerce", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "public/javascripts/expressCart.min.js", "max_issues_repo_name": "GomezAgustin12/zencast-ecommerce", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "public/javascripts/expressCart.min.js", "max_forks_repo_name": "GomezAgustin12/zencast-ecommerce", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 40.0858585859, "max_line_length": 2711, "alphanum_fraction": 0.4375708706}
function checkMaxQuantity(t, a) {
  if ($("#maxQuantity").length) {
    if (t.keyCode === 46 || t.keyCode === 8) return;
    if (parseInt($(t.target).val()) > parseInt($("#maxQuantity").val())) {
      const e = a.val();
      t.preventDefault(),
        a.val(e.slice(0, -1)),
        showNotification(
          `Exceeds maximum quantity: ${$("#maxQuantity").val()}`,
          "warning",
          !1
        );
    }
  }
}
function deleteFromCart(t) {
  $.ajax({
    method: "POST",
    url: "/product/removefromcart",
    data: { cartId: t.attr("data-cartid") },
  })
    .done((t) => {
      updateCartDiv(), showNotification(t.message, "success");
    })
    .fail((t) => {
      showNotification(t.responseJSON.message, "danger");
    });
}
function cartUpdate(t) {
  $(t).val() > 0 ? $(t).val() !== "" && updateCart(t) : $(t).val(1);
}
function updateCart(t) {
  $.ajax({
    method: "POST",
    url: "/product/updatecart",
    data: {
      cartId: t.attr("data-cartid"),
      productId: t.attr("data-id"),
      quantity: t.val(),
    },
  })
    .done((t) => {
      updateCartDiv();
    })
    .fail((t) => {
      showNotification(t.responseJSON.message, "danger", !0);
    });
}
function updateCartDiv() {
  $.ajax({ method: "GET", url: "/checkout/cartData" })
    .done((t) => {
      const a = t.cart;
        const e = t.session;
        let n = "";
        const o = numeral(e.totalCartAmount).format("0.00");
        const i = numeral(e.totalCartShipping).format("0.00");
        let r = `${e.shippingMessage} :<strong id="shipping-amount">${t.currencySymbol}${i}</strong>`;
      e.totalCartShipping === 0 &&
        (r = `<span id="shipping-amount">${e.shippingMessage}</span>`);
      const c = numeral(e.totalCartDiscount).format("0.00");
        let s = "";
      e.totalCartDiscount > 0 &&
        (s = `\n                <div class="text-right">\n                    Discount: <strong id="discount-amount">${t.currencySymbol}${c}</strong>\n                </div>`),
        a
          ? ($("#cart-empty").empty(),
            Object.keys(a).forEach((e) => {
              const o = a[e];
                const i = numeral(o.totalItemPrice).format("0.00");
                let r = "";
              o.variantId &&
                (r += `<strong>Option:</strong> ${o.variantTitle}`);
              let c = `<img class="img-fluid" src="/uploads/placeholder.png" alt="${o.title} product image"></img>`;
              o.productImage &&
                (c = `<img class="img-fluid" src="${o.productImage}" alt="${o.title} product image"></img>`),
                (n += `\n                <div class="d-flex flex-row bottom-pad-15">\n                    <div class="p-2 cart-product">\n                        <div class="row h-200">\n                            <div class="col-4 col-md-3 no-pad-left">\n                                ${c}\n                            </div>\n                            <div class="col-8 col-md-9">\n                                <div class="row">\n                                    <div class="col-12 no-pad-left mt-md-4">\n                                        <h6><a href="/product/${o.link}">${o.title}</a></h6>\n                                        ${r}\n                                    </div>\n                                    <div class="col-12 col-md-6 no-pad-left mb-2">\n                                        <div class="input-group">\n                                            <div class="input-group-prepend">\n                                                <button class="btn btn-primary btn-qty-minus" type="button">-</button>\n                                            </div>\n                                            <input \n                                                type="number" \n                                                class="form-control cart-product-quantity text-center"\n                                                data-cartid="${e}"\n                                                data-id="${o.productId}" \n                                                maxlength="2" \n                                                value="${o.quantity}"\n                                            >\n                                            <div class="input-group-append">\n                                                <button class="btn btn-primary btn-qty-add" type="button">+</button>\n                                            </div>\n                                        </div>\n                                    </div>\n                                    <div class="col-4 col-md-2 no-pad-left">\n                                        <button class="btn btn-danger btn-delete-from-cart" data-cartid="${e}" type="button"><i class="feather" data-feather="trash-2" data-cartid="${e}"></i></button>\n                                    </div>\n                                    <div class="col-8 col-md-4 align-self-center text-right">\n                                        <strong class="my-auto">${t.currencySymbol}${i}</strong>\n                                    </div>\n                                </div>\n                            </div>\n                        </div>\n                    </div>\n                </div>`);
            }),
            $(".cartBodyWrapper").html(n))
          : $(".cartBodyWrapper").html(""),
        $("#cart-count").text(e.totalCartItems);
      const d = `\n            <div class="d-flex flex-row">\n                <div class="cart-contents-shipping col-md-12 no-pad-right">\n                    <div class="text-right">\n                        ${r}\n                    </div>\n                    ${s}\n                    <div class="text-right">\n                        Total:\n                        <strong id="total-cart-amount">${t.currencySymbol}${o}</strong>\n                    </div>\n                </div>\n            </div>`;
      a
        ? ($(".cartTotalsWrapper").html(d),
          $(".cart-buttons").removeClass("d-none"))
        : ($(".cartTotalsWrapper").html(
            '\n            <div id="cart-empty" class="d-flex flex-row">\n                <div class="cart-contents-shipping col-md-12 no-pad-left>\n                    Cart empty\n                </div>\n            </div>'
          ),
          $(".cart-buttons").addClass("d-none")),
        feather.replace();
    })
    .fail((t) => {
      showNotification(t.responseJSON.message, "danger");
    });
}
function emptyCart() {
  $.ajax({ method: "POST", url: "/product/emptycart" }).done((t) => {
    updateCartDiv(), showNotification(t.message, "success", !0);
  });
}
$(document).ready(() => {
  if (
    ($(window).width() < 768 &&
      ($(".menu-side").on("click", (t) => {
        t.preventDefault(), $('.menu-side li:not(".active")').slideToggle();
      }),
      $('.menu-side li:not(".active")').hide(),
      $(".menu-side>.active").html(
        '<i class="feather" data-feather="menu"></i>'
      ),
      $(".menu-side>.active").addClass("menu-side-mobile"),
      $("#navbar ul li").length === 0 && $("#navbar").hide(),
      $("#offcanvasClose").hide()),
    $("#userSetupForm")
      .validator()
      .on("submit", (t) => {
        t.isDefaultPrevented() ||
          (t.preventDefault(),
          $.ajax({
            method: "POST",
            url: "/admin/setup_action",
            data: {
              usersName: $("#usersName").val(),
              userEmail: $("#userEmail").val(),
              userPassword: $("#userPassword").val(),
            },
          })
            .done((t) => {
              showNotification(t.message, "success", !1, "/admin/login");
            })
            .fail((t) => {
              showNotification(t.responseJSON.message, "danger");
            }));
      }),
    $(document).on("click", ".menu-btn", (t) => {
      t.preventDefault(), $("body").addClass("pushy-open-right");
    }),
    $("table").each(function () {
      $(this).addClass("table table-hover");
    }),
    $("#productTags").length && $("#productTags").tokenfield(),
    $(document)
      .on("click", ".dashboard_list", function (t) {
        window.document.location = $(this).attr("href");
      })
      .hover(function () {
        $(this).toggleClass("hover");
      }),
    $(document).on("click", ".btn-qty-minus", (t) => {
      t.preventDefault();
      const a = $(t.target).parent().parent().find(".cart-product-quantity");
      $(a).val(parseInt(a.val()) - 1), cartUpdate(a);
    }),
    $(document).on("click", ".btn-qty-add", (t) => {
      t.preventDefault();
      const a = $(t.target).parent().parent().find(".cart-product-quantity");
      $(a).val(parseInt(a.val()) + 1), cartUpdate(a);
    }),
    $(document).on("click", ".btn-delete-from-cart", (t) => {
      deleteFromCart($(t.target));
    }),
    $("#pager").length)
  ) {
    const t = $("#pageNum").val();
      const a = $("#itemsPerPage").val();
      const e = $("#totalItemCount").val();
      const n = $("#paginateUrl").val();
      let o = $("#searchTerm").val();
    o !== "" && (o += "/");
    const i = `/${n}/${o}{{number}}`;
      const r = Math.ceil(e / a);
    parseInt(e) > parseInt(a) &&
      ($("#pager").bootpag({
        total: r,
        page: t,
        maxVisible: 5,
        href: i,
        wrapClass: "pagination",
        prevClass: "page-item previous",
        nextClass: "page-item next",
        activeClass: "page-item active",
      }),
      $("#pager a").each(function () {
        $(this).addClass("page-link");
      }));
  }
  if (
    ($("#customerLogout").on("click", (t) => {
      $.ajax({ method: "POST", url: "/customer/logout", data: {} }).done(
        (t) => {
          location.reload();
        }
      );
    }),
    $("#customerForgotten")
      .validator()
      .on("submit", (t) => {
        t.isDefaultPrevented() ||
          (t.preventDefault(),
          $.ajax({
            method: "POST",
            url: "/customer/forgotten_action",
            data: { email: $("#email").val() },
          })
            .done((t) => {
              showNotification(t.message, "success");
            })
            .fail((t) => {
              t.message
                ? showNotification(t.responseJSON.message, "danger")
                : showNotification(t.responseText, "danger");
            }));
      }),
    $(document).on("click", "#createAccountCheckbox", (t) => {
      $("#newCustomerPassword").prop(
        "required",
        $("#createAccountCheckbox").prop("checked")
      );
    }),
    $("#checkoutInformation")
      .validator()
      .on("click", (t) => {
        if (
          (t.preventDefault(),
          $("#shipping-form").validator("validate").has(".has-error").length ===
            0)
        ) {
          let a = "/customer/save";
          $("#createAccountCheckbox").prop("checked") &&
            (a = "/customer/create"),
            $.ajax({
              method: "POST",
              url: a,
              data: {
                email: $("#shipEmail").val(),
                company: $("#shipCompany").val(),
                firstName: $("#shipFirstname").val(),
                lastName: $("#shipLastname").val(),
                address1: $("#shipAddr1").val(),
                address2: $("#shipAddr2").val(),
                country: $("#shipCountry").val(),
                state: $("#shipState").val(),
                postcode: $("#shipPostcode").val(),
                phone: $("#shipPhoneNumber").val(),
                password: $("#newCustomerPassword").val(),
                orderComment: $("#orderComment").val(),
              },
            })
              .done(() => {
                window.location = "/checkout/shipping";
              })
              .fail((t) => {
                showNotification(t.responseJSON.message, "danger");
              });
        }
      }),
    $("#adddiscountcode").on("click", (t) => {
      t.preventDefault(),
        $.ajax({
          method: "POST",
          url: "/checkout/adddiscountcode",
          data: { discountCode: $("#discountCode").val() },
        })
          .done((t) => {
            showNotification(t.message, "success", !0);
          })
          .fail((t) => {
            showNotification(t.responseJSON.message, "danger");
          });
    }),
    $("#removediscountcode").on("click", (t) => {
      t.preventDefault(),
        $.ajax({
          method: "POST",
          url: "/checkout/removediscountcode",
          data: {},
        })
          .done((t) => {
            showNotification(t.message, "success", !0);
          })
          .fail((t) => {
            showNotification(t.responseJSON.message, "danger");
          });
    }),
    $("#loginForm").on("click", (t) => {
      t.isDefaultPrevented() ||
        (t.preventDefault(),
        $.ajax({
          method: "POST",
          url: "/admin/login_action",
          data: { email: $("#email").val(), password: $("#password").val() },
        })
          .done((t) => {
            window.location = "/admin";
          })
          .fail((t) => {
            showNotification(t.responseJSON.message, "danger");
          })),
        t.preventDefault();
    }),
    $("#customerloginForm").on("click", (t) => {
      t.isDefaultPrevented() ||
        (t.preventDefault(),
        $.ajax({
          method: "POST",
          url: "/customer/login_action",
          data: {
            loginEmail: $("#email").val(),
            loginPassword: $("#password").val(),
          },
        })
          .done((t) => {
            window.location = "/customer/account";
          })
          .fail((t) => {
            showNotification(t.responseJSON.message, "danger");
          })),
        t.preventDefault();
    }),
    $("#customerLogin").on("click", (t) => {
      t.isDefaultPrevented() ||
        (t.preventDefault(),
        $.ajax({
          method: "POST",
          url: "/customer/login_action",
          data: {
            loginEmail: $("#customerLoginEmail").val(),
            loginPassword: $("#customerLoginPassword").val(),
          },
        })
          .done((t) => {
            const a = t.customer;
            $("#shipEmail").val(a.email),
              $("#shipFirstname").val(a.firstName),
              $("#shipLastname").val(a.lastName),
              $("#shipAddr1").val(a.address1),
              $("#shipAddr2").val(a.address2),
              $("#shipCountry").val(a.country),
              $("#shipState").val(a.state),
              $("#shipPostcode").val(a.postcode),
              $("#shipPhoneNumber").val(a.phone),
              location.reload();
          })
          .fail((t) => {
            showNotification(t.responseJSON.message, "danger");
          })),
        t.preventDefault();
    }),
    $("#customerSave")
      .validator()
      .on("click", (t) => {
        t.preventDefault(),
          $("#customer-form").validator("validate").has(".has-error")
              .length ===
            0 &&
            $.ajax({
              method: "PUT",
              url: "/customer/update",
              data: {
                email: $("#shipEmail").val(),
                company: $("#shipCompany").val(),
                firstName: $("#shipFirstname").val(),
                lastName: $("#shipLastname").val(),
                address1: $("#shipAddr1").val(),
                address2: $("#shipAddr2").val(),
                country: $("#shipCountry").val(),
                state: $("#shipState").val(),
                postcode: $("#shipPostcode").val(),
                phone: $("#shipPhoneNumber").val(),
                password: $("#newCustomerPassword").val(),
                orderComment: $("#orderComment").val(),
              },
            })
              .done(() => {
                showNotification("Customer saved", "success");
              })
              .fail((t) => {
                showNotification(t.responseJSON.message, "danger");
              });
      }),
    $(document).on("click", ".image-next", (t) => {
      const a = $(".thumbnail-image");
        let e = 0;
        let n = 0;
      $(".thumbnail-image").each(function () {
        $("#product-title-image").attr("src") === $(this).attr("src") &&
          (n = e + 1 === a.length || e + 1 < 0 ? 0 : e + 1),
          e++;
      }),
        $("#product-title-image").attr("src", $(a).eq(n).attr("src"));
    }),
    $(document).on("click", ".image-prev", (t) => {
      const a = $(".thumbnail-image");
        let e = 0;
        let n = 0;
      $(".thumbnail-image").each(function () {
        $("#product-title-image").attr("src") === $(this).attr("src") &&
          (n = e - 1 === a.length || e - 1 < 0 ? a.length - 1 : e - 1),
          e++;
      }),
        $("#product-title-image").attr("src", $(a).eq(n).attr("src"));
    }),
    $(document).on("change", "#product_variant", function (t) {
      const a = $(this).find(":selected").attr("data-price");
        const e = $("#currencySymbol").val();
      $("h4.product-price:first").html(e + a);
    }),
    $(document).on("click", ".add-variant-to-cart", function (t) {
      $.ajax({
        method: "POST",
        url: "/product/addtocart",
        data: {
          productId: $(this).attr("data-id"),
          productQuantity: "1",
          productVariant: $(`#productVariant-${$(this).attr("data-id")}`).val(),
        },
      })
        .done((t) => {
          updateCartDiv(), showNotification(t.message, "success");
        })
        .fail((t) => {
          showNotification(t.responseJSON.message, "danger");
        });
    }),
    $(document).on("click", ".product-add-to-cart", (t) => {
      parseInt($("#product_quantity").val()) < 1 &&
        $("#product_quantity").val(1),
        $.ajax({
          method: "POST",
          url: "/product/addtocart",
          data: {
            productId: $("#productId").val(),
            productQuantity: $("#product_quantity").val(),
            productVariant: $("#product_variant").val(),
            productComment: $("#product_comment").val(),
          },
        })
          .done((t) => {
            updateCartDiv(), showNotification(t.message, "success");
          })
          .fail((t) => {
            showNotification(t.responseJSON.message, "danger");
          });
    }),
    $("#product_quantity").on("keyup", (t) => {
      checkMaxQuantity(t, $("#product_quantity"));
    }),
    $(".cart-product-quantity").on("keyup", (t) => {
      checkMaxQuantity(t, $(".cart-product-quantity"));
    }),
    $(".cart-product-quantity").on("focusout", (t) => {
      cartUpdate($(t.target));
    }),
    $(document).on("click", ".pushy-link", (t) => {
      $("body").removeClass("pushy-open-right");
    }),
    $(document).on("click", ".add-to-cart", function (t) {
      let a = `/product/${$(this).attr("data-id")}`;
      $(this).attr("data-link") &&
        (a = `/product/${$(this).attr("data-link")}`),
        $(this).attr("data-has-variants") === "true"
          ? (window.location = a)
          : $.ajax({
              method: "POST",
              url: "/product/addtocart",
              data: { productId: $(this).attr("data-id") },
            })
              .done((t) => {
                updateCartDiv(), showNotification(t.message, "success");
              })
              .fail((t) => {
                showNotification(t.responseJSON.message, "danger");
              });
    }),
    $(document).on("click", "#add-review", (t) => {
      $.ajax({ method: "POST", url: "/customer/check", data: {} })
        .done((t) => {
          $("#reviewModal").modal("show");
        })
        .fail(() => {
          showNotification(
            "You need to be logged in to create a review",
            "danger",
            !1,
            "/customer/account"
          );
        });
    }),
    $(document).on("click", "#addReview", (t) => {
      $.ajax({
        method: "POST",
        url: "/product/addreview",
        data: {
          product: $("#product").val(),
          title: $("#review-title").val(),
          description: $("#review-description").val(),
          rating: $("#review-rating").val(),
        },
      })
        .done((t) => {
          showNotification(t.message, "success", !0);
        })
        .fail((t) => {
          t.responseJSON.message ===
            "You need to be logged in to create a review" &&
            showNotification(
              t.responseJSON.message,
              "danger",
              !1,
              "/customer/account"
            ),
            showNotification(t.responseJSON.message, "danger");
        });
    }),
    $(document).on("click", "#empty-cart", (t) => {
      $("#confirmModal").modal("show"),
        $("#buttonConfirm").attr("data-func", "emptyCart");
    }),
    $(document).on("click", "#buttonConfirm", (t) => {
      const a = $(t.target).attr("data-func");
      window[a](), $("#confirmModal").modal("hide");
    }),
    $(".qty-btn-minus").on("click", () => {
      const t = parseInt($("#product_quantity").val()) - 1;
      $("#product_quantity").val(t > 0 ? t : 1);
    }),
    $(".qty-btn-plus").on("click", () => {
      $("#product_quantity").val(parseInt($("#product_quantity").val()) + 1);
    }),
    $(".thumbnail-image").on("click", function () {
      $("#product-title-image").attr("src", $(this).attr("src"));
    }),
    $(document).on("click", "#btn_search_reset", (t) => {
      window.location.replace("/");
    }),
    $(document).on("click", "#btn_search", (t) => {
      t.preventDefault(),
        $("#frm_search").val().trim() === ""
          ? showNotification("Please enter a search value", "danger")
          : (window.location.href = `/search/${$("#frm_search").val()}`);
    }),
    $("#input_notify_message").val() !== "")
  ) {
    const c = $("#input_notify_message").val();
      const s = $("#input_notify_messageType").val();
    $("#input_notify_message").val(""),
      $("#input_notify_messageType").val(""),
      showNotification(c, s || "danger", !1);
  }
  if ($("#blockonomics_div").length > 0) {
    const d = $("#blockonomics_div").data("orderid") || "";
      const l = $("#blockonomics_div").data("timestamp") || -1;
      const u = $("#blockonomics_div").data("address") || "";
      const m = new WebSocket(
        `wss://www.blockonomics.co/payment/${u}?timestamp=${l}`
      );
    m.onopen = function (t) {};
    setTimeout(() => {
      $("#blockonomics_waiting").html(
        "<b>Payment expired</b><br><br><b><a href='/checkout/payment'>Click here</a></b> to try again.<br><br>If you already paid, your order will be processed automatically."
      ),
        showNotification("Payment expired", "danger"),
        m.close();
    }, 6e5);
    const p = $("#blockonomics_timeout");
      const f = new Date(new Date().getTime() + 6e5);
      var v = setInterval(() => {
        const t = new Date().getTime();
          const a = f - t;
        if (a < 0) clearInterval(v);
        else {
          const e = Math.floor((a % 36e5) / 6e4);
            const n = Math.floor((a % 6e4) / 1e3);
          p.html(`${e}m ${n}s`);
        }
      }, 1e3);
    m.onmessage = function (t) {
      const a = JSON.parse(t.data);
      if (a.status === 0 || a.status === 1 || a.status === 2) {
        const e = `<br>View <b><a href="/payment/${d}">Order</a></b>`;
        $("#blockonomics_waiting").html(
          `Payment detected (<b>${a.value / 1e8} BTC</b>).${e}`
        ),
          showNotification("Payment detected", "success"),
          $("#cart-count").html("0"),
          m.close(),
          $.ajax({ method: "POST", url: "/product/emptycart" }).done(
            () => {
              window.location.replace(`/payment/${d}`);
            }
          );
      }
    };
  }
});
