diff options
| author | lucascono <[email protected]> | 2017-10-04 05:33:17 -0300 |
|---|---|---|
| committer | lucascono <[email protected]> | 2017-10-04 05:33:17 -0300 |
| commit | 8c04a74c8c7f0174ea08bc02fa3762f49bf615a3 (patch) | |
| tree | db9d6923c082243d765c57885992db8dd26a70b5 /js/src/collapse.js | |
| parent | 9aff890efa3798f831b714c41794c9fee0684bae (diff) | |
| parent | b29b1e155880ac953899889c9cbb67f7f7df0529 (diff) | |
| download | bootstrap-8c04a74c8c7f0174ea08bc02fa3762f49bf615a3.tar.xz bootstrap-8c04a74c8c7f0174ea08bc02fa3762f49bf615a3.zip | |
Merge remote-tracking branch 'refs/remotes/twbs/v4-dev' into v4-dev
Diffstat (limited to 'js/src/collapse.js')
| -rw-r--r-- | js/src/collapse.js | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/js/src/collapse.js b/js/src/collapse.js index 78ed32906..d29e48722 100644 --- a/js/src/collapse.js +++ b/js/src/collapse.js @@ -1,14 +1,15 @@ +import $ from 'jquery' import Util from './util' /** * -------------------------------------------------------------------------- - * Bootstrap (v4.0.0-alpha.6): collapse.js + * Bootstrap (v4.0.0-beta): collapse.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) * -------------------------------------------------------------------------- */ -const Collapse = (($) => { +const Collapse = (() => { /** @@ -18,7 +19,7 @@ const Collapse = (($) => { */ const NAME = 'collapse' - const VERSION = '4.0.0-alpha.6' + const VERSION = '4.0.0-beta' const DATA_KEY = 'bs.collapse' const EVENT_KEY = `.${DATA_KEY}` const DATA_API_KEY = '.data-api' @@ -32,7 +33,7 @@ const Collapse = (($) => { const DefaultType = { toggle : 'boolean', - parent : 'string' + parent : '(string|element)' } const Event = { @@ -288,7 +289,18 @@ const Collapse = (($) => { } _getParent() { - const parent = $(this._config.parent)[0] + let parent = null + if (Util.isElement(this._config.parent)) { + parent = this._config.parent + + // it's a jQuery object + if (typeof this._config.parent.jquery !== 'undefined') { + parent = this._config.parent[0] + } + } else { + parent = $(this._config.parent)[0] + } + const selector = `[data-toggle="collapse"][data-parent="${this._config.parent}"]` @@ -343,7 +355,7 @@ const Collapse = (($) => { } if (typeof config === 'string') { - if (data[config] === undefined) { + if (typeof data[config] === 'undefined') { throw new Error(`No method named "${config}"`) } data[config]() @@ -361,7 +373,8 @@ const Collapse = (($) => { */ $(document).on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (event) { - if (!/input|textarea/i.test(event.target.tagName)) { + // preventDefault only for <a> elements (which change the URL) not inside the collapsible element + if (event.currentTarget.tagName === 'A') { event.preventDefault() } @@ -391,6 +404,6 @@ const Collapse = (($) => { return Collapse -})(jQuery) +})($) export default Collapse |
