diff options
author | GeoSot <geo.sotis@gmail.com> | 2021-10-10 12:36:18 +0300 |
---|---|---|
committer | XhmikosR <xhmikosr@gmail.com> | 2021-10-13 16:38:27 +0300 |
commit | 1eea13286671d19bdd5c0ec52769b6d75789a928 (patch) | |
tree | ae9464ed9bb228a57e8d0cf353b0c10753edfb3c /js/src/collapse.js | |
parent | 99f6cf509d8882b7c481ef50f15a86536330d8ab (diff) |
collapse: extract duplicate code to a function
Diffstat (limited to 'js/src/collapse.js')
-rw-r--r-- | js/src/collapse.js | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/js/src/collapse.js b/js/src/collapse.js index 39093c7a2a..f4fa11de40 100644 --- a/js/src/collapse.js +++ b/js/src/collapse.js @@ -8,8 +8,8 @@ import { defineJQueryPlugin, getElement, - getSelectorFromElement, getElementFromSelector, + getSelectorFromElement, reflow, typeCheckConfig } from './util/index' @@ -120,9 +120,7 @@ class Collapse extends BaseComponent { let activesData if (this._config.parent) { - const children = SelectorEngine.find(CLASS_NAME_DEEPER_CHILDREN, this._config.parent) - // remove children if greater depth - actives = SelectorEngine.find(SELECTOR_ACTIVES, this._config.parent).filter(elem => !children.includes(elem)) + actives = this._getFirstLevelChildren(SELECTOR_ACTIVES) } const container = SelectorEngine.findOne(this._selector) @@ -245,10 +243,9 @@ class Collapse extends BaseComponent { return } - const children = SelectorEngine.find(CLASS_NAME_DEEPER_CHILDREN, this._config.parent) - const elements = SelectorEngine.find(SELECTOR_DATA_TOGGLE, this._config.parent).filter(elem => !children.includes(elem)) + const children = this._getFirstLevelChildren(SELECTOR_DATA_TOGGLE) - for (const element of elements) { + for (const element of children) { const selected = getElementFromSelector(element) 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) { if (!triggerArray.length) { return |