-
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.
feat(storefront): BCTHEME-78 Add Play/Pause button to carousel
- Loading branch information
1 parent
c169162
commit 7b09a3e
Showing
11 changed files
with
182 additions
and
21 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
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
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { throttle } from 'lodash'; | ||
|
||
const playAction = 'slickPlay'; | ||
const pauseAction = 'slickPause'; | ||
|
||
export default ($heroCarousel) => { | ||
const $playPauseButton = $('.js-hero-play-pause-button'); | ||
|
||
if ($playPauseButton.length === 0) return; | ||
|
||
const slickSettings = $heroCarousel[0].slick; | ||
if (!slickSettings) return; | ||
|
||
const { slideCount, options: { speed } } = slickSettings; | ||
if (slideCount < 2) { | ||
$playPauseButton.css('display', 'none'); | ||
return; | ||
} | ||
|
||
const onPlayPauseClick = () => { | ||
const isCarouselPlaying = $playPauseButton.data('play'); | ||
const action = isCarouselPlaying ? pauseAction : playAction; | ||
const { | ||
play, | ||
ariaPlay, | ||
pause, | ||
ariaPause, | ||
} = $playPauseButton.data('labels'); | ||
|
||
$heroCarousel.slick(action); | ||
$playPauseButton | ||
.data('play', !isCarouselPlaying) | ||
.text(action === playAction ? pause : play) | ||
.attr('aria-label', action === playAction ? ariaPause : ariaPlay); | ||
}; | ||
|
||
$playPauseButton.on('click', throttle(onPlayPauseClick, speed, { trailing: false })); | ||
}; |
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
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
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
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
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
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
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
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