diff options
| author | Johann-S <[email protected]> | 2017-09-25 12:41:54 +0200 |
|---|---|---|
| committer | Johann-S <[email protected]> | 2017-09-25 13:23:13 +0200 |
| commit | 9b8356ba52d89fd065d6061979b5946b8c5f44fa (patch) | |
| tree | 3c78f94c599eb0ba9d052742abb8e8fe5d926fba /js/src | |
| parent | 3abf8a0e5525d30914ce37ebb98240a476cb6f17 (diff) | |
| download | bootstrap-9b8356ba52d89fd065d6061979b5946b8c5f44fa.tar.xz bootstrap-9b8356ba52d89fd065d6061979b5946b8c5f44fa.zip | |
Collapse - Allow to pass jQuery object or DOM element to the parent option
Diffstat (limited to 'js/src')
| -rw-r--r-- | js/src/collapse.js | 15 | ||||
| -rw-r--r-- | js/src/util.js | 10 |
2 files changed, 18 insertions, 7 deletions
diff --git a/js/src/collapse.js b/js/src/collapse.js index bf9c990ec..fa082f133 100644 --- a/js/src/collapse.js +++ b/js/src/collapse.js @@ -33,7 +33,7 @@ const Collapse = (() => { const DefaultType = { toggle : 'boolean', - parent : 'string' + parent : '(string|element)' } const Event = { @@ -289,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}"]` diff --git a/js/src/util.js b/js/src/util.js index b18d0f776..7eb25de55 100644 --- a/js/src/util.js +++ b/js/src/util.js @@ -32,10 +32,6 @@ const Util = (() => { return {}.toString.call(obj).match(/\s([a-zA-Z]+)/)[1].toLowerCase() } - function isElement(obj) { - return (obj[0] || obj).nodeType - } - function getSpecialTransitionEndEvent() { return { bindType: transition.end, @@ -138,12 +134,16 @@ const Util = (() => { return Boolean(transition) }, + isElement(obj) { + return (obj[0] || obj).nodeType + }, + typeCheckConfig(componentName, config, configTypes) { for (const property in configTypes) { if (Object.prototype.hasOwnProperty.call(configTypes, property)) { const expectedTypes = configTypes[property] const value = config[property] - const valueType = value && isElement(value) ? + const valueType = value && Util.isElement(value) ? 'element' : toType(value) if (!new RegExp(expectedTypes).test(valueType)) { |
