Skip to content

Commit

Permalink
getActiveSlideIdxAndSlidesQuantity updated
Browse files Browse the repository at this point in the history
  • Loading branch information
yurytut1993 committed Mar 14, 2021
1 parent 921a0ed commit f650203
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
5 changes: 3 additions & 2 deletions assets/js/theme/common/carousel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ import {
* @returns {Object}
*/
const extractSlidesDetails = ({
slideCount, currentSlide, options: { slidesToScroll },
slideCount, $slides, options: { slidesToShow, slidesToScroll },
}) => getActiveSlideIdxAndSlidesQuantity(
currentSlide,
slideCount,
slidesToShow,
slidesToScroll,
$slides,
);

export const onCarouselClick = ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
export default (currentSlide, slideCount, slidesToScroll) => (
export default (slideCount, slidesToShow, slidesToScroll, $slides) => {
const lastVisibleIdx = $slides.get().reduce((acc, curr, idx) => {
if ($(curr).hasClass('slick-active')) return idx;
return acc;
}, -1);

let activeSlideIdx;
let slidesQuantity;

activeSlideIdx = lastVisibleIdx < slidesToShow
? 0
: Math.ceil((lastVisibleIdx + 1 - slidesToShow) / slidesToScroll);

slidesQuantity = slideCount === 0
? 0
: slideCount <= slidesToShow
? 1
: Math.ceil((slideCount - slidesToShow) / slidesToScroll) + 1;

// FYI - one slide can contain several card items for product carousel
{
activeSlideIdx: Math.ceil(currentSlide / slidesToScroll),
slidesQuantity: Math.ceil(slideCount / slidesToScroll),
}
);
return {
activeSlideIdx,
slidesQuantity,
};
};

0 comments on commit f650203

Please sign in to comment.