diff options
author | GeoSot <geo.sotis@gmail.com> | 2021-09-10 02:02:44 +0300 |
---|---|---|
committer | XhmikosR <xhmikosr@gmail.com> | 2021-12-21 18:37:24 +0300 |
commit | 6f79721c82ecef5a4a25482e915ffa157965702c (patch) | |
tree | d5dc989499f73c923209ee4434301ee6f821b43e /js | |
parent | d60f146507c94bd889f7049d77a4b3725a6fa0a9 (diff) |
Carousel: return early and drop a loop.
We can achieve the same thing by querying the specific selector directly
Diffstat (limited to 'js')
-rw-r--r-- | js/src/carousel.js | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/js/src/carousel.js b/js/src/carousel.js index 14a0bd40b2..856d70dac0 100644 --- a/js/src/carousel.js +++ b/js/src/carousel.js @@ -61,7 +61,6 @@ const SELECTOR_ITEM = '.carousel-item' const SELECTOR_ITEM_IMG = '.carousel-item img' const SELECTOR_NEXT_PREV = '.carousel-item-next, .carousel-item-prev' const SELECTOR_INDICATORS = '.carousel-indicators' -const SELECTOR_INDICATOR = '[data-bs-target]' const SELECTOR_DATA_SLIDE = '[data-bs-slide], [data-bs-slide-to]' const SELECTOR_DATA_RIDE = '[data-bs-ride="carousel"]' @@ -293,21 +292,20 @@ class Carousel extends BaseComponent { } _setActiveIndicatorElement(element) { - if (this._indicatorsElement) { - const activeIndicator = SelectorEngine.findOne(SELECTOR_ACTIVE, this._indicatorsElement) + if (!this._indicatorsElement) { + return + } - activeIndicator.classList.remove(CLASS_NAME_ACTIVE) - activeIndicator.removeAttribute('aria-current') + const activeIndicator = SelectorEngine.findOne(SELECTOR_ACTIVE, this._indicatorsElement) - const indicators = SelectorEngine.find(SELECTOR_INDICATOR, this._indicatorsElement) + activeIndicator.classList.remove(CLASS_NAME_ACTIVE) + activeIndicator.removeAttribute('aria-current') - for (const indicator of indicators) { - if (Number.parseInt(indicator.getAttribute('data-bs-slide-to'), 10) === this._getItemIndex(element)) { - indicator.classList.add(CLASS_NAME_ACTIVE) - indicator.setAttribute('aria-current', 'true') - break - } - } + const newActiveIndicator = SelectorEngine.findOne(`[data-bs-slide-to="${this._getItemIndex(element)}"]`, this._indicatorsElement) + + if (newActiveIndicator) { + newActiveIndicator.classList.add(CLASS_NAME_ACTIVE) + newActiveIndicator.setAttribute('aria-current', 'true') } } |