Skip to content

Commit

Permalink
renaming and js class pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
yurytut1993 committed Jul 30, 2020
1 parent e330602 commit 8e19b69
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
5 changes: 3 additions & 2 deletions assets/js/theme/common/carousel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'slick-carousel';

const firstNumInStrRegExp = /[0-9]+/;
const integerRegExp = /[0-9]+/;

const setSlideTabindexes = ($slides) => {
$slides.each((index, element) => {
Expand All @@ -26,7 +26,7 @@ const arrowAriaLabling = ($arrowLeft, $arrowRight, currentSlide, lastSlide) => {
const arrowAriaLabelBaseText = $arrowLeft.attr('aria-label');

const isInit = arrowAriaLabelBaseText.includes(['NUMBER']);
const valueToReplace = isInit ? '[NUMBER]' : firstNumInStrRegExp;
const valueToReplace = isInit ? '[NUMBER]' : integerRegExp;

const leftGoToNumber = currentSlide === 1 ? lastSlide : currentSlide - 1;
const arrowLeftText = arrowAriaLabelBaseText.replace(valueToReplace, leftGoToNumber);
Expand Down Expand Up @@ -54,6 +54,7 @@ export default function () {
$carouselCollection.on('afterChange', onCarouselChange);

$carouselCollection.each((index, carousel) => {
// getting element using find to pass jest test
const $carousel = $(document).find(carousel);

const isMultipleSlides = $carousel.children().length > 1;
Expand Down
8 changes: 4 additions & 4 deletions templates/components/carousel.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
"autoplaySpeed": {{carousel.swap_frequency}},
"lazyLoad": "anticipated",
"slide": ".hero-slide",
"prevArrow": ".hero-prev-arrow",
"nextArrow": ".hero-next-arrow"
"prevArrow": ".js-hero-prev-arrow",
"nextArrow": ".js-hero-next-arrow"
}'>
{{#if carousel.slides.length '>' 1}}
<button aria-label="{{lang 'carousel.arrowAriaLabel'}} {{carousel.slides.length}}" class="hero-prev-arrow slick-prev slick-arrow">hero-prev-arrow</button>
<button aria-label="{{lang 'carousel.arrowAriaLabel'}} {{carousel.slides.length}}" class="js-hero-prev-arrow slick-prev slick-arrow">hero-prev-arrow</button>
{{/if}}
{{#each carousel.slides}}
<a class="hero-slide" href="{{url}}">
Expand Down Expand Up @@ -48,6 +48,6 @@
</a>
{{/each}}
{{#if carousel.slides.length '>' 1}}
<button aria-label="{{lang 'carousel.arrowAriaLabel'}} {{carousel.slides.length}}" class="hero-next-arrow slick-next slick-arrow">hero-next-arrow</button>
<button aria-label="{{lang 'carousel.arrowAriaLabel'}} {{carousel.slides.length}}" class="js-hero-next-arrow slick-next slick-arrow">hero-next-arrow</button>
{{/if}}
</section>
9 changes: 4 additions & 5 deletions templates/components/products/carousel.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
data-list-name="{{list}}"
data-slick='{
"dots": true,
"infinite": true,
"mobileFirst": true,
"slidesToShow": 2,
"slidesToScroll": 1,
"slide": ".product-slide",
"prevArrow": ".product-prev-arrow",
"nextArrow": ".product-next-arrow",
"prevArrow": ".js-product-prev-arrow",
"nextArrow": ".js-product-next-arrow",
"responsive": [
{
"breakpoint": 800,
Expand All @@ -27,14 +26,14 @@
]
}'>
{{#if products.length '>' 1}}
<button aria-label="{{lang 'carousel.arrowAriaLabel'}} {{products.length}}" class="product-prev-arrow slick-prev slick-arrow"></button>
<button aria-label="{{lang 'carousel.arrowAriaLabel'}} {{products.length}}" class="js-product-prev-arrow slick-prev slick-arrow"></button>
{{/if}}
{{#each products}}
<div class="productCarousel-slide product-slide">
{{> components/products/card settings=../settings theme_settings=../theme_settings customer=../customer event="list" position=(add @index 1)}}
</div>
{{/each}}
{{#if products.length '>' 1}}
<button aria-label="{{lang 'carousel.arrowAriaLabel'}} {{products.length}}" class="product-next-arrow slick-next slick-arrow"></button>
<button aria-label="{{lang 'carousel.arrowAriaLabel'}} {{products.length}}" class="js-product-next-arrow slick-next slick-arrow"></button>
{{/if}}
</section>

0 comments on commit 8e19b69

Please sign in to comment.