mirror of
https://github.com/twbs/bootstrap.git
synced 2025-04-06 23:57:36 +02:00
collapse: extract duplicate code to a function
This commit is contained in:
parent
99f6cf509d
commit
1eea132866
@ -8,8 +8,8 @@
|
|||||||
import {
|
import {
|
||||||
defineJQueryPlugin,
|
defineJQueryPlugin,
|
||||||
getElement,
|
getElement,
|
||||||
getSelectorFromElement,
|
|
||||||
getElementFromSelector,
|
getElementFromSelector,
|
||||||
|
getSelectorFromElement,
|
||||||
reflow,
|
reflow,
|
||||||
typeCheckConfig
|
typeCheckConfig
|
||||||
} from './util/index'
|
} from './util/index'
|
||||||
@ -120,9 +120,7 @@ class Collapse extends BaseComponent {
|
|||||||
let activesData
|
let activesData
|
||||||
|
|
||||||
if (this._config.parent) {
|
if (this._config.parent) {
|
||||||
const children = SelectorEngine.find(CLASS_NAME_DEEPER_CHILDREN, this._config.parent)
|
actives = this._getFirstLevelChildren(SELECTOR_ACTIVES)
|
||||||
// remove children if greater depth
|
|
||||||
actives = SelectorEngine.find(SELECTOR_ACTIVES, this._config.parent).filter(elem => !children.includes(elem))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const container = SelectorEngine.findOne(this._selector)
|
const container = SelectorEngine.findOne(this._selector)
|
||||||
@ -245,10 +243,9 @@ class Collapse extends BaseComponent {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const children = SelectorEngine.find(CLASS_NAME_DEEPER_CHILDREN, this._config.parent)
|
const children = this._getFirstLevelChildren(SELECTOR_DATA_TOGGLE)
|
||||||
const elements = SelectorEngine.find(SELECTOR_DATA_TOGGLE, this._config.parent).filter(elem => !children.includes(elem))
|
|
||||||
|
|
||||||
for (const element of elements) {
|
for (const element of children) {
|
||||||
const selected = getElementFromSelector(element)
|
const selected = getElementFromSelector(element)
|
||||||
|
|
||||||
if (selected) {
|
if (selected) {
|
||||||
@ -257,6 +254,12 @@ class Collapse extends BaseComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_getFirstLevelChildren(selector) {
|
||||||
|
const children = SelectorEngine.find(CLASS_NAME_DEEPER_CHILDREN, this._config.parent)
|
||||||
|
// remove children if greater depth
|
||||||
|
return SelectorEngine.find(selector, this._config.parent).filter(elem => !children.includes(elem))
|
||||||
|
}
|
||||||
|
|
||||||
_addAriaAndCollapsedClass(triggerArray, isOpen) {
|
_addAriaAndCollapsedClass(triggerArray, isOpen) {
|
||||||
if (!triggerArray.length) {
|
if (!triggerArray.length) {
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user