aboutsummaryrefslogtreecommitdiff
path: root/js/src/util
diff options
context:
space:
mode:
authorGeoSot <[email protected]>2022-11-06 20:31:43 +0200
committerGitHub <[email protected]>2022-11-06 20:31:43 +0200
commite81e7cda90026cdb2a05fcdadd2d66f48f0bbdc4 (patch)
treeea2459eebdf22e47438e3494a4955e173b5e9b66 /js/src/util
parent2b21094074b1bdabf9ebc4095c29398f8b2de237 (diff)
downloadbootstrap-e81e7cda90026cdb2a05fcdadd2d66f48f0bbdc4.tar.xz
bootstrap-e81e7cda90026cdb2a05fcdadd2d66f48f0bbdc4.zip
Move `getElementFromSelector` & `getSelectorFromElement` to SelectorEngine (#36027)
* Move `getElementFromSelector` & getSelectorFromElement` inside selector-engine.js, in order to use SelectorEngine methods, avoiding raw querySelector usage * add `getMultipleElementsFromSelector` helper Co-authored-by: Julien Déramond <[email protected]>
Diffstat (limited to 'js/src/util')
-rw-r--r--js/src/util/component-functions.js5
-rw-r--r--js/src/util/index.js43
2 files changed, 3 insertions, 45 deletions
diff --git a/js/src/util/component-functions.js b/js/src/util/component-functions.js
index 2298ac371..6896faf56 100644
--- a/js/src/util/component-functions.js
+++ b/js/src/util/component-functions.js
@@ -6,7 +6,8 @@
*/
import EventHandler from '../dom/event-handler.js'
-import { getElementFromSelector, isDisabled } from './index.js'
+import { isDisabled } from './index.js'
+import SelectorEngine from '../dom/selector-engine.js'
const enableDismissTrigger = (component, method = 'hide') => {
const clickEvent = `click.dismiss${component.EVENT_KEY}`
@@ -21,7 +22,7 @@ const enableDismissTrigger = (component, method = 'hide') => {
return
}
- const target = getElementFromSelector(this) || this.closest(`.${name}`)
+ const target = SelectorEngine.getElementFromSelector(this) || this.closest(`.${name}`)
const instance = component.getOrCreateInstance(target)
// Method argument is left, for Alert and only, as it doesn't implement the 'hide' method
diff --git a/js/src/util/index.js b/js/src/util/index.js
index ad99f85ed..b92eddba2 100644
--- a/js/src/util/index.js
+++ b/js/src/util/index.js
@@ -30,47 +30,6 @@ const getUID = prefix => {
return prefix
}
-const getSelector = element => {
- let selector = element.getAttribute('data-bs-target')
-
- if (!selector || selector === '#') {
- let hrefAttribute = element.getAttribute('href')
-
- // The only valid content that could double as a selector are IDs or classes,
- // so everything starting with `#` or `.`. If a "real" URL is used as the selector,
- // `document.querySelector` will rightfully complain it is invalid.
- // See https://github.com/twbs/bootstrap/issues/32273
- if (!hrefAttribute || (!hrefAttribute.includes('#') && !hrefAttribute.startsWith('.'))) {
- return null
- }
-
- // Just in case some CMS puts out a full URL with the anchor appended
- if (hrefAttribute.includes('#') && !hrefAttribute.startsWith('#')) {
- hrefAttribute = `#${hrefAttribute.split('#')[1]}`
- }
-
- selector = hrefAttribute && hrefAttribute !== '#' ? hrefAttribute.trim() : null
- }
-
- return selector
-}
-
-const getSelectorFromElement = element => {
- const selector = getSelector(element)
-
- if (selector) {
- return document.querySelector(selector) ? selector : null
- }
-
- return null
-}
-
-const getElementFromSelector = element => {
- const selector = getSelector(element)
-
- return selector ? document.querySelector(selector) : null
-}
-
const getTransitionDurationFromElement = element => {
if (!element) {
return 0
@@ -316,10 +275,8 @@ export {
executeAfterTransition,
findShadowRoot,
getElement,
- getElementFromSelector,
getjQuery,
getNextActiveElement,
- getSelectorFromElement,
getTransitionDurationFromElement,
getUID,
isDisabled,