if (swiper.isEnd) { $prev.removeClass('product-arrow-hide swiper-button-disabled').addClass('product-arrow-show'); } else if (swiper.isBeginning) { $next.removeClass('product-arrow-hide swiper-button-disabled').addClass('product-arrow-show'); } else { $prev.removeClass('product-arrow-hide swiper-button-disabled').addClass('product-arrow-show'); $next.removeClass('product-arrow-hide swiper-button-disabled').addClass('product-arrow-show'); } } $('.product-content-2 .product-category').each(function () { var $category = $(this); var $viewport = $category.find('.product-category-viewport'); var $list = $category.find('ul'); var $prev = $category.find('.product-category-prev'); var $next = $category.find('.product-category-next'); var index = 0; function getMaxIndex() { var maxScroll = Math.max(0, $list[0].scrollWidth - $viewport.width()); var step = Math.max(1, Math.round($viewport.width() * .6)); return Math.ceil(maxScroll / step); } function updateCategory() { var count = $list.find('li').length; if (count <= 6) { $category.removeClass('is-slide'); $list.css('transform', 'translate(0)'); index = 0; return; } $category.addClass('is-slide'); var maxIndex = getMaxIndex(); index = Math.min(index, maxIndex); var step = Math.max(1, Math.round($viewport.width() * .6)); var maxScroll = Math.max(0, $list[0].scrollWidth - $viewport.width()); var translate = Math.min(index * step, maxScroll); $list.css('transform', 'translate(' + (-translate) + 'px)'); $prev.toggleClass('disabled', index <= 0); $next.toggleClass('disabled', index >= maxIndex); } $prev.on('click', function () { index = Math.max(0, index - 1); updateCategory(); }); $next.on('click', function () { index = Math.min(getMaxIndex(), index + 1); updateCategory(); }); $(window).on('resize', updateCategory); updateCategory(); }); function setProductFilter($content, isOpen) { $content.each(function () { var $item = $(this); $item.toggleClass('is-filter-open', isOpen); $item.find('.product-filter').toggleClass('active', isOpen).attr('aria-expanded', isOpen ? 'true' : 'false'); $item.find('.product-filter-panel').stop(true, true).removeAttr('style'); }); } setProductFilter($('.product-content-2'), false); $('.product-content-2 .product-filter').on('click', function (e) { e.preventDefault(); var $content = $(this).closest('.product-content-2'); var isOpen = !$content.hasClass('is-filter-open'); setProductFilter($content, isOpen); }); $('.product-content-2 .product-filter-group button').on('click', function () { var $group = $(this).closest('.product-filter-group'); $group.toggleClass('active'); $group.find('ul').stop(true, true).slideToggle(260); }); $('.product-content-2 .product-sort').on('click', function (e) { e.preventDefault(); e.stopPropagation(); $(this).toggleClass('active'); $('.product-content-2 .product-sort-panel').stop(true, true).slideToggle(220); setProductFilter($('.product-content-2'), false); }); $('.product-content-2 .product-sort-panel a').on('click', function (e) { e.preventDefault(); var text = $(this).text(); $('.product-content-2 .product-sort-panel a').removeClass('active'); $(this).addClass('active'); $('.product-content-2 .product-sort strong').text(text); $('.product-content-2 .product-sort').removeClass('active'); $('.product-content-2 .product-sort-panel').stop(true, true).slideUp(220); }); $(document).on('click', function () { $('.product-content-2 .product-sort').removeClass('active'); $('.product-content-2 .product-sort-panel').stop(true, true).slideUp(220); }); $('.product-content-2 .product-sort-wrap').on('click', function (e) { e.stopPropagation(); }); $('.product-content-4 .product-faq-list button').on('click', function () { var $item = $(this).closest('li'); $item.toggleClass('active'); $item.find('.product-faq-answer').stop(true, true).slideToggle(260); });