const site_domain = 'zeus-ceramica.com.ua', url_lang_insert = 'ukr'; add_to_favorites_query_selector = '.add_product_fav', add_to_compare_query_selector = '.add_product_comp', phonevalidationclass = '.phonevalidation', main_page_banner = '.main_page_banner', main_page_banner_duration = 4500; var rating_text = {}, rating_text_answer = {}; rating_text['1'] = "Фууу! Отстой!"; rating_text['2'] = "Третий сорт не брак"; rating_text['3'] = "Лучшее соотношение цена/качество"; rating_text['4'] = "Очень хороший товар!"; rating_text['5'] = "Отлично! Рекомендую!"; rating_text_answer['success'] = "Спасибо! Ваш голос учтен"; rating_text_answer['exist'] = "Вы уже голосовали"; rating_text_answer['error'] = "Возникла ошибка"; var lang = ''; if (location.href.split('/').includes(url_lang_insert)) { lang = 'ua'; } else { lang = 'ru'; } function onlyUnique(value, index, self) { return self.indexOf(value) === index; } function remove(el) { var toRemove = document.querySelector(el); toRemove.parentNode.removeChild(toRemove); } function wraphtmlelement(el, wrapper) { el.parentNode.insertBefore(wrapper, el); wrapper.appendChild(el); } function hide_global_search() { document.querySelector('.global_overlay').classList.remove('active'); document.querySelector('.burger_wrapper').classList.remove('active'); document.querySelector('.roundbg').classList.remove('active'); enable_window_scroll(); document.querySelector('.header').classList.remove('white'); } function json_ajax_get(url, callback) { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { // console.log('responseText:' + xmlhttp.responseText); try { var data = JSON.parse(xmlhttp.responseText); } catch(err) { console.log(err.message + " in " + xmlhttp.responseText); return; } callback(data); } }; xmlhttp.open("GET", url, true); xmlhttp.send(); } function ajax_get(url, callback) { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { // console.log('responseText:' + xmlhttp.responseText); try { var data = xmlhttp.responseText; } catch(err) { console.log(err.message + " in " + xmlhttp.responseText); return; } callback(data); } }; xmlhttp.open("GET", url, true); xmlhttp.send(); } function disable_window_scroll() { document.querySelector('html').style.overflow = "hidden"; } function enable_window_scroll() { document.querySelector('html').style.overflow = "visible"; } function control_scroll() { const topmenutopfix = 5, showtothetop = 200, documentheight = parseInt(document.documentElement.offsetHeight), screenheight = parseInt(document.documentElement.clientHeight), footerheight = parseInt(document.querySelector('.footer').offsetHeight), footerscrolllimit = documentheight-screenheight-footerheight + 100; if (pageYOffset > topmenutopfix) { document.querySelector('.header').classList.add('whitebg'); } else { document.querySelector('.header').classList.remove('whitebg'); } if (pageYOffset > showtothetop) { document.querySelector('.tothetop').classList.add('active'); } else { document.querySelector('.tothetop').classList.remove('active'); } if (pageYOffset > footerscrolllimit) { document.querySelector('.tothetop').classList.add('makewhite'); } else { document.querySelector('.tothetop').classList.remove('makewhite'); } /* document.getElementById('debugger').innerText = pageYOffset+'/'+footerheight+'/'+screenheight+'/'+documentheight+'/'+footerscrolllimit; */ } /* scrolling on click */ var toTop = document.querySelector('.tothetop'); toTop.addEventListener("click", function(){ scrollToTop(500); }); function scrollToTop(scrollDuration) { var scrollStep = -window.scrollY / (scrollDuration / 15), scrollInterval = setInterval(function(){ if (window.scrollY > 0) { window.scrollBy(0,scrollStep); } else clearInterval(scrollInterval); },15); } /* scrolling on click */ /* window onload */ function init() { console.log('loaded'); control_scroll(); document.querySelector('.with_borders').appendChild(document.createElement('div')).classList.add('centeredline'); document.querySelector('.global_overlay').appendChild(document.createElement('div')).className = 'global_overlay_line global_overlay_line_1'; document.querySelector('.global_overlay').appendChild(document.createElement('div')).className = 'global_overlay_line global_overlay_line_2'; document.querySelector('.global_overlay').appendChild(document.createElement('div')).className = 'global_overlay_line global_overlay_line_3'; document.querySelector('.global_overlay').appendChild(document.createElement('div')).className = 'global_overlay_line global_overlay_line_4'; document.querySelector('.global_overlay').appendChild(document.createElement('div')).className = 'global_overlay_line global_overlay_line_5'; [].forEach.call(document.querySelectorAll('.with_borders'), function (el) { el.appendChild(document.createElement('div')).classList.add('centeredline'); }); if (!!document.querySelector('.productpagecontent')) { var productid = document.querySelector('.productpagecontent').dataset.id; if (cookie.get('looked') !== undefined) { var lookedcookies = cookie.get('looked').split('|'); lookedcookies.push(productid); lookedcookies = lookedcookies.filter(onlyUnique); lookedcookiesstr = lookedcookies.join('|'); } else { lookedcookiesstr = productid; } cookie.set('looked',lookedcookiesstr,{path:'/',domain:site_domain}); } document.querySelector('body').classList.remove('preload'); if (/Android/i.test(navigator.userAgent) && !!document.querySelector('.show_filter_fixed')) { document.querySelector('.show_filter_fixed').classList.add('iamandroid'); } } window.onload = init; window.addEventListener('scroll', function() { control_scroll(); }); /* window onload */ /* keypress */ document.onkeyup = function(evt) { evt = evt || window.event; var isEscape = false; if ("key" in evt) { isEscape = (evt.key === "Escape" || evt.key === "Esc"); } else { isEscape = (evt.keyCode === 27); } if (isEscape) { hide_global_search(); console.log('Esc pressed'); } }; /* keypress */ /* lazyloading */ /* if ('loading' in HTMLImageElement.prototype) { const images = document.querySelectorAll("img.lazyload"); images.forEach(img => { img.src = img.dataset.src; }); } else { let script = document.createElement("script"); script.async = true; script.src = "https://cdnjs.cloudflare.com/ajax/libs/lazysizes/4.1.8/lazysizes.min.js"; document.body.appendChild(script); } */ const imageslazy = document.querySelectorAll("img.lazyload"); imageslazy.forEach(img => { img.src = img.dataset.src; }); /* lazyloading */ /* menu */ [].forEach.call(document.querySelectorAll('.burger_wrapper'), function (el) { el.addEventListener('click', function() { var searchbgX = parseInt(event.clientY)-150, searchbgY = parseInt(event.clientX)-150, searchbg = document.querySelector('.roundbg'); searchbgX += 'px'; searchbgY += 'px'; if (this.classList.contains('active')) { hide_global_search(); } else { this.classList.add('active'); document.querySelector('.global_overlay').classList.add('active'); document.querySelector('.header').classList.add('white'); disable_window_scroll(); searchbg.style.top = searchbgX; searchbg.style.left = searchbgY; searchbg.classList.add('active'); } }, false); }); [].forEach.call(document.querySelectorAll('.roundbg'), function (el) { el.addEventListener('click', function() { hide_global_search(); }, false); }); /* menu */ /* filter */ [].forEach.call(document.querySelectorAll('.show_filter_fixed'), function (el) { el.addEventListener('click', function() { event.preventDefault(); document.querySelector('.filter_overlay').classList.add('active'); document.querySelector('.filter_aside').classList.add('active'); document.querySelector('.show_filter_fixed').classList.add('hidden'); disable_window_scroll(); }, false); }); [].forEach.call(document.querySelectorAll('.filter_overlay'), function (el) { el.addEventListener('click', function() { document.querySelector('.filter_overlay').classList.remove('active'); document.querySelector('.filter_aside').classList.remove('active'); document.querySelector('.show_filter_fixed').classList.remove('hidden'); enable_window_scroll(); }, false); }); [].forEach.call(document.querySelectorAll('.filter_widget_checkbox'), function (el) { el.addEventListener('click', function() { if (!!document.querySelector('.filter_float_submit_wrapper')) { remove('.filter_float_submit_wrapper'); } let addsubmit = document.createElement('div'), addsubmitsubmit = document.createElement('button'); addsubmitsubmit.classList.add('filter_float_submit'); addsubmitsubmit.classList.add('btn'); addsubmitsubmit.setAttribute('type','submit'); if (lang == 'ru') { addsubmitsubmit.innerText = 'Подобрать'; } if (lang == 'ua') { addsubmitsubmit.innerText = 'Підібрати'; } addsubmit.classList.add('filter_float_submit_wrapper'); addsubmit.appendChild(addsubmitsubmit); el.parentNode.appendChild(addsubmit); }, false); }); [].forEach.call(document.querySelectorAll('.your_choise_select'), function (el) { el.addEventListener('change', function() { var thisval = el.value; document.getElementById('filter_sort_hidden').value = thisval; document.querySelector('.filter_submit_button').click(); }, false); }); /* filter */ /* search */ var search_animation = ['.search_overlay', '.search_div', '.search_div_before_content', '.search_div_content', '.search_div_form_label', '.search_div_form_input_wrapper', '.naprimer_wrapper'], search_animation_reverse = search_animation.slice().reverse(), search_animation_interval = 300; [].forEach.call(document.querySelectorAll('.lupa'), function (el) { el.addEventListener('click', function() { var iindex = 1; search_animation.forEach(function (el, index) { setTimeout(function () { document.querySelector(el).classList.add('active'); }, index * search_animation_interval); }); console.log(iindex); setTimeout(function () { document.querySelector('.search_div_form_input').focus(); }, search_animation_interval*(search_animation.length+1)); document.querySelector('.lupa').classList.add('opacityzero'); disable_window_scroll(); }, false); }); [].forEach.call(document.querySelectorAll('.search_overlay'), function (el) { el.addEventListener('click', function() { search_animation_reverse.forEach(function (el, index) { setTimeout(function () { document.querySelector(el).classList.remove('active'); }, index * search_animation_interval); }); document.querySelector('.lupa').classList.remove('opacityzero'); enable_window_scroll(); document.querySelector('.search_small_results_wrapper').classList.remove('active'); }, false); }); const min_search_symbols = 3; [].forEach.call(document.querySelectorAll('.search_div_form_input'), function (el) { el.addEventListener('keyup', function() { var thisval = this.value, thisvallen = thisval.length; if (thisvallen >= min_search_symbols) { document.querySelector('body').classList.add('loading'); var thisval = this.value, requestpath = '/modules/loadhints.php?search='+thisval+'&lang='+lang+'&rand='+Math.random(); ajax_get(requestpath, function(data) { document.querySelector('.search_small_results').innerHTML = data; document.querySelector('body').classList.remove('loading'); }); document.querySelector('.naprimer_wrapper').classList.remove('active'); document.querySelector('.search_small_results_wrapper').classList.add('active'); } else { document.querySelector('.naprimer_wrapper').classList.add('active'); document.querySelector('.search_small_results_wrapper').classList.remove('active'); } }, false); }); /* search */ /* rating */ [].forEach.call(document.querySelectorAll('.star-cb-group label'), function (el) { el.addEventListener('click', function() { var ratingstar = this.dataset.rating, id = this.parentNode.dataset.id, column = this.parentNode.dataset.column, requestpath = '/modules/starget.php?id='+id+'&column='+column+'&rating='+ratingstar; // console.log(ratingstar+'/'+id+'/'+column); console.log(requestpath); json_ajax_get(requestpath, function(data) { var touser = rating_text_answer[data.status], rating_answear = document.querySelector(".rating_answear"); rating_answear.innerText = touser; rating_answear.classList.add('active'); document.querySelector(".rating_hidden").value = ratingstar; document.querySelector(".star-cb-group").classList.add('voted'); setTimeout(function(){ rating_answear.classList.remove('active'); }, 2000); }); }, false); }); /* rating */ /* cartpage */ [].forEach.call(document.querySelectorAll('.carttbale_input'), function (el) { el.addEventListener('keyup', function() { document.querySelector('.before_oformitzakaz').style.display = 'block' }, false); }); [].forEach.call(document.querySelectorAll('.carttbale_input'), function (el) { el.addEventListener('mouseup', function() { document.querySelector('.before_oformitzakaz').style.display = 'block' }, false); }); /* cartpage */ /* alert div */ [].forEach.call(document.querySelectorAll('.alert_div_close'), function (el) { el.addEventListener('click', function() { document.querySelector('.alert_div').classList.add('hidethis'); }, false); }); /* alert div */ /* phonevalidation */ function checkphone(thisel) { var value = thisel.value, firstsymbol = thisel.value.charAt(0), lastsymbol = thisel.value.substr(-1), beforelastsymbol = thisel.value.substr(-2,1), goodsymbols = ['+','0','1','2','3','4','5','6','7','8','9'], normsymbol = true; if ( (thisel.value.length === 1 && thisel.value != '3' && thisel.value != '0' && thisel.value != '8' && thisel.value != '+') || (thisel.value.length === 2 && thisel.value != '+3') || (thisel.value.length === 3 && thisel.value != '+38') || (thisel.value.length === 4 && thisel.value != '+380') ) { normsymbol = false; thisel.value = thisel.value.substring(0,thisel.value.length-1); } console.log(beforelastsymbol+'|'+lastsymbol+'|'+normsymbol); if (thisel.value == '0') { thisel.value = '+380'; } if (thisel.value == '3') { thisel.value = '+3'; } if (thisel.value == '8') { thisel.value = '+38'; } if (thisel.value.length > 1) { var newstr = '', valuearr = thisel.value.split(''); valuearr.forEach(function(item) { if (goodsymbols.indexOf(item) > -1) { newstr = newstr+item; } }); thisel.value = newstr; } if (thisel.value.length == 12 && thisel.value.charAt(0) == '3') { thisel.value = '+'+thisel.value; } if (thisel.value.length == 11 && thisel.value.charAt(0) == '8') { thisel.value = '+3'+thisel.value; } if (thisel.value.length == 10 && thisel.value.charAt(0) == '0') { thisel.value = '+38'+thisel.value; } if (thisel.value.length == 9 && thisel.value.charAt(0) != '0' && thisel.value.charAt(0) != '+') { thisel.value = '+380'+thisel.value; } } [].forEach.call(document.querySelectorAll(phonevalidationclass), function (el) { el.setAttribute("type","tel"); el.setAttribute("pattern","[\+]38[0-9]{10}"); el.setAttribute("placeholder","+380XXXXXXXXX"); el.addEventListener('keyup', function() { checkphone(el); }, false); el.addEventListener('change', function() { checkphone(el); }, false); el.addEventListener('mouseup', function() { checkphone(el); }, false); }); /* phonevalidation */ /* favorites */ [].forEach.call(document.querySelectorAll(add_to_favorites_query_selector), function (el) { el.addEventListener('click', function() { var prodid = el.dataset.id, favar = ''; if (el.classList.contains('active')) { el.classList.remove('active'); favar = cookie.get('izbrannoe'); var favarar = favar.split('|'); favarar.splice(favarar.indexOf(prodid), 1); favarar = favarar.filter(onlyUnique); favar = favarar.join('|'); cookie.set('izbrannoe',favar,{path:'/',domain:site_domain}); } else { el.classList.add('active'); if (!!cookie.get('izbrannoe')) { favar = cookie.get('izbrannoe'); var favarar = favar.split('|'); favarar.push(prodid); favarar = favarar.filter(onlyUnique); favar = favarar.join('|'); cookie.set('izbrannoe',favar,{path:'/',domain:site_domain}); } else { cookie.set('izbrannoe',prodid,{path:'/',domain:site_domain}); } } }, false); }); /* favorites */ /* compare */ [].forEach.call(document.querySelectorAll(add_to_compare_query_selector), function (el) { el.addEventListener('click', function() { var prodid = el.dataset.id, compar = ''; if (el.classList.contains('active')) { el.classList.remove('active'); compar = cookie.get('compare'); var comparar = compar.split('|'); comparar.splice(comparar.indexOf(prodid), 1); comparar = comparar.filter(onlyUnique); compar = comparar.join('|'); cookie.set('compare',compar,{path:'/',domain:site_domain}); console.log(compar); } else { el.classList.add('active'); if (!!cookie.get('compare')) { compar = cookie.get('compare'); var comparar = compar.split('|'); comparar.push(prodid); comparar = comparar.filter(onlyUnique); compar = comparar.join('|'); cookie.set('compare',compar,{path:'/',domain:site_domain}); } else { cookie.set('compare',prodid,{path:'/',domain:site_domain}); } console.log(compar); } }, false); }); /* compare */ /* order form */ function checknamephone() { var order_name_length = parseInt(document.getElementById('imya').value.length), order_phone_length = parseInt(document.getElementById('phone').value.length); console.log(order_name_length+'|'+order_phone_length); if (order_name_length > 0 && order_phone_length > 0) { document.querySelector('.tr_pay_card_warning').style.display = 'none'; document.querySelector('.oformitzakaz').disabled = false; } else { document.querySelector('.tr_pay_card_warning').style.display = 'block'; document.querySelector('.oformitzakaz').disabled = true; } } [].forEach.call(document.querySelectorAll(".submit_order_by_card"), function (el) { el.addEventListener('click', function() { var thango = 'https://www.liqpay.ua/ru/personal'; document.querySelector('.thango').value = thango; document.querySelector('.oformitzakaz_glavniy').click(); }, false); }); [].forEach.call(document.querySelectorAll("#imya"), function (el) { el.addEventListener('click', function() { checknamephone(); }, false); }); [].forEach.call(document.querySelectorAll("#phone"), function (el) { el.addEventListener('click', function() { checknamephone(); }, false); }); [].forEach.call(document.querySelectorAll(".input_form_formaoplaty_click"), function (el) { el.addEventListener('change', function() { var thisval = this.value; if (thisval == 'liqpay') { document.querySelector(".tr_pay_card").style.display = 'table-row'; checknamephone(); } else { document.querySelector(".tr_pay_card").style.display = 'none'; } }, false); }); [].forEach.call(document.querySelectorAll(".input_form_sposobdostavki_click"), function (el) { el.addEventListener('change', function() { if (this.value == 'npochta') { document.querySelector(".np_oblast").style.display = 'table-row'; document.querySelector(".forma_order_label_mejgorod").style.display = 'flex'; document.querySelector(".np_gorod").style.display = 'none'; document.querySelector(".np_otdel").style.display = 'none'; } else { document.querySelector(".np_oblast").style.display = 'none'; document.querySelector(".forma_order_label_mejgorod").style.display = 'none'; document.querySelector(".np_gorod").style.display = 'none'; document.querySelector(".np_otdel").style.display = 'none'; } }, false); }); [].forEach.call(document.querySelectorAll("select.oblast"), function (el) { el.addEventListener('change', function() { document.querySelector('body').classList.add('loading'); document.querySelector(".np_gorod").style.display = 'table-row'; var thisval = this.value, requestpath = '/modules/npajax.php?table=gorod&area='+thisval+'&whatcolumn=Area&lang='+lang+'&rand='+Math.random(); json_ajax_get(requestpath, function(data) { var options_toreturn = ''; data.forEach(function(item, i, arr) { options_toreturn += ''; }); document.querySelector('select.gorod').innerHTML = options_toreturn; document.querySelector('body').classList.remove('loading'); }); }, false); }); [].forEach.call(document.querySelectorAll("select.gorod"), function (el) { el.addEventListener('change', function() { document.querySelector('body').classList.add('loading'); document.querySelector(".np_otdel").style.display = 'table-row'; var thisval = this.value, requestpath = '/modules/npajax.php?table=otdel&area='+thisval+'&whatcolumn=CityRef&lang='+lang+'&rand='+Math.random(); json_ajax_get(requestpath, function(data) { var options_toreturn = ''; data.forEach(function(item, i, arr) { options_toreturn += ''; }); document.querySelector('select.otdelenie').innerHTML = options_toreturn; document.querySelector('body').classList.remove('loading'); }); }, false); }); /* order form */ /* main page banner */ if (!!document.querySelector(main_page_banner)) { var main_page_banner_slider = main_page_banner+'>*:not(.main_page_banner_navigation)', main_page_banner_slider_first = main_page_banner_slider + ':first-child', main_page_banner_num = parseInt(document.querySelector(main_page_banner).children.length), cycle_num = 0, mpb_ul_nav = document.createElement('ul'), banner_type = ''; if (!!document.querySelector(main_page_banner).dataset.banner) { banner_type = document.querySelector(main_page_banner).dataset.banner; } else { banner_type = 'html'; } if (banner_type == 'img') { [].forEach.call(document.querySelectorAll(main_page_banner_slider), function (el) { wraphtmlelement(el,document.createElement('div')); }); } mpb_ul_nav.classList.add('main_page_banner_navigation'); document.querySelector(main_page_banner).appendChild(mpb_ul_nav); for (let i = 0; i < main_page_banner_num; i++) { mpb_ul_nav.appendChild(document.createElement('li')).dataset.id = i; } document.querySelector(main_page_banner_slider_first).classList.add('active'); document.querySelector('.main_page_banner_navigation li:nth-child(1)').classList.add('active'); setInterval(function() { cycle_num++; var nomer = parseInt(cycle_num%main_page_banner_num)+1, current_slide = main_page_banner_slider+':nth-child('+nomer+')', current_slide_ul = '.main_page_banner_navigation li:nth-child('+nomer+')'; [].forEach.call(document.querySelectorAll(main_page_banner_slider), function (el) { el.classList.remove('active'); }); [].forEach.call(document.querySelectorAll(".main_page_banner_navigation li"), function (el) { el.classList.remove('active'); }); document.querySelector(current_slide).classList.add('active'); document.querySelector(current_slide_ul).classList.add('active'); }, main_page_banner_duration); [].forEach.call(document.querySelectorAll(".main_page_banner_navigation li"), function (el) { el.addEventListener('click', function() { var nomer = parseInt(this.dataset.id)+ 1, current_slide = main_page_banner_slider+':nth-child('+nomer+')', current_slide_ul = '.main_page_banner_navigation li:nth-child('+nomer+')'; [].forEach.call(document.querySelectorAll(main_page_banner_slider), function (el) { el.classList.remove('active'); }); [].forEach.call(document.querySelectorAll(".main_page_banner_navigation li"), function (el) { el.classList.remove('active'); }); document.querySelector(current_slide).classList.add('active'); document.querySelector(current_slide_ul).classList.add('active'); }, false); }); } /* main page banner */ /* cookie */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).cookie=t()}(this,function(){"use strict";var e=function(){return e.get.apply(e,arguments)},t=e.utils={isArray:Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)},isPlainObject:function(e){return!!e&&"[object Object]"===Object.prototype.toString.call(e)},toArray:function(e){return Array.prototype.slice.call(e)},getKeys:Object.keys||function(e){var t=[],r="";for(r in e)e.hasOwnProperty(r)&&t.push(r);return t},encode:function(e){return String(e).replace(/[,;"\\=\s%]/g,function(e){return encodeURIComponent(e)})},decode:function(e){return decodeURIComponent(e)},retrieve:function(e,t){return null==e?t:e}};return e.defaults={},e.expiresMultiplier=86400,e.set=function(e,r,i){if(t.isPlainObject(e))for(var n in e)e.hasOwnProperty(n)&&this.set(n,e[n],r);else{var o=void 0!==(i=t.isPlainObject(i)?i:{expires:i}).expires?i.expires:this.defaults.expires||"",s=typeof o;"string"===s&&""!==o?o=new Date(o):"number"===s&&(o=new Date(+new Date+1e3*this.expiresMultiplier*o)),""!==o&&"toUTCString"in o&&(o=";expires="+o.toUTCString());var u=i.path||this.defaults.path;u=u?";path="+u:"";var a=i.domain||this.defaults.domain;a=a?";domain="+a:"";var c=i.secure||this.defaults.secure?";secure":"";!1===i.secure&&(c=""),document.cookie=t.encode(e)+"="+t.encode(r)+o+u+a+c}return this},e.setDefault=function(r,i,n){if(t.isPlainObject(r)){for(var o in r)void 0===this.get(o)&&this.set(o,r[o],i);return e}if(void 0===this.get(r))return this.set.apply(this,arguments)},e.remove=function(e){for(var r=0,i=(e=t.isArray(e)?e:t.toArray(arguments)).length;r