aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeoSot <[email protected]>2021-09-10 02:02:44 +0300
committerGeoSot <[email protected]>2021-09-10 02:02:44 +0300
commita6fb50aa8c9d1b1b9987f4c3758bea425eae42ab (patch)
treee69ef6a8415084d4cf8f8fa81117441aa4c60ce0
parentd829fe8f6c5d7a1b945a87c143426dc683bce9f0 (diff)
downloadbootstrap-a6fb50aa8c9d1b1b9987f4c3758bea425eae42ab.tar.xz
bootstrap-a6fb50aa8c9d1b1b9987f4c3758bea425eae42ab.zip
Save up some iterations time
-rw-r--r--js/src/carousel.js24
1 files changed, 11 insertions, 13 deletions
diff --git a/js/src/carousel.js b/js/src/carousel.js
index 662badd31..ca66ed384 100644
--- a/js/src/carousel.js
+++ b/js/src/carousel.js
@@ -93,7 +93,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"]'
@@ -358,21 +357,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 (let i = 0; i < indicators.length; i++) {
- if (Number.parseInt(Manipulator.getDataAttribute(indicators[i], 'slide-to'), 10) === this._getItemIndex(element)) {
- indicators[i].classList.add(CLASS_NAME_ACTIVE)
- indicators[i].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')
}
}