diff options
author | Johann-S <johann.servoire@gmail.com> | 2018-09-10 12:01:14 +0300 |
---|---|---|
committer | Johann-S <johann.servoire@gmail.com> | 2018-09-10 22:10:00 +0300 |
commit | 6e2a823a44063af96749d54560808656e007c2a8 (patch) | |
tree | 9e70195b7d4685dd34a1e3c964be92fd3be4e9e7 /js/src/collapse.js | |
parent | de75bd0a4fea8bc1443173a338e7f6888f82aa1d (diff) |
collapse children with no data-parent
Diffstat (limited to 'js/src/collapse.js')
-rw-r--r-- | js/src/collapse.js | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/js/src/collapse.js b/js/src/collapse.js index d3404630a4..ad98ffa6aa 100644 --- a/js/src/collapse.js +++ b/js/src/collapse.js @@ -127,7 +127,13 @@ const Collapse = (($) => { if (this._parent) { actives = [].slice.call(this._parent.querySelectorAll(Selector.ACTIVES)) - .filter((elem) => elem.getAttribute('data-parent') === this._config.parent) + .filter((elem) => { + if (typeof this._config.parent === 'string') { + return elem.getAttribute('data-parent') === this._config.parent + } + + return elem.classList.contains(ClassName.COLLAPSE) + }) if (actives.length === 0) { actives = null @@ -282,7 +288,8 @@ const Collapse = (($) => { } _getParent() { - let parent = null + let parent + if (Util.isElement(this._config.parent)) { parent = this._config.parent @@ -309,14 +316,12 @@ const Collapse = (($) => { } _addAriaAndCollapsedClass(element, triggerArray) { - if (element) { - const isOpen = $(element).hasClass(ClassName.SHOW) + const isOpen = $(element).hasClass(ClassName.SHOW) - if (triggerArray.length) { - $(triggerArray) - .toggleClass(ClassName.COLLAPSED, !isOpen) - .attr('aria-expanded', isOpen) - } + if (triggerArray.length) { + $(triggerArray) + .toggleClass(ClassName.COLLAPSED, !isOpen) + .attr('aria-expanded', isOpen) } } |