(function($) { $(function() { $('div.header__nav-toggle').click(function() { var toggle = $(this); var textShow = toggle.data('show'); var textHide = toggle.data('hide'); var nav = $('nav.header__nav'); if ( toggle.is('.active') ) { toggle.text(textShow).removeClass('active'); nav.removeClass('active'); } else { toggle.text(textHide).addClass('active'); nav.addClass('active'); } }); $('div.header__nav-menu').click(function() { var nav = $('nav.header__nav'); if (nav.is('.active')) { nav.removeClass('active'); } else { nav.addClass('active'); } }); $(document).click(function() { $('nav.header__nav').removeClass('active'); }); $('div.header__nav-menu, nav.header__nav').click(function(e) { e.stopPropagation(); }); $('ul.tabs__caption').on('click', 'li:not(.active)', function() { $(this) .addClass('active').siblings().removeClass('active') .closest('div.tabs').find('div.items').removeClass('active').eq($(this).index()).addClass('active'); $(this) .closest('div.tabs').find('div.tabs__desc').removeClass('active').eq($(this).index()).addClass('active'); }); $('div.scroller').baron({ bar: 'div.scroller__bar', }); if ( $('input:file').length ) { $('input:file').styler({ filePlaceholder: 'Прикрепите фото', fileBrowse: 'Обзор' }); } if ( $('div.related-items').length ) { if ( $('div.related-items div.items').length && $.trim($('div.related-items div.items').html()) === '' ) { $('div.related-items').hide(); } } $('div.gallery-desktop').each(function() { var thumbs_item = $(this).find('div.gallery-thumbs-item'); var big_item = $(this).find('a.gallery-big-item'); thumbs_item.click(function() { big_item.removeClass('active').eq( $(this).index() ).addClass('active'); thumbs_item.removeClass('active'); $(this).addClass('active'); }); }); var win = $(window); win.resize(function() { if ( $('div.gallery').length ) { if ( win.width() < 1000 ) { $('div.gallery-desktop').each(function() { var gallery_desktop = $(this); var gallery_big = gallery_desktop.find('div.gallery-big:not(.slick-slider)'); var gallery_thumbs = gallery_desktop.find('div.gallery-thumbs:not(.slick-slider)'); gallery_big.on('init', function(slick) { gallery_desktop.removeClass('gallery-desktop'); }); gallery_big.on('init swipe afterChange', function(event, slick, currentSlide, nextSlide){ var current = (currentSlide ? currentSlide : 0); if ( Number.isInteger(current) ) $('span.gallery__count-current').text(current + 1); $('span.gallery__count-total').text(slick.slideCount); }); gallery_big.slick({ asNavFor: gallery_thumbs, arrows: false, mobileFirst: true, responsive: [{ breakpoint: 999, settings: 'unslick', }, { breakpoint: 479, settings: { arrows: false, } }, { breakpoint: 319, settings: { slidesToShow: 1, arrows: true, } }], }); gallery_thumbs.slick({ asNavFor: gallery_big, focusOnSelect: true, mobileFirst: true, responsive: [{ breakpoint: 999, settings: 'unslick' }, { breakpoint: 767, settings: { slidesToShow: 4, } }, { breakpoint: 479, settings: { slidesToShow: 2, } }, { breakpoint: 319, settings: { slidesToShow: 1, } }], }); }); } else { $('div.gallery').addClass('gallery-desktop'); if ( $('div.gallery-thumbs-item.active').length ) { $('div.gallery-thumbs-item.active').trigger('click'); } else { $('a.gallery-big-item:first-child, div.gallery-thumbs-item:first-child').addClass('active'); } } } // if ( $('div.gallery').length ) if ( $('div.popular-in-cat').length ) { if ( win.width() < 768 ) { $('div.popular-in-cat div.items:not(.slick-slider)').slick({ autoplay: true, autoplaySpeed: 3000, mobileFirst: true, responsive: [{ breakpoint: 767, settings: 'unslick' }, { breakpoint: 766, settings: { slidesToShow: 1, } }], }); } } }).resize(); var menu = $('div.header__nav-menu'); var nav = $('nav.header__nav'); var menuOffset = menu.offset().top; win.scroll(function() { if ( win.scrollTop() > menuOffset ) { menu.addClass('fixed'); nav.addClass('fixed'); } else { menu.removeClass('fixed'); nav.removeClass('fixed'); } }).scroll(); }); })(jQuery);