aboutsummaryrefslogtreecommitdiff
path: root/js/dist/collapse.js
diff options
context:
space:
mode:
authorPierre Vanduynslager <[email protected]>2017-04-08 18:43:25 -0400
committerGitHub <[email protected]>2017-04-08 18:43:25 -0400
commitfe72daf2b34263d3cfc9bc77e9998cd22adfa34d (patch)
tree15dc9fc6fcb513362ba112d52ab01b568b423709 /js/dist/collapse.js
parentf5cc59145642d78d7abbdf38fee1905786da5367 (diff)
parentfeb35b94a61c4d6016be8d1773a79a6bbe57d856 (diff)
downloadbootstrap-fe72daf2b34263d3cfc9bc77e9998cd22adfa34d.tar.xz
bootstrap-fe72daf2b34263d3cfc9bc77e9998cd22adfa34d.zip
Merge branch 'v4-dev' into dropdown-keyboard
Diffstat (limited to 'js/dist/collapse.js')
-rw-r--r--js/dist/collapse.js33
1 files changed, 17 insertions, 16 deletions
diff --git a/js/dist/collapse.js b/js/dist/collapse.js
index dcf368128..6e570b890 100644
--- a/js/dist/collapse.js
+++ b/js/dist/collapse.js
@@ -59,7 +59,8 @@ var Collapse = function ($) {
var Selector = {
ACTIVES: '.card > .show, .card > .collapsing',
- DATA_TOGGLE: '[data-toggle="collapse"]'
+ DATA_TOGGLE: '[data-toggle="collapse"]',
+ DATA_CHILDREN: 'data-children'
};
/**
@@ -76,13 +77,20 @@ var Collapse = function ($) {
this._element = element;
this._config = this._getConfig(config);
this._triggerArray = $.makeArray($('[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) {
+ var 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();
}
@@ -103,11 +111,7 @@ var Collapse = function ($) {
Collapse.prototype.show = function show() {
var _this = this;
- if (this._isTransitioning) {
- throw new Error('Collapse is transitioning');
- }
-
- if ($(this._element).hasClass(ClassName.SHOW)) {
+ if (this._isTransitioning || $(this._element).hasClass(ClassName.SHOW)) {
return;
}
@@ -115,7 +119,7 @@ var Collapse = function ($) {
var activesData = void 0;
if (this._parent) {
- actives = $.makeArray($(this._parent).find(Selector.ACTIVES));
+ actives = $.makeArray($(this._parent).find(this._selectorActives));
if (!actives.length) {
actives = null;
}
@@ -180,11 +184,7 @@ var Collapse = function ($) {
Collapse.prototype.hide = function hide() {
var _this2 = this;
- if (this._isTransitioning) {
- throw new Error('Collapse is transitioning');
- }
-
- if (!$(this._element).hasClass(ClassName.SHOW)) {
+ if (this._isTransitioning || !$(this._element).hasClass(ClassName.SHOW)) {
return;
}
@@ -195,9 +195,8 @@ var Collapse = function ($) {
}
var dimension = this._getDimension();
- var 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);
@@ -331,7 +330,9 @@ var Collapse = function ($) {
*/
$(document).on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (event) {
- event.preventDefault();
+ if (!/input|textarea/i.test(event.target.tagName)) {
+ event.preventDefault();
+ }
var target = Collapse._getTargetFromElement(this);
var data = $(target).data(DATA_KEY);