diff options
author | Johann-S <johann.servoire@gmail.com> | 2017-06-14 14:21:49 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-14 14:21:49 +0300 |
commit | f0124769c9850bea321cbd82d6250b756a52bb52 (patch) | |
tree | e3a1f8867bae18511a9f0aa80dae22b5a4bb81c3 /js/src/collapse.js | |
parent | ddf0dbbd29e556518f5f4baa3c6ba25a9891fe7b (diff) |
Collapse supports multi-target thanks to @vanduynslagerp (#22713)
Diffstat (limited to 'js/src/collapse.js')
-rw-r--r-- | js/src/collapse.js | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/js/src/collapse.js b/js/src/collapse.js index bf1c738f56..78ed32906b 100644 --- a/js/src/collapse.js +++ b/js/src/collapse.js @@ -77,6 +77,14 @@ const Collapse = (($) => { `[data-toggle="collapse"][href="#${element.id}"],` + `[data-toggle="collapse"][data-target="#${element.id}"]` )) + const tabToggles = $(Selector.DATA_TOGGLE) + for (let i = 0; i < tabToggles.length; i++) { + const elem = tabToggles[i] + const selector = Util.getSelectorFromElement(elem) + if (selector !== null && $(selector).filter(element).length > 0) { + this._triggerArray.push(elem) + } + } this._parent = this._config.parent ? this._getParent() : null @@ -215,9 +223,17 @@ const Collapse = (($) => { .removeClass(ClassName.SHOW) if (this._triggerArray.length) { - $(this._triggerArray) - .addClass(ClassName.COLLAPSED) - .attr('aria-expanded', false) + for (let i = 0; i < this._triggerArray.length; i++) { + const trigger = this._triggerArray[i] + const selector = Util.getSelectorFromElement(trigger) + if (selector !== null) { + const $elem = $(selector) + if (!$elem.hasClass(ClassName.SHOW)) { + $(trigger).addClass(ClassName.COLLAPSED) + .attr('aria-expanded', false) + } + } + } } this.setTransitioning(true) @@ -349,11 +365,14 @@ const Collapse = (($) => { event.preventDefault() } - const target = Collapse._getTargetFromElement(this) - const data = $(target).data(DATA_KEY) - const config = data ? 'toggle' : $(this).data() - - Collapse._jQueryInterface.call($(target), config) + const $trigger = $(this) + const selector = Util.getSelectorFromElement(this) + $(selector).each(function () { + const $target = $(this) + const data = $target.data(DATA_KEY) + const config = data ? 'toggle' : $trigger.data() + Collapse._jQueryInterface.call($target, config) + }) }) |