1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-08-07 22:26:57 +02: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

View File

@@ -9,6 +9,7 @@ import Data from './dom/data'
import {
emulateTransitionEnd,
execute,
getElement,
getTransitionDurationFromElement
} from './util/index'
import EventHandler from './dom/event-handler'
@@ -23,7 +24,7 @@ const VERSION = '5.0.0'
class BaseComponent {
constructor(element) {
element = typeof element === 'string' ? document.querySelector(element) : element
element = getElement(element)
if (!element) {
return