(function (factory){
if(typeof define==='function'&&define.amd){
define(['jquery'], factory);
}else if(typeof exports==='object'){
module.exports=factory(require('jquery'));
}else{
factory(jQuery);
}}(function ($){
var pluses=/\+/g;
function encode(s){
return config.raw ? s:encodeURIComponent(s);
}
function decode(s){
return config.raw ? s:decodeURIComponent(s);
}
function stringifyCookieValue(value){
return encode(config.json ? JSON.stringify(value):String(value));
}
function parseCookieValue(s){
if(s.indexOf('"')===0){
s=s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
}
try {
s=decodeURIComponent(s.replace(pluses, ' '));
return config.json ? JSON.parse(s):s;
} catch(e){}}
function read(s, converter){
var value=config.raw ? s:parseCookieValue(s);
return $.isFunction(converter) ? converter(value):value;
}
var config=$.cookie=function (key, value, options){
if(arguments.length > 1&&!$.isFunction(value)){
options=$.extend({}, config.defaults, options);
if(typeof options.expires==='number'){
var days=options.expires, t=options.expires=new Date();
t.setMilliseconds(t.getMilliseconds() + days * 864e+5);
}
return (document.cookie=[
encode(key), '=', stringifyCookieValue(value),
options.expires ? '; expires=' + options.expires.toUTCString():'',
options.path    ? '; path=' + options.path:'',
options.domain  ? '; domain=' + options.domain:'',
options.secure  ? '; secure':''
].join(''));
}
var result=key ? undefined:{},
cookies=document.cookie ? document.cookie.split('; '):[],
i=0,
l=cookies.length;
for (; i < l; i++){
var parts=cookies[i].split('='),
name=decode(parts.shift()),
cookie=parts.join('=');
if(key===name){
result=read(cookie, value);
break;
}
if(!key&&(cookie=read(cookie))!==undefined){
result[name]=cookie;
}}
return result;
};
config.defaults={};
$.removeCookie=function (key, options){
$.cookie(key, '', $.extend({}, options, { expires: -1 }));
return !$.cookie(key);
};}));
(function($){
function createInputWeight(n){
let row='<div class="wrap-input"><input type="text" class="inputbox input-weight" value="" placeholder="5"><i>' + $('#rowWeight').attr('data-unit') + '</i></div>';
$('#weightInputs').html('');
for (let index=0; index < n; index++){
$('#weightInputs').append(row);
}}
$(document).ready(function (){
$(document).on('click','a.btn-link-subscribe', function(){
if($(this).attr('href')=='#'){
return false;
}});
$(document).on('click','a.mfp-link',function(){
let url=$(this).attr('data-href');
if(url!=undefined){
$.magnificPopup.open({
items: { src: url },
overflowY:'scroll',
type: 'ajax',
overflowY: 'scroll',
removalDelay: 300,
mainClass: 'my-mfp-zoom-in',
callbacks: {
ajaxContentAdded: function(){
let h=$('.mfp-content').height();
if($('#wpadminbar').length){
h +=$('#wpadminbar').height();
}},
open: function(){
$('body').addClass('blur');
let h=$('.mfp-content').height();
if($('#wpadminbar').length){
h +=$('#wpadminbar').height();
}
$('body').addClass('popup-open');
},
close: function(){
$('body').removeClass('blur');
$('body').removeClass('popup-open');
$('html').removeAttr('style');
}},
});
return false;
}});
$(document).on('click','a[data-calc]',function(){
let url='/wp-admin/admin-ajax.php';
let id=$(this).attr('data-calc');
let catlink=$(this).attr('data-catlink');
url=url + '?action=load_product_calc_popup&catlink=' + encodeURIComponent(catlink) + '&product_id=' + id + '&lang=' + (document.documentElement.lang||'en');
if(url!=undefined){
$.magnificPopup.open({
items: { src: url },
overflowY:'scroll',
type: 'ajax',
overflowY: 'scroll',
removalDelay: 300,
mainClass: 'my-mfp-zoom-in',
callbacks: {
ajaxContentAdded: function(){
let h=$('.mfp-content').height();
if($('#wpadminbar').length){
h +=$('#wpadminbar').height();
}},
open: function(){
$('body').addClass('blur');
$('body').addClass('popup-open');
let h=$('.mfp-content').height();
if($('#wpadminbar').length){
h +=$('#wpadminbar').height();
}},
close: function(){
$('body').removeClass('blur');
$('body').removeClass('popup-open');
$('html').removeAttr('style');
}},
});
return false;
}});
$(document).on('click','a.back',function(){
let url='/wp-admin/admin-ajax.php';
let id=$(this).attr('data-pid');
let catlink=$(this).attr('data-catlink');
url=url + '?action=load_product_calc_popup&catlink=' + encodeURIComponent(catlink) + '&product_id=' + id + '&lang=' + (document.documentElement.lang||'en');
if(url!=undefined){
setTimeout(()=> {
$.magnificPopup.open({
items: { src: url },
overflowY:'scroll',
type: 'ajax',
overflowY: 'scroll',
removalDelay: 300,
mainClass: 'my-mfp-zoom-in',
callbacks: {
ajaxContentAdded: function(){
let h=$('.mfp-content').height();
if($('#wpadminbar').length){
h +=$('#wpadminbar').height();
}},
open: function(){
$('body').addClass('blur');
$('body').addClass('popup-open');
let h=$('.mfp-content').height();
if($('#wpadminbar').length){
h +=$('#wpadminbar').height();
}},
close: function(){
$('body').removeClass('blur');
$('body').removeClass('popup-open');
$('html').removeAttr('style');
}},
});
}, 300);
return false;
}});
$(document).on('click','.popup-calc .weight-inputs .wrap-input i',function(){
let $input=$(this).prev();
$input.focus();
let input=$input.get(0);
if(input.setSelectionRange){
let length=$input.val().length;
setTimeout(()=> input.setSelectionRange(length, length), 10);
}});
$(document).on('click','.btnCalc',function(){
if($(this).hasClass('not-active')){
$('.popup-calc').addClass('drag-intut');
setTimeout(()=> {
$('.popup-calc').removeClass('drag-intut');
}, 1500);
return false;
}
let arr=[];
$('.weight-inputs input').each(function(){
arr.push($(this).val());
});
$.cookie('my_cats', encodeURIComponent(JSON.stringify(arr)), { expires: 7, path: '/' });
let url='/wp-admin/admin-ajax.php';
let id=$(this).attr('data-pid');
let catlink=$(this).attr('data-catlink');
url=url + '?action=load_product_calc_res_popup&catlink=' + encodeURIComponent(catlink) + '&product_id=' + id + '&lang=' + (document.documentElement.lang||'en');
if(url!=undefined){
$('.mfp-close').click();
setTimeout(()=> {
$.magnificPopup.open({
items: { src: url },
overflowY:'scroll',
type: 'ajax',
overflowY: 'scroll',
removalDelay: 300,
mainClass: 'my-mfp-zoom-in',
callbacks: {
ajaxContentAdded: function(){
let h=$('.mfp-content').height();
if($('#wpadminbar').length){
h +=$('#wpadminbar').height();
}},
open: function(){
$('body').addClass('blur');
$('body').addClass('popup-open');
let h=$('.mfp-content').height();
if($('#wpadminbar').length){
h +=$('#wpadminbar').height();
}},
close: function(){
$('body').removeClass('blur');
$('body').removeClass('popup-open');
$('html').removeAttr('style');
}},
});
}, 300);
return false;
}
return false;
});
$(document).on('focusout','.input-count',function(){
});
$(document).on('keyup change', '.popup-calc .inputbox', function(e){
var value=$(this).val();
var num=parseInt(value.replace(/[^0-9]/g,""), 10);
$('.popup-calc .btn-calc').addClass('not-active');
if(isNaN(num)){
num='';
}else{
if($(this).hasClass('input-count')){
if(num > 10){
num=10;
$('.popup-calc .tooltip').show();
}
else if(num < 1){
num=1;
}else{
}}
if($(this).hasClass('input-weight')){
if(num > 100){
num=99;
}
else if(num < 1){
num=1;
}else{
}
let flag=true;
$('.popup-calc .input-weight').each(function(){
if($(this).val()==''){
flag=false;
}});
if($('.popup-calc .input-count').val()==''){
flag=false;
}
if(flag){
$('.popup-calc .btn-calc').removeClass('not-active');
}}
}
$(this).val(num);
if($(this).hasClass('input-count')){
if(num!=''){
createInputWeight(num)
}else{
createInputWeight(1);
}}
});
});
jQuery(document).ready(function($){
$('.show-text-menu').click(function(){
if($('.text-menu').hasClass('fix-open')){
$('.text-menu').removeClass('fix-open');
}else{
$('.text-menu').addClass('fix-open');
}
return false;
});
if($('.blog-menu .active').length>0&&!isDesktop()){
var $activeItem=$('.blog-menu a.active');
var $menu=$('.blog-menu');
var scrollLeft=$activeItem.position().left + $menu.scrollLeft() - 20;
console.log(scrollLeft);
$menu.animate({
scrollLeft: scrollLeft
}, 0);
}
const getMetaContent=(property)=> {
const meta=document.querySelector(`meta[property="${property}"]`);
return meta ? meta.getAttribute('content'):'';
};
const og={
url: getMetaContent('og:url')||window.location.href,
title: getMetaContent('og:title')||document.title,
description: getMetaContent('og:description')||'',
image: getMetaContent('og:image')||''
};
const url=encodeURIComponent(og.url);
const title=encodeURIComponent(og.title);
const description=encodeURIComponent(og.description);
const image=encodeURIComponent(og.image);
const shareLinks={
facebook: `https://www.facebook.com/sharer/sharer.php?u=${url}`,
pinterest: `https://pinterest.com/pin/create/button/?url=${url}&media=${image}&description=${description}`,
whatsapp: `https://api.whatsapp.com/send?text=${title}%20${url}`,
telegram: `https://t.me/share/url?url=${url}&text=${title}`,
twitter: `https://twitter.com/intent/tweet?url=${url}&text=${title}`,
linkedin: `https://www.linkedin.com/shareArticle?mini=true&url=${url}&title=${title}&summary=${description}`,
instagram: `https://www.instagram.com/` // Instagram не поддерживает шаринг через веб
};
$('.share-btn').each(function(){
const network=$(this).data('network');
if(shareLinks[network]){
$(this).on('click', function(e){
e.preventDefault();
if($('.wrap-social-share').hasClass('open')){
$('.wrap-social-share').removeClass('open');
}
window.open(shareLinks[network],
'shareWindow',
'width=600,height=400,toolbar=no,menubar=no,scrollbars=yes,resizable=yes'
);
});
}});
$('.socials').on('click', function(e){
e.preventDefault();
if(!$('.wrap-social-share').hasClass('open')){
$('.wrap-social-share').addClass('open');
}else{
$('.wrap-social-share').removeClass('open');
}
return false;
})
$('.page-link').on('click', function(e){
e.preventDefault();
const pageUrl=getMetaContent('og:url')||window.location.href;
const $this=$(this);
let $notice=$this.find('.copy-notice');
if($notice.length===0){
$notice=$('<div class="copy-notice">Link copied</div>');
$this.append($notice);
}
navigator.clipboard.writeText(pageUrl).then(()=> {
$notice.addClass('show');
setTimeout(()=> {
$notice.removeClass('show');
}, 1500);
}).catch(err=> {
console.error('Ошибка при копировании: ', err);
alert('Не удалось скопировать ссылку');
});
});
$('.btn-up').on('click', function(){
$('body,html').animate({scrollTop:$('.blog-item').offset().top},300);
});
function generateTextMenu(){
const $menu=$('.text-menu');
const $menuList=$menu.find('ul');
const $content=$('.some-text');
const $headings=$content.find('h2');
if($headings.length===0){
$menu.addClass('hidden');
$menu.remove();
$('.text-menu-psevdo').remove();
return;
}else{
$menu.removeClass('hidden');
}
$menuList.empty();
$headings.each(function(index){
const $h2=$(this);
let text=$h2.text().trim();
let number='';
const match=text.match(/^(\d+)\.\s*(.*)$/);
if(match){
number=match[1] + '.';
text=match[2];
}else{
number=(index + 1) + '.';
}
const id=$h2.attr('id')||'heading-' + index;
$h2.attr('id', id);
const $li=$('<li></li>');
const $a=$('<a></a>').attr('href', '#' + id);
const $i=$('<i></i>').text(number);
$a.append($i).append(' ' + text);
$li.append($a);
$menuList.append($li);
});
$menuList.find('a').on('click', function(e){
e.preventDefault();
const targetId=$(this).attr('href').substring(1);
const $targetH2=$('#' + targetId);
let newTop=50;
if(!isDesktop()){
newTop=0;
newTop +=50;
}
newTop +=$('header#header .main-menu').outerHeight();
if($('#wpadminbar').length&&!isDesktop()){
newTop +=$('#wpadminbar').outerHeight();
}
if($targetH2.length){
$('html, body').animate({
scrollTop: $targetH2.offset().top - newTop
}, 500);
}
if($('.text-menu').hasClass('fix-open')){
$('.text-menu').removeClass('fix-open');
}});
if(!isDesktop()){
$('.some-text').css({'padding-top': ($('.text-menu').outerHeight()+36) + 'px'});
}
$('.text-menu-psevdo').data('data-height', $('.text-menu').outerHeight());
}
function updateMenu(){
if($('.text-menu').length==0){
return;
}
const $menu=$('.text-menu');
const $menuItems=$menu.find('li');
const $wrap=$('.wrap-some-text');
const $content=$('.some-text');
const $headings=$content.find('h2');
const wrapTop=$wrap.offset().top;
const wrapBottom=wrapTop + $wrap.outerHeight();
let contentTop=$content.offset().top;
const contentBottom=contentTop + $content.outerHeight();
const scrollTop=$(window).scrollTop();
const windowHeight=$(window).height();
const menuHeight=$menu.outerHeight();
if(!isDesktop()){
contentTop +=parseInt($('.text-menu-psevdo').data('data-height'),10);
}
let newTop=0;
if(scrollTop > contentTop){
newTop=scrollTop - wrapTop;
if(isDesktop()){
newTop +=7;
}
newTop +=$('header#header .main-menu').outerHeight();
if($('#wpadminbar').length&&isDesktop()){
newTop +=$('#wpadminbar').outerHeight();
}
const maxTop=wrapBottom - wrapTop - menuHeight;
if(!isDesktop()&&newTop + 50 >=maxTop){
$('.text-menu').addClass('fixed-off');
}else{
$('.text-menu').removeClass('fixed-off');
}
newTop=Math.min(newTop, maxTop);
newTop=Math.max(0, newTop);
}
$menu.css('top', newTop + 'px');
if(!isDesktop()&&newTop>0){
$('.text-menu').addClass('fix-mobile');
}else{
$('.text-menu').removeClass('fix-mobile');
$('.text-menu-psevdo').css({'display':'none'});
}
let activeIndex=0;
let zoneTop=scrollTop + 160;
if(!isDesktop()){
zoneTop=scrollTop + 160;
}
$headings.each(function(index){
const $h2=$(this);
const h2Top=$h2.offset().top;
if(h2Top <=zoneTop){
activeIndex=index;
}});
if(scrollTop > $headings.last().offset().top){
activeIndex=$headings.length - 1;
}
$menuItems.removeClass('active');
$menuItems.eq(activeIndex).addClass('active');
const totalHeight=contentBottom - contentTop;
const visibleHeight=Math.min(contentBottom, scrollTop + windowHeight) - contentTop;
const progress=Math.max(0, Math.min(1, visibleHeight / totalHeight)) * 100;
$('.progress-bar-line').css('width', progress + '%');
$('.percent').text(Math.round(progress) + '%');
}
generateTextMenu();
updateMenu();
function isDesktop(){
return $(window).width() > 992;
}
function positionBtnUp(){
if($('.blog-item').length > 0&&$('.btn-up').length > 0){
let scrollTopB=$(window).scrollTop();
if(scrollTopB > $('.blue-line').offset().top){
$('.btn-up').show();
}else{
$('.btn-up').hide();
}
let newRight=0;
newRight=$(window).width() - $('.blog-item').width() - $('.blog-item').offset().left + 30;
$('.btn-up').css('right', newRight + 'px');
}}
$(window).on('scroll resize', function(){
positionBtnUp();
updateMenu();
});
positionBtnUp();
if(!isDesktop()){
let $wrapMenu=$('#header .product-categories');
let $wrapMenuUl=$('#header .product-categories>ul');
$wrapMenu.append('<div class="wrap-logo-menu"><img src="' + $('#header .logo').attr('src') + '" /></div>');
$wrapMenuUl.prepend('<li id="menu-item-account" class="menu-item-type-post_type menu-item-object-page menu-item-account items-account without-icon"><a href="' + $('#header .icon-auth').attr('href') + '"><span>' + $('.header-buttons').attr('data-labelacc') + '</span></a><a class="js-more" href="#"><i class="more"></i></a></li>');
$wrapMenuUl.prepend('<li id="menu-item-wish" class="menu-item-type-post_type menu-item-object-page menu-item-wish items-wish without-icon"><a href="' + $('#header .wishlist-info').attr('href') + '"><span>' + $('.header-buttons').attr('data-labelwish') + '</span></a><a class="js-more" href="#"><i class="more"></i></a></li>');
$wrapMenu.find('li ul').each(function(){
let text=$(this).closest('li').find('>a').text();
if(text){
$(this).prepend('<li id="menu-item-wish" class="menu-item-type-post_type menu-item-object-page menu-item-parent-back items-wish without-icon"><a href="javascript:void(0)" ><span>' + text + '</span></a><a class="js-more2" href="#"><i class="more"></i></a></li>')
}});
$(document).on('click','.menu-item-parent-back', function(){
$('.mobile-menu-back').trigger('click');
return false;
});
let $curLang=$wrapMenu.find('.wpml-ls-current-language>a>span');
$wrapMenu.append('<div class="lang-bar"><div class="title">' + $('.header-buttons').attr('data-labellang') + ':</div><a href="javascript:void(0)"><img src="' + $curLang.find('img').attr('src') + '">' + $curLang.text() + '<i></i></a></div>');
$(document).on('click','.lang-bar a', function(){
let langMenu=$('li.wpml-ls-current-language');
if(langMenu.hasClass('open')){
langMenu.removeClass('open');
}else{
langMenu.addClass('open');
}
return false;
});
$('#menu-item-wish .js-more').click(function(){
location=$(this).prev().attr('href');
return false;
});
$('#menu-item-account .js-more').click(function(){
location=$(this).prev().attr('href');
return false;
});
}
let initialViewportHeight=window.innerHeight;
$('.mfp-content').on('focus', 'input, textarea', function(){
let currentViewportHeight=window.innerHeight;
if(currentViewportHeight < initialViewportHeight){
$('.mfp-wrap').css({
'align-items': 'flex-start',
'padding-top': '20px'
});
}});
$('.mfp-content').on('blur', 'input, textarea', function(){
setTimeout(function(){
$('.mfp-wrap').css({
'align-items': 'center',
'padding-top': '0'
});
}, 300);
});
$(document).on('added_to_cart removed_from_cart updated_cart_totals',
function (){
console.log('removed_from_cart');
if($('.woocommerce-cart-form').length>0||$('.woocommerce-checkout').length>0){
location.reload();
}}
);
});
})(jQuery);