0
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-03-15 15:29:22 +01:00

Add a helper function to check for showing

Also, remove the `isTransitioning()` helper.
This commit is contained in:
GeoSot 2021-06-10 01:16:54 +03:00 committed by XhmikosR
parent 4961ad0c63
commit 5882d5dbe8

View File

@ -113,7 +113,7 @@ class Collapse extends BaseComponent {
// Public // Public
toggle() { toggle() {
if (this._element.classList.contains(CLASS_NAME_SHOW)) { if (this._isShown()) {
this.hide() this.hide()
} else { } else {
this.show() this.show()
@ -121,7 +121,7 @@ class Collapse extends BaseComponent {
} }
show() { show() {
if (this._isTransitioning || this._element.classList.contains(CLASS_NAME_SHOW)) { if (this._isTransitioning || this._isShown()) {
return return
} }
@ -184,16 +184,16 @@ class Collapse extends BaseComponent {
}) })
} }
this.setTransitioning(true) this._isTransitioning = true
const complete = () => { const complete = () => {
this._isTransitioning = false
this._element.classList.remove(CLASS_NAME_COLLAPSING) this._element.classList.remove(CLASS_NAME_COLLAPSING)
this._element.classList.add(CLASS_NAME_COLLAPSE, CLASS_NAME_SHOW) this._element.classList.add(CLASS_NAME_COLLAPSE, CLASS_NAME_SHOW)
this._element.style[dimension] = '' this._element.style[dimension] = ''
this.setTransitioning(false)
EventHandler.trigger(this._element, EVENT_SHOWN) EventHandler.trigger(this._element, EVENT_SHOWN)
} }
@ -205,7 +205,7 @@ class Collapse extends BaseComponent {
} }
hide() { hide() {
if (this._isTransitioning || !this._element.classList.contains(CLASS_NAME_SHOW)) { if (this._isTransitioning || !this._isShown()) {
return return
} }
@ -229,17 +229,17 @@ class Collapse extends BaseComponent {
const trigger = this._triggerArray[i] const trigger = this._triggerArray[i]
const elem = getElementFromSelector(trigger) const elem = getElementFromSelector(trigger)
if (elem && !elem.classList.contains(CLASS_NAME_SHOW)) { if (elem && !this._isShown(elem)) {
trigger.classList.add(CLASS_NAME_COLLAPSED) trigger.classList.add(CLASS_NAME_COLLAPSED)
trigger.setAttribute('aria-expanded', false) trigger.setAttribute('aria-expanded', false)
} }
} }
} }
this.setTransitioning(true) this._isTransitioning = true
const complete = () => { const complete = () => {
this.setTransitioning(false) this._isTransitioning = false
this._element.classList.remove(CLASS_NAME_COLLAPSING) this._element.classList.remove(CLASS_NAME_COLLAPSING)
this._element.classList.add(CLASS_NAME_COLLAPSE) this._element.classList.add(CLASS_NAME_COLLAPSE)
EventHandler.trigger(this._element, EVENT_HIDDEN) EventHandler.trigger(this._element, EVENT_HIDDEN)
@ -250,8 +250,8 @@ class Collapse extends BaseComponent {
this._queueCallback(complete, this._element, true) this._queueCallback(complete, this._element, true)
} }
setTransitioning(isTransitioning) { _isShown(element = this._element) {
this._isTransitioning = isTransitioning return element.classList.contains(CLASS_NAME_SHOW)
} }
// Private // Private
@ -296,7 +296,7 @@ class Collapse extends BaseComponent {
return return
} }
const isOpen = element.classList.contains(CLASS_NAME_SHOW) const isOpen = this._isShown(element)
triggerArray.forEach(elem => { triggerArray.forEach(elem => {
if (isOpen) { if (isOpen) {