| 1 |
(function ($, elementor) { |
| 2 |
("use strict"); |
| 3 |
$(document).on("click", ".quick_view", function () { |
| 4 |
var product_id = $(this).data("id"); |
| 5 |
get_product_details(product_id); |
| 6 |
}); |
| 7 |
|
| 8 |
//woocommerce gallery |
| 9 |
$(document).on("click", ".thumbnails a", function (e) { |
| 10 |
var img_url = $(this).attr("data-href"); |
| 11 |
$(".usk-modal-image-wrapper .images > a").attr("href", img_url); |
| 12 |
$(".usk-modal-image-wrapper .images > a > img").attr({ |
| 13 |
src: img_url, |
| 14 |
srcset: img_url, |
| 15 |
}); |
| 16 |
}); |
| 17 |
$(document).on( |
| 18 |
"click", |
| 19 |
".usk-modal-page .usk-modal-product .images a", |
| 20 |
function (e) { |
| 21 |
e.preventDefault(); |
| 22 |
var img_url = $(this).attr("data-href"); |
| 23 |
var img_src = $(this).find("img").attr("srcset"); |
| 24 |
// $('.woocommerce-main-image').find('img').attr('src', img_url); |
| 25 |
// $('.woocommerce-main-image').find('img').attr('srcset', img_src); |
| 26 |
$(".woocommerce-main-image").closest("a").attr("href", img_url); |
| 27 |
|
| 28 |
$(".woocommerce-main-image").find("img").attr({ |
| 29 |
src: img_url, |
| 30 |
srcset: img_src, |
| 31 |
}); |
| 32 |
|
| 33 |
$("a.zoom").prettyPhoto({ |
| 34 |
hook: "data-rel", |
| 35 |
social_tools: false, |
| 36 |
theme: "pp_woocommerce", |
| 37 |
horizontal_padding: 20, |
| 38 |
opacity: 0.8, |
| 39 |
deeplinking: false, |
| 40 |
}); |
| 41 |
$("a[data-rel^='prettyPhoto']").prettyPhoto({ |
| 42 |
hook: "data-rel", |
| 43 |
social_tools: false, |
| 44 |
theme: "pp_woocommerce", |
| 45 |
horizontal_padding: 20, |
| 46 |
opacity: 0.8, |
| 47 |
deeplinking: false, |
| 48 |
}); |
| 49 |
} |
| 50 |
); |
| 51 |
|
| 52 |
function get_product_details(product_id) { |
| 53 |
if (product_id !== undefined) { |
| 54 |
jQuery.ajax({ |
| 55 |
type: "POST", |
| 56 |
url: ultimate_store_kit_ajax_config.ajaxurl, |
| 57 |
data: { |
| 58 |
action: "ultimate_store_kit_wc_product_quick_view_content", |
| 59 |
product_id: product_id, |
| 60 |
}, |
| 61 |
success: function (response) { |
| 62 |
setTimeout(function () { |
| 63 |
$("#quick-view-id").html(response); |
| 64 |
}, 1000); |
| 65 |
}, |
| 66 |
}); |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
$(".elementor-widget-usk-florence-grid").on( |
| 71 |
"click", |
| 72 |
".usk-pagination a", |
| 73 |
function (b) { |
| 74 |
b.preventDefault(); |
| 75 |
const requestUrl = $(this).prop("href"); |
| 76 |
$.ajax({ |
| 77 |
url: requestUrl, |
| 78 |
success: function (d) { |
| 79 |
var data = $(d).find(".elementor-widget-usk-florence-grid"); |
| 80 |
$(".elementor-widget-usk-florence-grid").html(data); |
| 81 |
if (window.history.pushState) { |
| 82 |
window.history.pushState({}, "", requestUrl); |
| 83 |
} |
| 84 |
}, |
| 85 |
}); |
| 86 |
} |
| 87 |
); |
| 88 |
|
| 89 |
// ======================================== |
| 90 |
// AJAX START |
| 91 |
// ======================================== |
| 92 |
|
| 93 |
$(".ajax_add_to_wishlist:not(.usk-active)").attr("href", "javascript:void(0);"); |
| 94 |
$(".ajax_add_to_wishlist").on("click", function (e) { |
| 95 |
// e.preventDefault(); |
| 96 |
var $this = $(this), |
| 97 |
$product_id = $this.data("product_id"), |
| 98 |
$redirect_url = $this.data("redirect_url"), |
| 99 |
$area_label = $this.data("aria_label"); |
| 100 |
$.ajax({ |
| 101 |
url: ultimate_store_kit_ajax_config.ajaxurl, |
| 102 |
data: { |
| 103 |
action: "usk_add_to_wishlist", |
| 104 |
product_id: $product_id, |
| 105 |
nonce: ultimate_store_kit_ajax_config.nonce, |
| 106 |
}, |
| 107 |
type: "POST", |
| 108 |
dataType: "JSON", |
| 109 |
success: function (response) { |
| 110 |
if (response.action === "added") { |
| 111 |
$this.addClass("usk-active").attr("aria-label", $area_label); |
| 112 |
$(".usk-wishlist-button") |
| 113 |
.find(".usk-wishlist-count") |
| 114 |
.html(response.count); |
| 115 |
|
| 116 |
$this.attr({ |
| 117 |
href: $redirect_url, |
| 118 |
}); |
| 119 |
} |
| 120 |
// else { |
| 121 |
// $this.removeClass("usk-active").attr("aria-label", response.message); |
| 122 |
// $this.attr({ |
| 123 |
// href: "javascript:void(0);", |
| 124 |
// }); |
| 125 |
// } |
| 126 |
}, |
| 127 |
error: function (response) { |
| 128 |
console.log(response); |
| 129 |
}, |
| 130 |
}); |
| 131 |
}); |
| 132 |
$(".ajax_remove_from_wishlist").on("click", function (e) { |
| 133 |
e.preventDefault(); |
| 134 |
var $this = $(this), |
| 135 |
$product_id = $this.data("product_id"); |
| 136 |
$.ajax({ |
| 137 |
url: ultimate_store_kit_ajax_config.ajaxurl, |
| 138 |
data: { |
| 139 |
action: "usk_remove_wishlist", |
| 140 |
product_id: $product_id, |
| 141 |
nonce: ultimate_store_kit_ajax_config.nonce, |
| 142 |
}, |
| 143 |
type: "POST", |
| 144 |
dataType: "JSON", |
| 145 |
success: function (response) { |
| 146 |
if (response.action == "removed") { |
| 147 |
$this.closest("tr").remove(); |
| 148 |
$(".usk-wishlist-button") |
| 149 |
.find(".usk-wishlist-count") |
| 150 |
.html(response.count); |
| 151 |
} |
| 152 |
}, |
| 153 |
error: function (response) { |
| 154 |
console.log(response); |
| 155 |
}, |
| 156 |
}); |
| 157 |
}); |
| 158 |
|
| 159 |
$(".ajax_add_to_compare:not(.usk-active)").attr("href", "javascript:void(0);"); |
| 160 |
$(".ajax_add_to_compare").on("click", function (e) { |
| 161 |
var $this = $(this), |
| 162 |
$product_id = $this.data("product_id"), |
| 163 |
$redirect_url = $this.data("redirect_url"), |
| 164 |
$area_label = $this.data("aria_label"); |
| 165 |
$.ajax({ |
| 166 |
url: ultimate_store_kit_ajax_config.ajaxurl, |
| 167 |
data: { |
| 168 |
action: "usk_add_to_compare_products", |
| 169 |
product_id: $product_id, |
| 170 |
nonce: ultimate_store_kit_ajax_config.nonce, |
| 171 |
}, |
| 172 |
type: "POST", |
| 173 |
dataType: "JSON", |
| 174 |
success: function (response) { |
| 175 |
if (response.action === "added") { |
| 176 |
|
| 177 |
$this.addClass("usk-active").attr("aria-label", $area_label); |
| 178 |
$(".usk-compare-button") |
| 179 |
.find(".usk-compare-count") |
| 180 |
.html(response.count); |
| 181 |
|
| 182 |
$this.attr({ |
| 183 |
href: $redirect_url, |
| 184 |
}); |
| 185 |
} |
| 186 |
// else { |
| 187 |
// $this.attr({ |
| 188 |
// href: "javascript:void(0);", |
| 189 |
// "aria-label": response.message, |
| 190 |
// }); |
| 191 |
// } |
| 192 |
}, |
| 193 |
error: function (response) { |
| 194 |
console.log(response); |
| 195 |
}, |
| 196 |
}); |
| 197 |
}); |
| 198 |
|
| 199 |
$(".ajax_add_to_cart").on("click", function (e) { |
| 200 |
e.preventDefault(); |
| 201 |
var $this = $(this); |
| 202 |
$this.attr("aria-label", "Added to cart"); |
| 203 |
}); |
| 204 |
// ======================================== |
| 205 |
// AJAX END |
| 206 |
// ======================================== |
| 207 |
$(document).ready(function () { |
| 208 |
var loader = `<div class="usk-bouncing-loader"><div></div><div></div><div></div></div>`; |
| 209 |
var width = $(".product-quick-view").data("modal-width"); |
| 210 |
var height = $(".product-quick-view").data("modal-height"); |
| 211 |
var animation = $(".product-quick-view").data("animation"); |
| 212 |
var close_btn = $(".product-quick-view").data("close-btn"); |
| 213 |
var btn_style = $(".product-quick-view").data("btn-style"); |
| 214 |
// var btn_place = $('.product-quick-view').data('btn-place'); |
| 215 |
var btn_text = $(".product-quick-view").data("btn-text"); |
| 216 |
var modal_bg = $(".product-quick-view").data("modal-bg"); |
| 217 |
var modal_overlay = $(".product-quick-view").data("modal-overlay"); |
| 218 |
$(".product-quick-view").SlickModals({ |
| 219 |
popup_reopenClass: "quick_view", |
| 220 |
popup_animation: animation, |
| 221 |
overlay_animation: animation, |
| 222 |
popup_closeButtonEnable: close_btn, |
| 223 |
popup_closeButtonStyle: btn_style, |
| 224 |
popup_closeButtonText: btn_text, |
| 225 |
popup_closeButtonPlace: "inside", |
| 226 |
popup_css: { |
| 227 |
width: width ? width + "px" : "800px", |
| 228 |
height: height ? height + "px" : "450px", |
| 229 |
background: modal_bg ? modal_bg : "#fff", |
| 230 |
"overflow-y": "auto", |
| 231 |
"animation-duration": "0.7s", |
| 232 |
}, |
| 233 |
overlay_css: { |
| 234 |
background: modal_overlay, |
| 235 |
}, |
| 236 |
mobile_breakpoint: "768px", |
| 237 |
mobile_position: "center", |
| 238 |
mobile_css: { |
| 239 |
width: "300px", |
| 240 |
padding: "30px", |
| 241 |
margin: "20px", |
| 242 |
}, |
| 243 |
callback_afterClose: function () { |
| 244 |
$("#quick-view-id").html(loader); |
| 245 |
}, |
| 246 |
callback_beforeOpen: function () { |
| 247 |
$("#quick-view-id").html(loader); |
| 248 |
}, |
| 249 |
}); |
| 250 |
}); |
| 251 |
|
| 252 |
// Each time quantity in the cart changes, trigger update |
| 253 |
// cart option |
| 254 |
jQuery(".usk-page-cart div.woocommerce").on("change", ".qty", function () { |
| 255 |
var $form = jQuery(this).closest(".woocommerce-cart-form"); |
| 256 |
var $updateButton = $form.find("[name='update_cart']"); |
| 257 |
|
| 258 |
$updateButton.prop("disabled", false); |
| 259 |
$updateButton.trigger("click"); |
| 260 |
}); |
| 261 |
})(jQuery, window.elementorFrontend); |
| 262 |
|