-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery-add-to-wishlist.min.js
54 lines (53 loc) · 6.7 KB
/
jquery-add-to-wishlist.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Name: Bloggger Add To Wishlist Plugin
var data_label, wishlist_empty = '<td class="wishlist-empty" colspan="6">' + wishlist.empty + "</td>";
$(document).ready(function() {
var t, a, e, s, l, i = [],
o = "",
d = "";
if ((data_icon_label = localStorage.getItem("data_icon_label")) ? ($(".header-wishlist-icon>a>i").attr("data-icon-label", data_icon_label), data_label = Number($(".header-wishlist-icon>a>i").attr("data-icon-label"))) : data_label = "0", $(".wishlist-article").each(function() {
t = $(this).find("button.wishlist-button"), $(t).one("click", function(t) {
t.preventDefault();
var i = $(this);
if (a = this.value, id_sp = this.value, data_label >= wishlist.item) {
var c = '<div class="show" id="modal--confirm"><div class="modal--dialog"><div class="_3em"></div><div class="modal--content"><div class="modal--header flex align-center"><div class="_mht">' + messages.alert + '</div><div class="_mhc modal--close"><svg viewBox="0 0 24 24"><path d="M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z"></path></svg></div></div><div class="modal--body"><div><p>' + wishlist.alert + '</p></div></div><div class="modal--footer"><button class="modal--close" type="button">' + messages.calcel + '</button><button class="modal--submit" type="submit">' + messages.accept + '</button></div></div><div class="_3em"></div></div></div>';
$(c).appendTo("body"), $("html").css("overflow", "hidden"), $(".modal--submit").click(function() { location.href = wishlist.url }), $(".modal--close").click(function() { $("html").removeAttr("style"), $("#modal--confirm").remove() })
} else $.ajax({
type: "GET",
url: "/feeds/posts/default/" + id_sp,
data: { alt: "json-in-script" },
dataType: "jsonp",
success: function(t) {
if (t.entry) {
for (var c = t.entry, r = 0; r < c.link.length; r++)
if ("alternate" == c.link[r].rel) { url_sp = c.link[r].href; break }
if ("category" in c) {
gia_sp = curr(c.category[0].term, ".", ",");
for (var n = 1; n < c.category.length; n++) {
var m = (o += c.category[n].term).indexOf(stock);
o.slice(m, Number(m) + stock.length) == stock ? (d = messages.outstock, l = "") : (d = messages.instock, l = '<button class="single_add_to_cart_button button alt" name="add-to-cart" type="button" value=' + id_sp + ' style="margin:0;">' + cart.add + "</button>")
}
}
"media$thumbnail" in c ? anh_sp = c.media$thumbnail.url.replace("s72-c", "s76") : "enclosure" == c.link[0].rel && ("image/png" != c.link[0].type && "image/jpg" != c.link[0].type && "image/jpeg" != c.link[0].type || (anh_sp = c.link[0].href)), ten_sp = c.title.$t, remove_item = cart.url + "?remove_item=" + id_sp, cart_item = '<tr><td class="product-remove"><a href=' + remove_item + ' class="remove" aria-label="Remove this item">×</a></td><td class="product-thumbnail"><a href=' + url_sp + '><img alt="' + ten_sp + '" src="' + anh_sp + '"></a></td><td class="product-name"><a href=' + url_sp + ">" + ten_sp + '</a><div class="show-for-small mobile-product-price"><span class="mobile-product-price__qty">1 x </span><span class="woocommerce-Price-amount amount">' + gia_sp + '</span><span class="woocommerce-Price-currencySymbol amount">' + dv_tt + '</span></div></td><td class="product-price"><span class="woocommerce-Price-amount amount">' + gia_sp + '</span><span class="woocommerce-Price-currencySymbol amount">' + dv_tt + '</span></td><th class="product-stock-status"><span class="nobr">' + d + '</span></th><td class="product-add-to-cart">' + l + "</td></tr>", data_label = Number(data_label) + 1, $(".header-wishlist-icon>a>i").addClass("added"), $(".header-wishlist-icon>a>i").attr("data-icon-label", data_label), localStorage.setItem("data_icon_label", data_label), i.addClass("loading"), i.parent().find(".add_to_wishlist").click(), setTimeout(function() { i.removeClass("loading"), i.addClass("wishlist-added"), $(".header-wishlist-icon>a>i").removeClass("added") }, 500), e = "<span id=" + a + "></span>", $("#wishlist-id").append(e), s = $("#wishlist-id").html(), localStorage.setItem("wishlist_added", s), $("table#wishlist_table>tbody").append(cart_item), wishlist_html = $("table#wishlist_table>tbody").html(), localStorage.setItem("wishlist_table_saved", wishlist_html)
}
}
})
})
}), s = localStorage.getItem("wishlist_added")) {
$("#wishlist-id").html(s);
for (var c = document.querySelector("#wishlist-id").getElementsByTagName("span"), r = 0; r < c.length; r++) i.push(c[r].id);
$(".wishlist-button").hover(function() {
var t = $(this);
a = t.attr("value"), i.includes(a) && (t.parent().find(".yith-wcwl-add-button").removeClass("show").addClass("hide"), t.parent().find(".yith-wcwl-wishlistaddedbrowse").removeClass("hide").addClass("show"), t.unbind("click"))
})
}
if (wishlist_html = localStorage.getItem("wishlist_table_saved")) {
$("table#wishlist_table>tbody").html(wishlist_html), $("table.wishlist_table>tbody").html(wishlist_html);
var n = $("table.wishlist_table>tbody").children("tr").size();
$("table.wishlist_table>tbody>tr").each(function() {
var t = $(this),
a = $(this).find("td.product-remove a");
$(a).click(function(e) { e.preventDefault(), t.parent().addClass("processing"), n -= 1, setTimeout(function() { $(".header-wishlist-icon>a>i").attr("data-icon-label", data_label - 1), $(a).parent().parent().remove(), wishlist_html = $("table.wishlist_table>tbody").html(), localStorage.setItem("wishlist_table_saved", wishlist_html), data_label = Number($(".header-wishlist-icon>a>i").attr("data-icon-label")), localStorage.setItem("data_icon_label", data_label), 0 == n && ($(".header-wishlist-icon>a>i").attr("data-icon-label", 0), $("table#wishlist_table>tbody").html(wishlist_empty), data_label = Number($(".header-wishlist-icon>a>i").attr("data-icon-label")), $("table.wishlist_table>tbody").html(wishlist_empty), localStorage.setItem("data_icon_label", data_label), localStorage.removeItem("wishlist_table_saved"), localStorage.removeItem("wishlist_added")), $(".processing").removeClass("processing") }, 500) })
})
}
});
1