Skip to content

Commit

Permalink
improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
bc-alexsaiannyi committed Feb 3, 2021
1 parent c0fdc81 commit d71cdf7
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions assets/js/theme/common/product-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export default class ProductDetails extends ProductDetailsBase {
this.imageGallery = new ImageGallery($('[data-image-gallery]', this.$scope));
this.imageGallery.init();
this.listenQuantityChange();
this.swatchOptionMessageText = $('.swatch-option-message').text();
this.$swatchOptionMessage = $('.swatch-option-message');
this.swatchOptionMessageInitText = this.$swatchOptionMessage.text();

const $form = $('form[data-cart-item-add]', $scope);
const $productOptionsElement = $('[data-product-option-change]', $form);
Expand All @@ -26,7 +27,7 @@ export default class ProductDetails extends ProductDetailsBase {
const $productSwatchGroup = $('[id*="attribute_swatch"]', $form);

if (context.showSwatchNames) {
$('.swatch-option-message').removeClass('u-hidden');
this.$swatchOptionMessage.removeClass('u-hidden');
$productSwatchGroup.on('change', ({ target }) => this.showSwatchNameOnOption($(target)));

$.each($productSwatchGroup, (_, element) => {
Expand Down Expand Up @@ -204,11 +205,10 @@ export default class ProductDetails extends ProductDetailsBase {
*/
showSwatchNameOnOption($swatch) {
const swatchName = $swatch.attr('aria-label');
const swatchOptionText = $('span.swatch-option-message');

$('[data-product-attribute="swatch"] [data-option-value]').text(swatchName);
swatchOptionText.text(`${this.swatchOptionMessageText} ${swatchName}`);
this.setLiveRegionAttributes(swatchOptionText, 'status', 'assertive');
this.$swatchOptionMessage.text(`${this.swatchOptionMessageInitText} ${swatchName}`);
this.setLiveRegionAttributes(this.$swatchOptionMessage, 'status', 'assertive');
}

setLiveRegionAttributes($element, roleType, ariaLiveStatus) {
Expand Down

0 comments on commit d71cdf7

Please sign in to comment.