aboutsummaryrefslogtreecommitdiff
path: root/js/src/collapse.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/collapse.js')
-rw-r--r--js/src/collapse.js36
1 files changed, 19 insertions, 17 deletions
diff --git a/js/src/collapse.js b/js/src/collapse.js
index 28c4493cc..88428310d 100644
--- a/js/src/collapse.js
+++ b/js/src/collapse.js
@@ -57,7 +57,8 @@ const Collapse = (($) => {
const Selector = {
ACTIVES : '.card > .show, .card > .collapsing',
- DATA_TOGGLE : '[data-toggle="collapse"]'
+ DATA_TOGGLE : '[data-toggle="collapse"]',
+ DATA_CHILDREN : 'data-children'
}
@@ -77,13 +78,20 @@ const Collapse = (($) => {
`[data-toggle="collapse"][href="#${element.id}"],` +
`[data-toggle="collapse"][data-target="#${element.id}"]`
))
-
this._parent = this._config.parent ? this._getParent() : null
if (!this._config.parent) {
this._addAriaAndCollapsedClass(this._element, this._triggerArray)
}
+ this._selectorActives = Selector.ACTIVES
+ if (this._parent) {
+ const childrenSelector = this._parent.hasAttribute(Selector.DATA_CHILDREN) ? this._parent.getAttribute(Selector.DATA_CHILDREN) : null
+ if (childrenSelector !== null) {
+ this._selectorActives = `${childrenSelector} > .show, ${childrenSelector} > .collapsing`
+ }
+ }
+
if (this._config.toggle) {
this.toggle()
}
@@ -112,11 +120,8 @@ const Collapse = (($) => {
}
show() {
- if (this._isTransitioning) {
- throw new Error('Collapse is transitioning')
- }
-
- if ($(this._element).hasClass(ClassName.SHOW)) {
+ if (this._isTransitioning ||
+ $(this._element).hasClass(ClassName.SHOW)) {
return
}
@@ -124,7 +129,7 @@ const Collapse = (($) => {
let activesData
if (this._parent) {
- actives = $.makeArray($(this._parent).find(Selector.ACTIVES))
+ actives = $.makeArray($(this._parent).find(this._selectorActives))
if (!actives.length) {
actives = null
}
@@ -196,11 +201,8 @@ const Collapse = (($) => {
}
hide() {
- if (this._isTransitioning) {
- throw new Error('Collapse is transitioning')
- }
-
- if (!$(this._element).hasClass(ClassName.SHOW)) {
+ if (this._isTransitioning ||
+ !$(this._element).hasClass(ClassName.SHOW)) {
return
}
@@ -211,10 +213,8 @@ const Collapse = (($) => {
}
const dimension = this._getDimension()
- const offsetDimension = dimension === Dimension.WIDTH ?
- 'offsetWidth' : 'offsetHeight'
- this._element.style[dimension] = `${this._element[offsetDimension]}px`
+ this._element.style[dimension] = `${this._element.getBoundingClientRect()[dimension]}px`
Util.reflow(this._element)
@@ -357,7 +357,9 @@ const Collapse = (($) => {
*/
$(document).on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (event) {
- event.preventDefault()
+ if (!/input|textarea/i.test(event.target.tagName)) {
+ event.preventDefault()
+ }
const target = Collapse._getTargetFromElement(this)
const data = $(target).data(DATA_KEY)