2
0
mirror of https://github.com/tenrok/bootstrap.git synced 2026-06-11 18:02:28 +03:00

Move get element functionality to a helper (#33327)

Looking around on js components I found out many checks, different expressed but with same purpose.
Some of them are trying to parse string to element, others, jQuery element to js simple nodeElement etc

With this Pr, I am trying to give a standard way to parse an element

So this pr:

* Creates `getElement` helper that tries to parse an argument to element or null
* Changes `isElement` to make  explicit checks and return Boolean 
* fixes tests deficiencies
This commit is contained in:
GeoSot
2021-05-13 18:17:20 +03:00
committed by GitHub
parent e376142d85
commit 6e1c9096f0
8 changed files with 85 additions and 49 deletions
+2 -9
View File
@@ -7,9 +7,9 @@
import {
defineJQueryPlugin,
getElement,
getSelectorFromElement,
getElementFromSelector,
isElement,
reflow,
typeCheckConfig
} from './util/index'
@@ -272,14 +272,7 @@ class Collapse extends BaseComponent {
_getParent() {
let { parent } = this._config
if (isElement(parent)) {
// it's a jQuery object
if (typeof parent.jquery !== 'undefined' || typeof parent[0] !== 'undefined') {
parent = parent[0]
}
} else {
parent = SelectorEngine.findOne(parent)
}
parent = getElement(parent)
const selector = `${SELECTOR_DATA_TOGGLE}[data-bs-parent="${parent}"]`