-
Notifications
You must be signed in to change notification settings - Fork 614
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
getActiveSlideIdxAndSlidesQuantity updated
- Loading branch information
1 parent
921a0ed
commit f650203
Showing
2 changed files
with
27 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 24 additions & 6 deletions
30
assets/js/theme/common/carousel/utils/getActiveSlideIdxAndSlidesQuantity.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}; |