(function ($, window){
"use strict";
var WooLentorBlocks={
init: function (){
this.TabsMenu($(".ht-tab-menus"), ".ht-tab-pane");
this.TabsMenu($(".woolentor-product-video-tabs"), ".video-cus-tab-pane");
if($("[class*='woolentorblock-'] .ht-product-image-slider").length > 0){
this.productImageThumbnailsSlider($(".ht-product-image-slider"));
}
this.thumbnailsimagescontroller();
this.ThumbNailsTabs(".woolentor-thumbanis-image",
".woolentor-advance-product-image-area"
);
},
TabsMenu: function ($tabmenus, $tabpane){
$tabmenus.on("click", "a", function (e){
e.preventDefault();
var $this=$(this),
$target=$this.attr("href");
$this
.addClass("htactive")
.parent()
.siblings()
.children("a")
.removeClass("htactive");
$($tabpane + $target)
.addClass("htactive")
.siblings()
.removeClass("htactive");
if($(".slick-slider").length > 0){
var $id=$this.attr("href");
$($id).find(".slick-slider").slick("refresh");
}});
},
ThumbNailsTabs: function ($tabmenu, $area){
$($tabmenu).on("click", "li", function (e){
e.preventDefault();
var $image=$(this).data("wlimage");
if($image){
$($area)
.find(".woocommerce-product-gallery__image .wp-post-image")
.attr("src", $image);
$($area)
.find(".woocommerce-product-gallery__image .wp-post-image")
.attr("srcset", $image);
}});
},
initSlickSlider: function ($block){
$($block).css("display", "block");
var settings=WooLentorBlocks.sanitizeObject($($block).data("settings"));
if(settings){
var arrows=settings["arrows"];
var dots=settings["dots"];
var autoplay=settings["autoplay"];
var rtl=settings["rtl"];
var autoplay_speed=parseInt(settings["autoplay_speed"])||3000;
var animation_speed=parseInt(settings["animation_speed"])||300;
var fade=false;
var pause_on_hover=settings["pause_on_hover"];
var display_columns=parseInt(settings["product_items"])||4;
var scroll_columns=parseInt(settings["scroll_columns"])||4;
var tablet_width=parseInt(settings["tablet_width"])||800;
var tablet_display_columns =
parseInt(settings["tablet_display_columns"])||2;
var tablet_scroll_columns =
parseInt(settings["tablet_scroll_columns"])||2;
var mobile_width=parseInt(settings["mobile_width"])||480;
var mobile_display_columns =
parseInt(settings["mobile_display_columns"])||1;
var mobile_scroll_columns =
parseInt(settings["mobile_scroll_columns"])||1;
$($block)
.not(".slick-initialized")
.slick({
arrows: arrows,
prevArrow:
'<button type="button" class="slick-prev" aria-label="Previous slide"><i class="fa fa-angle-left" aria-hidden="true"></i></button>',
nextArrow:
'<button type="button" class="slick-next" aria-label="Next slide"><i class="fa fa-angle-right" aria-hidden="true"></i></button>',
dots: dots,
infinite: true,
autoplay: autoplay,
autoplaySpeed: autoplay_speed,
speed: animation_speed,
fade: fade,
pauseOnHover: pause_on_hover,
slidesToShow: display_columns,
slidesToScroll: scroll_columns,
rtl: rtl,
responsive: [
{
breakpoint: tablet_width,
settings: {
slidesToShow: tablet_display_columns,
slidesToScroll: tablet_scroll_columns,
},
},
{
breakpoint: mobile_width,
settings: {
slidesToShow: mobile_display_columns,
slidesToScroll: mobile_scroll_columns,
},
},
],
});
$($block).find(".slick-track").removeAttr("role");
}},
initSlickNavForAsSlider: function ($sliderwrap){
$($sliderwrap).find(".woolentor-learg-img").css("display", "block");
$($sliderwrap).find(".woolentor-thumbnails").css("display", "block");
var settings=WooLentorBlocks.sanitizeObject($($sliderwrap).data("settings"));
if(settings){
$($sliderwrap)
.find(".woolentor-learg-img")
.not(".slick-initialized")
.slick({
slidesToShow: 1,
slidesToScroll: 1,
dots: settings["mainslider"].dots,
arrows: settings["mainslider"].arrows,
fade: false,
asNavFor: ".woolentor-thumbnails",
prevArrow:
'<button type="button" class="woolentor-slick-large-prev" aria-label="Previous image"><i class="sli sli-arrow-left" aria-hidden="true"></i></button>',
nextArrow:
'<button type="button" class="woolentor-slick-large-next" aria-label="Next image"><i class="sli sli-arrow-right" aria-hidden="true"></i></button>',
});
$($sliderwrap)
.find(".woolentor-thumbnails")
.not(".slick-initialized")
.slick({
slidesToShow: settings["thumbnailslider"].slider_items,
slidesToScroll: 1,
asNavFor: ".woolentor-learg-img",
centerMode: false,
dots: false,
arrows: settings["thumbnailslider"].arrows,
vertical: settings["thumbnailslider"].slidertype,
focusOnSelect: true,
prevArrow:
'<button type="button" class="woolentor-slick-prev" aria-label="Previous thumbnail"><i class="sli sli-arrow-left" aria-hidden="true"></i></button>',
nextArrow:
'<button type="button" class="woolentor-slick-next" aria-label="Next thumbnail"><i class="sli sli-arrow-right" aria-hidden="true"></i></button>',
});
$($sliderwrap).find(".slick-track").removeAttr("role");
}},
initAccordion: function ($block){
var settings=$($block).data("settings");
if($block.length > 0){
var $id=$block.attr("id");
new Accordion("#" + $id, {
duration: 500,
showItem: settings.showitem,
elementClass: "htwoolentor-faq-card",
questionClass: "htwoolentor-faq-head",
answerClass: "htwoolentor-faq-body",
});
}},
sanitizeHTML: function (str){
if(str){
return str.replace(/[&<>"']/g, function (c){
switch (c){
case '&': return '&amp;';
case '<': return '&lt;';
case '>': return '&gt;';
case '"': return '&quot;';
case "'": return '&#39;';
default: return c;
}});
}else{
return '';
}},
sanitizeObject: function (inputObj){
const sanitizedObj={};
for (let key in inputObj){
if(inputObj.hasOwnProperty(key)){
let value=inputObj[key];
if(typeof value==='string'){
sanitizedObj[key]=WooLentorBlocks.sanitizeHTML(value);
}else if(typeof value==='number'){
sanitizedObj[key]=Number.isFinite(value) ? value:0;
}else if(typeof value==='boolean'){
sanitizedObj[key]=value;
}else{
sanitizedObj[key]=value;
}}
}
return sanitizedObj;
},
woolentorToolTips: function (element, content){
if(content=="html"){
var tipText=element.text();
}else{
var tipText=element.attr("title");
}
element.on("mouseover", function (){
if($(".woolentor-tip").length==0){
element.before('<span class="woolentor-tip">' + WooLentorBlocks.sanitizeHTML(tipText) + "</span>");
$(".woolentor-tip").css("transition", "all 0.5s ease 0s");
$(".woolentor-tip").css("margin-left", 0);
}});
element.on("mouseleave", function (){
$(".woolentor-tip").remove();
});
},
woolentorToolTipHandler: function (){
$("a.woolentor-compare").each(function (){
WooLentorBlocks.woolentorToolTips($(this), "title");
});
$(
".woolentor-cart a.add_to_cart_button,.woolentor-cart a.added_to_cart,.woolentor-cart a.button"
).each(function (){
WooLentorBlocks.woolentorToolTips($(this), "html");
});
},
productImageThumbnailsSlider: function ($slider){
$slider.slick({
dots: true,
arrows: true,
prevArrow:
'<button type="button" class="slick-prev" aria-label="Previous image"><i class="sli sli-arrow-left" aria-hidden="true"></i></button>',
nextArrow:
'<button type="button" class="slick-next" aria-label="Next image"><i class="sli sli-arrow-right" aria-hidden="true"></i></button>',
});
$slider.find(".slick-track").removeAttr("role");
},
thumbnailsimagescontroller: function (){
this.TabsMenu($(".ht-product-cus-tab-links"), ".ht-product-cus-tab-pane");
this.TabsMenu($(".ht-tab-menus"), ".ht-tab-pane");
$(".ht-product-countdown").each(function (){
var $this=$(this),
finalDate=$(this).data("countdown");
var customlavel=$(this).data("customlavel");
$this.countdown(finalDate, function (event){
$this.html(event.strftime('<div class="cd-single"><div class="cd-single-inner"><h3>%D</h3><p>' +
WooLentorBlocks.sanitizeHTML(customlavel.daytxt) +
'</p></div></div><div class="cd-single"><div class="cd-single-inner"><h3>%H</h3><p>' +
WooLentorBlocks.sanitizeHTML(customlavel.hourtxt) +
'</p></div></div><div class="cd-single"><div class="cd-single-inner"><h3>%M</h3><p>' +
WooLentorBlocks.sanitizeHTML(customlavel.minutestxt) +
'</p></div></div><div class="cd-single"><div class="cd-single-inner"><h3>%S</h3><p>' +
WooLentorBlocks.sanitizeHTML(customlavel.secondstxt) +
"</p></div></div>"
)
);
});
});
},
quantityIncreaseDescrease: function ($area){
$area
.find("form.cart")
.on("click",
"span.wl-quantity-plus, span.wl-quantity-minus",
function (){
const poductType=$area.data("producttype");
if("grouped"!=poductType){
var qty=$(this).closest("form.cart").find(".qty:visible");
var val=parseFloat(qty.val());
var min_val=1;
}else{
var qty=$(this)
.closest(".wl-quantity-grouped-cal")
.find(".qty:visible");
var val = !qty.val() ? 0:parseFloat(qty.val());
var min_val=0;
}
var max=parseFloat(qty.attr("max"));
var min=parseFloat(qty.attr("min"));
var step=parseFloat(qty.attr("step"));
if($(this).is(".wl-quantity-plus")){
if(max&&max <=val){
qty.val(max);
}else{
qty.val(val + step);
}}else{
if(min&&min >=val){
qty.val(min);
}else if(val > min_val){
qty.val(val - step);
}}
}
);
},
CartTableHandler: function (){
$('body').on("click", '.woolentor-cart-product-details-toggle', function (e){
e.preventDefault();
const $target=$(this).data('target');
if($(`[data-id="${$target}"]`).is(':hidden')){
$(`[data-id="${$target}"]`).slideDown();
}else{
$(`[data-id="${$target}"]`).slideUp();
}});
},
viewSwitcher: function($grid, $selector, $style='modern'){
const $viewButtons=$grid.find('.woolentor-layout-btn');
if($viewButtons.length===0){
return;
}
$viewButtons.on('click', function(e){
e.preventDefault();
const $this=$(this);
const layout=$this.data('layout');
const $gridContainer=$this.closest('.woolentor-product-grid, .woolentor-filters-enabled').find($selector);
$this.siblings().removeClass('woolentor-active');
$this.addClass('woolentor-active');
if($gridContainer.length > 0){
$gridContainer.removeClass('woolentor-layout-grid woolentor-layout-list');
$gridContainer.addClass('woolentor-layout-' + layout);
$gridContainer.attr('data-show-layout', layout);
const $productCards=$gridContainer.find('.woolentor-product-card');
$productCards.removeClass('woolentor-grid-card woolentor-list-card');
if(layout==='grid'){
if($style==='editorial'){
$productCards.removeClass('woolentor-editorial-list-card');
$productCards.addClass('woolentor-editorial-grid-card');
}else if($style==='magazine'){
$productCards.removeClass('woolentor-magazine-list-card');
$productCards.addClass('woolentor-magazine-grid-card');
}else{
$productCards.addClass('woolentor-grid-card');
}}else if(layout==='list'){
if($style==='editorial'){
$productCards.removeClass('woolentor-editorial-grid-card');
$productCards.addClass('woolentor-editorial-list-card');
}else if($style==='magazine'){
$productCards.removeClass('woolentor-magazine-grid-card');
$productCards.addClass('woolentor-magazine-list-card');
}else{
$productCards.addClass('woolentor-list-card');
}}
}
$grid.trigger('woolentor:viewChanged', [ layout ]);
});
},
quantitySelectors: function($grid){
$grid.on('click', '.woolentor-qty-plus', function(e){
e.preventDefault();
const $button=$(this);
const $input=$button.siblings('.woolentor-qty-input');
const currentValue=parseInt($input.val())||1;
const max=parseInt($input.attr('max') )||999;
if(currentValue < max){
$input.val(currentValue + 1).trigger('change');
}});
$grid.on('click', '.woolentor-qty-minus', function(e){
e.preventDefault();
const $button=$(this);
const $input=$button.siblings('.woolentor-qty-input');
const currentValue=parseInt($input.val())||1;
const min=parseInt($input.attr('min') )||1;
if(currentValue > min){
$input.val(currentValue - 1).trigger('change');
}});
$grid.on('change', '.woolentor-qty-input', function(){
const $input=$(this);
const quantity=$input.val();
const $cartButton=$input.closest('.woolentor-product-actions').find('.woolentor-cart-btn');
if($cartButton.length){
$cartButton.attr('data-quantity', quantity);
}});
},
loadMore: function($gridArea){
let loadMoreButton=$gridArea.find('.woolentor-load-more-btn');
if(loadMoreButton.length > 0){
loadMoreButton.on('click', function(e){
e.preventDefault();
const $button=loadMoreButton;
const uniqIdentifire=$button.data('grid-id');
const $loader=$button.siblings('.woolentor-ajax-loader');
const $grid=$('#' + uniqIdentifire);
const currentPage=parseInt($button.data('page'));
const maxPages=parseInt($button.data('max-pages'));
const dataLayout=$grid.attr('data-show-layout');
const loadMoreWrapper=$('.' + uniqIdentifire).find('.woolentor-ajax-enabled');
if(currentPage > maxPages){
return;
}
$button.hide();
$loader.show();
let settings=loadMoreWrapper.attr('data-wl-widget-settings');
const ajaxData={
action: 'woolentor_load_more_products',
nonce: typeof window?.woolentorLocalizeData!=='undefined' ? window?.woolentorLocalizeData.security:'',
page: currentPage,
settings: settings,
viewlayout: typeof dataLayout==='undefined' ? '':dataLayout
};
$.ajax({
url: typeof window?.woolentorLocalizeData!=='undefined' ? window?.woolentorLocalizeData.ajaxUrl:'',
type: 'POST',
data: ajaxData,
success: function(response){
if(response.success&&response.data.html){
const $newProducts=$(response.data.html);
$grid.append($newProducts);
$button.data('page', currentPage+1);
if(currentPage < maxPages){
$button.show();
}else{
$button.text($button.data('complete-loadtxt')).prop('disabled', true).show();
}}
$loader.hide();
},
error: function(xhr, status, error){
$loader.hide();
$button.show();
console.log("Status:", status, "Error:", error);
}});
});
}},
infiniteScroll: function($gridArea){
let selectorBtn=$gridArea.find('.woolentor-infinite-scroll');
let isLoading=false;
const uniqIdentifire=selectorBtn.data('grid-id');
const productLoadWrapper=$('.' + uniqIdentifire).find('.woolentor-ajax-enabled');
const $loader=selectorBtn.find('.woolentor-ajax-loader');
const $grid=$('#' + uniqIdentifire);
const paginationArea=productLoadWrapper.find('.woolentor-pagination-infinite');
function loadMoreOnScroll(){
if(isLoading) return;
const gridOffset=$grid?.offset()?.top;
const gridHeight=$grid.outerHeight();
const gridBottom=gridOffset + gridHeight;
const scrollTop=$(window).scrollTop();
const windowHeight=$(window).height();
const triggerPoint=gridBottom - windowHeight - 100;
if(scrollTop >=triggerPoint){
const currentPage=parseInt(selectorBtn.data('page'));
const maxPages=parseInt(selectorBtn.data('max-pages'));
if(currentPage > maxPages){
$(window).off('scroll', loadMoreOnScroll);
return;
}
paginationArea.css('margin-top', '30px');
isLoading=true;
$loader.show();
let settings=productLoadWrapper.attr('data-wl-widget-settings');
const dataLayout=$grid.attr('data-show-layout');
$.ajax({
url: typeof woolentor_addons!=='undefined' ? woolentor_addons.woolentorajaxurl:'',
type: 'POST',
data: {
action: 'woolentor_load_more_products',
nonce: typeof woolentor_addons!=='undefined' ? woolentor_addons.ajax_nonce:'',
page: currentPage,
settings: settings,
viewlayout: typeof dataLayout==='undefined' ? '':dataLayout
},
success: function(response){
if(response.success&&response.data.html){
const $newProducts=$(response.data.html);
$grid.append($newProducts);
selectorBtn.data('page', currentPage + 1);
if(currentPage > maxPages){
$(window).off('scroll', loadMoreOnScroll);
selectorBtn.remove();
}}
},
complete: function(){
$loader.hide();
isLoading=false;
paginationArea.css('margin-top', '0');
},
error: function(){
$loader.hide();
isLoading=false;
}});
}}
$(window).on('scroll', loadMoreOnScroll);
},
initProductGridModern: function(){
$("[class*='woolentorblock-'] .woolentor-product-grid").each(function(){
const $grid=$(this);
if($grid.hasClass('woolentor-style-editorial')){
WooLentorBlocks.viewSwitcher($grid, '.woolentor-product-grid-editorial', 'editorial');
}else if($grid.hasClass('woolentor-style-magazine')){
WooLentorBlocks.viewSwitcher($grid, '.woolentor-product-grid-magazine', 'magazine');
}else{
WooLentorBlocks.viewSwitcher($grid, '.woolentor-product-grid-modern');
}
WooLentorBlocks.quantitySelectors($grid);
WooLentorBlocks.loadMore($grid);
WooLentorBlocks.infiniteScroll($grid);
});
}};
$(document).ready(function (){
WooLentorBlocks.init();
WooLentorBlocks.CartTableHandler();
WooLentorBlocks.initProductGridModern();
$("[class*='woolentorblock-'] .product-slider").each(function (){
WooLentorBlocks.initSlickSlider($(this));
});
$("[class*='woolentorblock-'].woolentor-block-slider-navforas").each(function (){
WooLentorBlocks.initSlickNavForAsSlider($(this));
}
);
$("[class*='woolentorblock-'] .htwoolentor-faq").each(function (){
WooLentorBlocks.initAccordion($(this));
});
$("[class*='woolentorblock-'].woolentor-product-addtocart").each(function (){
WooLentorBlocks.quantityIncreaseDescrease($(this));
}
);
WooLentorBlocks.woolentorToolTipHandler();
});
document.addEventListener("WoolentorEditorModeSlick",
function (event){
let editorMainArea=$(".block-editor__container"),
editorIframe=$("iframe.edit-site-visual-editor__editor-canvas"),
productSliderDiv =
editorIframe.length > 0
? editorIframe
.contents()
.find("body.block-editor-iframe__body")
.find(`.woolentorblock-editor-${event.detail.uniqid} .product-slider`
)
: editorMainArea.find(`.woolentorblock-editor-${event.detail.uniqid} .product-slider`
);
window.setTimeout(WooLentorBlocks.initSlickSlider(productSliderDiv),
1000
);
},
false
);
document.addEventListener("WoolentorEditorModeNavForSlick",
function (event){
let editorMainArea=$(".block-editor__container"),
editorIframe=$("iframe.edit-site-visual-editor__editor-canvas"),
navForAsSliderDiv =
editorIframe.length > 0
? editorIframe
.contents()
.find("body.block-editor-iframe__body")
.find(`.woolentorblock-editor-${event.detail.uniqid} .woolentor-block-slider-navforas`
)
: editorMainArea.find(`.woolentorblock-editor-${event.detail.uniqid} .woolentor-block-slider-navforas`
);
window.setTimeout(WooLentorBlocks.initSlickNavForAsSlider(navForAsSliderDiv),
1000
);
},
false
);
document.addEventListener("wooLentorProductGridModern", function (event){ WooLentorBlocks.initProductGridModern() }, false);
document.addEventListener("wooLentorProductGridEditorial", function (event){ WooLentorBlocks.initProductGridModern() }, false);
document.addEventListener("wooLentorProductGridMagazine", function (event){ WooLentorBlocks.initProductGridModern() }, false);
})(jQuery, window);