jQuery(document).ready(function ($){
if(fifuImageVars.fifu_block){
jQuery('body').on('contextmenu', 'img', function (e){
return false;
});
}
if(fifuImageVars.fifu_redirection&&fifuImageVars.fifu_forwarding_url&&!fifuImageVars.fifu_is_front_page){
if(fifuImageVars.fifu_main_image_url)
jQuery('img[src*="' + fifu_no_protocol(fifuImageVars.fifu_main_image_url) + '"]').wrap('<a href="' + fifuImageVars.fifu_forwarding_url + '" target="_blank"></a>');
else
jQuery('img[srcset*="' + fifu_no_protocol(fifuImageVars.fifu_local_image_url) + '"]').wrap('<a href="' + fifuImageVars.fifu_forwarding_url + '" target="_blank"></a>');
}
if(fifuImageVars.fifu_should_crop){
setTimeout(function (){
cropImage();
}, parseInt(fifuImageVars.fifu_crop_delay));
}
disableClick($);
disableLink($);
setTimeout(function (){
jQuery('img.zoomImg').css('z-index', '');
if(!jQuery('img.zoomImg').attr('alt')){
const $zoomImg=jQuery('img.zoomImg');
const $precedingImg=$zoomImg.prev('img');
if($precedingImg.length > 0){
$zoomImg.attr('alt', $precedingImg.attr('alt'));
}}
}, 1000);
jQuery('img[height=1]').each(function (index){
if(jQuery(this).attr('width')!=1)
jQuery(this).css('position', 'relative');
});
});
jQuery(document).ajaxComplete(function ($){
jQuery('div.woocommerce-product-gallery img').on('error', function (){
jQuery(this)[0].src=fifuImageVars.fifu_error_url;
});
});
jQuery(window).on('ajaxComplete', function (){
setTimeout(function (){
if(fifuImageVars.fifu_slider)
fifu_slider=fifu_load_slider();
}, 300);
});
function cropImage(selector){
if(!selector)
selector=fifuImageVars.fifu_crop_default + fifuImageVars.fifu_crop_selectors;
sel=selector.split(',');
dictRatio={};
dicFit={};
selector='';
for (i=0; i < sel.length; i++){
arr=sel[i].split('|');
if(arr.length > 1){
dictRatio[i]=arr[1];
if(arr.length > 2)
dicFit[i]=arr[2];
}
selector +=arr[0];
if(i + 1 < sel.length)
selector +=', ';
}
fit=fifuImageVars.fifu_fit;
global_ratio=fifuImageVars.fifu_crop_ratio;
global_ratio_w=global_ratio.split(':')[0];
global_ratio_h=global_ratio.split(':')[1];
sel=selector.split(',');
for (i=0; i < sel.length; i++){
if(dictRatio){
local_ratio=dictRatio[i];
ratio_w=local_ratio ? local_ratio.split(':')[0]:global_ratio_w;
ratio_h=local_ratio ? local_ratio.split(':')[1]:global_ratio_h;
}
if(dicFit){
local_fit=dicFit[i];
fit=local_fit ? local_fit:fit;
}
jQuery(sel[i]).each(function (index){
if(sel[i].trim()==='.fifu-slider')
return;
var width;
var backend=false;
jQuery(this).find('img, a.g1-frame').each(function (index){
ignoreSelectors=fifuImageVars.fifu_crop_ignore_parent.split(',');
skip=false;
for (j=0; j < ignoreSelectors.length; j++){
if(jQuery(this).parent().is(ignoreSelectors[j])){
skip=true;
break
}}
if(skip)
return;
theme_width=jQuery(this).attr('theme-width');
theme_height=jQuery(this).attr('theme-height');
if(!width){
width=jQuery(this).parent().css('width').replace('px', '');
width=width!=0 ? width:jQuery(this).parent().parent().css('width').replace('px', '');
width=width!=0 ? width:jQuery(this).parent().parent().parent().css('width').replace('px', '');
}
if(width=='100%'){
width=jQuery(this).parent()[0].clientWidth;
width=width!=0 ? width:jQuery(this).parent().parent()[0].clientWidth;
width=width!=0 ? width:jQuery(this).parent().parent().parent()[0].clientWidth;
}
if(isValidImgClass(jQuery(this).attr('class'))){
if(fifuImageVars.fifu_should_crop_with_theme_sizes&&(backend||(theme_width&&theme_height&&theme_height!=9999))){
backend=true;
jQuery(this).attr('style', jQuery(this).attr('style') + ';height: ' + (width * theme_height / theme_width) + 'px !important');
}else{
jQuery(this).attr('style', jQuery(this).attr('style') + ';height: ' + (width * ratio_h / ratio_w) + 'px !important');
}
if(jQuery(this)[0].clientHeight > jQuery(this)[0].clientWidth)
jQuery(this).css('width', '100%');
else
jQuery(this).css('width', width + 'px !important');
jQuery(this).css('object-fit', fit ? fit:'cover');
position=jQuery(this).attr('fifu-position');
if(position){
jQuery(this).css('object-position', position);
jQuery(this).removeAttr('fifu-position');
}}
});
jQuery(this).find('*[style*="background-image"]').each(function (index){
jQuery(this).css('background-size', fit);
});
});
}
jQuery('a.woocommerce-LoopProduct-link').css('width', '100%');
}
function isValidImgClass(className){
return !className||!className.includes('avatar');
}
function disableClick($){
if(!fifuImageVars.fifu_woo_lbox_enabled){
firstParentClass='';
parentClass='';
jQuery('figure.woocommerce-product-gallery__wrapper').find('div.woocommerce-product-gallery__image').each(function (index){
parentClass=jQuery(this).parent().attr('class').split(' ')[0];
if(!firstParentClass)
firstParentClass=parentClass;
if(parentClass!=firstParentClass)
return false;
jQuery(this).children().click(function (){
return false;
});
jQuery(this).children().children().css("cursor", "default");
});
}}
function disableLink($){
if(!fifuImageVars.fifu_woo_lbox_enabled){
firstParentClass='';
parentClass='';
jQuery('figure.woocommerce-product-gallery__wrapper').find('div.woocommerce-product-gallery__image').each(function (index){
parentClass=jQuery(this).parent().attr('class').split(' ')[0];
if(!firstParentClass)
firstParentClass=parentClass;
if(parentClass!=firstParentClass)
return false;
jQuery(this).children().attr("href", "");
});
}}
jQuery(document).ajaxSuccess(function (){
if(fifuImageVars.fifu_should_crop){
setTimeout(function (){
cropImage();
}, parseInt(fifuImageVars.fifu_crop_delay));
}});
jQuery(document).click(function ($){
fifu_fix_gallery_height();
})
function fifu_fix_gallery_height(){
if(fifuImageVars.fifu_is_flatsome_active){
mainImage=jQuery('.woocommerce-product-gallery__wrapper div.flickity-viewport').find('img')[0];
if(mainImage)
jQuery('.woocommerce-product-gallery__wrapper div.flickity-viewport').css('height', mainImage.clientHeight + 'px');
}}
jQuery(document.body).on('post-load', function (){
setTimeout(function (){
if(fifuImageVars.fifu_slider)
fifu_slider=fifu_load_slider();
}, 300);
});
jQuery('img.lazy').on('appear', function (){
if(fifuImageVars.fifu_should_crop)
cropImage();
});
function fifu_no_protocol(url){
return url.replace(/^https?:\/\//, '');
};