$(function() { clickMenuButton(); openMobMenu(); closeMobMenu(); addArrowMobMenuAndOpen(); searchMob(); filtersShowMobil(); filtersCloseMobil(); imgCardZoom(); $('.field-feedback-recaptcha').addClass('col-sm-12').addClass('f_center'); function clickMenuButton() { var menuButtonParent = $('.main-nav-item') menuButtonParent.find('.btn-like').click(function (e) { if(menuButtonParent.hasClass('home-page-menu')) { e.preventDefault; $('body, html').animate({scrollTop:$('.dropdown-menu.sidebar').offset().top + 2},500) } else { function qqq() { if(!($('body').find('.catalog-overlay')>0)){ $('body').append('
') } $('.catalog-menu-wrapper-start').addClass('opened'); setTimeout(function () { $('.catalog-menu-wrapper-start').addClass('visible_catalog') },10) } if($(window).scrollTop()>104) { $('body, html').animate({scrollTop:0},500, function () { qqq(); }) } else { qqq(); } } }) $('body').on('click','.catalog-overlay',function () { $('.catalog-overlay').remove(); $('.main-nav-item').removeClass('open'); $('.catalog-menu-wrapper-start').removeClass('visible_catalog') setTimeout(function () { $('.catalog-menu-wrapper-start').removeClass('opened') },510) }) } function mobOverlayAdd() { $('body').append('
') } function mobOverlayRemove() { $('.mob-overlay').remove() } function openMobMenu() { $('.menu_mob').click(function () { mobOverlayAdd() $('body').addClass('off-scroll') $('#menu-mob-hidden').addClass('opens') setTimeout(function () { $('#menu-mob-hidden').addClass('visible') },10) }) } function closeMobMenu() { $('body').on('click','.mob-overlay',function () { mobOverlayRemove() if($('#menu-mob-hidden').hasClass('visible')) { $('#menu-mob-hidden').removeClass('visible') setTimeout(function () { $('#menu-mob-hidden').removeClass('opens') },200) $('body').removeClass('off-scroll') } if($('.btn_call').hasClass('close')) { $('.btn_call').removeClass('close') closeCallMobileHide() } }) $('.close-menu-mob .close_mob').click(function () { mobOverlayRemove() $('#menu-mob-hidden').removeClass('visible') setTimeout(function () { $('#menu-mob-hidden').removeClass('opens') },200) $('body').removeClass('off-scroll') $('#menu-mob-hidden ul li.has_ul').removeClass('open') }) } function closeCallMobileHide() { $('.call-mobile-wr').removeClass('visible') setTimeout(function () { $('.call-mobile-wr').removeClass('open') },200) } function addArrowMobMenuAndOpen() { $('#menu-mob-hidden ul li').each(function () { if($(this).find('ul').length>0){ $(this).addClass('has_ul') $(this).parent().addClass('sub_m') $('#menu-mob-hidden>ul').removeClass('sub_m').addClass('sub_m-first'); } }) $('body').on('click','#menu-mob-hidden ul li.has_ul a',function () { if($(this).parent().parent().hasClass('sub_m')){ //если li элемент вложженый if($(this).parent().hasClass('open')){ $(this).parent().removeClass('open') } else { $('.sub_m').find('.has_ul').removeClass('open') $(this).parent().addClass('open') } } if($(this).parent().parent().hasClass('sub_m-first')) { //если ли родительский открываем/закрываем if($(this).parent().hasClass('open')) { $(this).parent().removeClass('open') $(this).parent().find('.open').removeClass('open') } else { $(this).parent().addClass('open') } } }) } function searchMob() { $('.search_ico .fa').click(function () { $('.search-block').addClass('show_search'); }) $('.close_search_ico').click(function () { $('.search-block').removeClass('show_search'); }) } function filtersShowMobil() { $('.filter_mobile_').click(function () { $('.mob_filters_wr').animate({left:0,opacity:1},300) $('body').addClass('hidden_scroll-y') }) } function filtersCloseMobil() { $('.close_mob_filters').click(function () { $('body').removeClass('hidden_scroll-y') $('.mob_filters_wr').animate({left:'-100%',opacity:0},300) }) } function imgCardZoom() { $('body').on('click','.image-zoom img', function () { var thisLink = $(this).attr('src'); var windowWidth = $(window).width(); if(windowWidth>767) { $('body').append('
'); } }) $('body').on('click','.close-zoom', function () { $('.zoom-img-overlay').remove() }) } $(window).resize(function () { var windowWidth = $(window).width(); if(windowWidth >992) { $('body').removeClass('hidden_scroll-y') $('.mob_filters_wr').attr('style','') } }) var basket = new ArtboxBasket({ 'cartSelector': '#cart' }); /** * Modal form submit code */ $(document) .on('beforeSubmit', '#feedback-form', function(e) { var f = this; var form = $(this); var formData = form.serialize(); $.ajax({ url: form.attr("action"), type: form.attr("method"), data: formData, success: function(data) { f.reset(); $('#feedback-modal') .modal('hide'); $('#success-modal') .modal('show'); }, error: function() { $('#feedback-modal') .modal('hide'); } }); }) .on('submit', '#feedback-form', function(e) { e.preventDefault(); }); /** * Contact form submitting */ $(document) .on('beforeSubmit', '#contact-form', function(e) { var f = this; var form = $(this); var formData = form.serialize(); $.ajax({ url: form.attr("action"), type: form.attr("method"), data: formData, success: function(data) { f.reset(); form.replaceWith(data.alert); }, error: function() { } }); }) .on('submit', '#contact-form', function(e) { e.preventDefault(); }); /** * Button UP code */ if ($('#back-to-top').length) { var scrollTrigger = 100, // px backToTop = function() { var scrollTop = $(window) .scrollTop(); if (scrollTop > scrollTrigger) { $('#back-to-top') .addClass('show'); } else { $('#back-to-top') .removeClass('show'); } }; backToTop(); $(window) .on('scroll', function() { backToTop(); }); $('#back-to-top') .on('click', function(e) { e.preventDefault(); $('html,body') .animate({ scrollTop: 0 }, 700); }); } $(document) .on('click', '.add-to-basket', function(e) { e.preventDefault(); var id = $(this) .data('id'); basket.add(id, 1); if ($('.alert-cart').length > 0) { } else { $('body') .prepend($("
Товар додано у кошик.
")); setTimeout(function() { $(".alert-cart") .addClass("active"); }, 100); setTimeout(function() { $(".alert-cart") .removeClass("active"); }, 3500); setTimeout(function() { $(".alert-cart") .remove(); }, 3600); } }); $(document) .on('click', '.remove-product-cart', function(e) { e.preventDefault(); var id = $(this) .parents('.product-row-basket') .data('id'); showLoader('#basket'); var xhr = basket.remove(id); xhr.done(function() { $.pjax.reload({ container: '#basket', fragment: '#basket', timeout: 5000 }); }) }); $(document) .on('change', '.increase-product-basket', function(e) { var id = $(this) .parents('.product-row-basket') .data('id'); showLoader('#basket'); var xhr = basket.set(id, $(this) .val()); xhr.done(function() { $.pjax.reload({ container: '#basket', fragment: '#basket', timeout: 5000 }); }); }); $(document) .on('click', 'li.disabled a', function(e) { e.preventDefault(); }); $(document) .on('submit', '#fast-buy-form', function(e) { e.preventDefault(); }); $(document) .on('afterValidate', '#fast-buy-form', function(e, m, errors) { if (!errors.length) { var form = $(e.target); var action = form.attr('action'); $.post(action, form.serialize(), function(data) { if (data.success) { $('#oneclick-modal') .find('.modal-body') .text(data.msg); } }); } }.bind(this)); $(document) .on( 'click', '.wishlist-rm, .wishlist-add', function() { var button = $(this); $.ajax( { url: button.data('url'), type: "POST", data: { 'variant': button.data('variant'), 'product': button.data('product'), 'user': button.data('user') }, success: function(data) { button.replaceWith(data.button); new PNotify( { title: 'Info', text: data.message, type: 'info', styling: 'fontawesome' } ); } } ) } ); $(document) .on( 'click', '.wishlist-delete', function(e) { e.preventDefault(); var button = $(this); $.ajax( { url: button.data('url'), type: "POST", data: { 'product': button.data('product'), 'variant': button.data('variant'), 'user': button.data('user') }, success: function(data) { if (data.success) { $.pjax.reload({container: '#wishlist-products'}); new PNotify( { title: 'Info', text: data.message, type: 'info', styling: 'fontawesome' } ); } } } ); } ); $(document) .on('click', '.sort-cat>a', function(e) { $(this) .parent() .toggleClass("active"); return false; }); $(document) .on('click', '.sorter li a', function(e) { var sortclick = $(this) .text(); parentsort = $(".sort-cat a span"); pstext = $(parentsort) .text(); mainlink = $(".sort-cat a") .attr('href'); newmainlink = $(this) .attr('href'); $(parentsort) .text(sortclick); $(".sort-cat>a") .attr('href', newmainlink); $(this) .text(pstext); $(this) .attr('href', mainlink); $(".sort-cat>a") .click(); $(location) .attr('href', newmainlink); return false; }); // Price slider $('.price-inputs input') .keypress(function(key) { if (key.charCode < 48 || key.charCode > 57) { return false; } }); var priceSlider = $(".price_slider input"); var pricemin = priceSlider.data("pricemin"); var pricemax = priceSlider.data("pricemax"); var currentMin = priceSlider.data("currentmin"); var currentMax = priceSlider.data("currentmax"); $(".price-inputs #price-min") .val(currentMin); $(".price-inputs #price-max") .val(currentMax); $("#price_interval") .ionRangeSlider({ type: "double", min: pricemin, max: pricemax, from: currentMin, to: currentMax, onChange: function(data) { $(".price-inputs #price-min") .val(data.from); $(".price-inputs #price-max") .val(data.to); } }); var slider = $("#price_interval") .data("ionRangeSlider"); $(document) .on('change', '.price-inputs #price-min', function() { var newmin = $(this) .val(); currentmax = $(".price-inputs #price-max") .val(); if (newmin > currentmax) { newmin = currentmax; $('.price-inputs #price-min') .val(currentmax); } else if (newmin > pricemax) { newmin = pricemax; $('.price-inputs #price-min') .val(pricemax); } slider.update({from: newmin}); }); $(document) .on('change', '.price-inputs #price-max', function() { var newmax = $(this) .val(); currentmin = $(".price-inputs #price-min") .val(); if (newmax < currentmin) { newmax = currentmin; $('.price-inputs #price-max') .val(currentmin); } else if (newmax > pricemax) { newmax = pricemax; $('.price-inputs #price-max') .val(pricemax); } slider.update({to: newmax}); }); $(document) .on('click', '.price-apply', function() { var max = $('#price-max') .val(); var min = $('#price-min') .val(); // console.log(max, min); var arr = window.location.href.split('#'); var href = arr[0]; var question = href.indexOf('?'); var queryString = ''; if (question !== -1) { queryString = href.substr(question); href = href.substr(0, question); } var count = 0; var pos = -1; while ((pos = href.indexOf('/', pos + 1)) !== -1) { count++; } console.log(count); if (count === 4) { window.location.href = href + '/price-' + min + '-' + max + queryString; } else if (count > 4) { var result = href.match(/\/[^\/]*price-(\d+)-(\d+)$/); if (result) { window.location.href = href.replace(/(\/[^\/]*)price-\d+-\d+$/, '$1price-' + min + '-' + max) + queryString; }else{ window.location.href = href + '_price-' + min + '-' + max + queryString; } } }); // End of price slider $(document).on('click', '.sidebar-menu .form-group .hiddens-button a.btn', function() { $(this).parent().parent().find(".hiddens").toggleClass("active"); var showTxt = $(this).data('show'); var hideTxt = $(this).data('hide'); if($(this).parent().parent().find(".hiddens").hasClass('active')){ $(this).text(function(i, text) { return text = hideTxt; }); } else { $(this).text(function(i, text) { return text = showTxt; }); } return false; }); }); function showLoader(container) { $(container) .prepend('
'); }