mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-06 13:46:42 +02:00
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
import { isDisabled, isVisible } from '../util/index.js'
|
||||
import { isDisabled, isVisible, parseSelector } from '../util/index.js'
|
||||
|
||||
/**
|
||||
* Constants
|
||||
@@ -99,6 +99,7 @@ const SelectorEngine = {
|
||||
}
|
||||
|
||||
selector = hrefAttribute && hrefAttribute !== '#' ? hrefAttribute.trim() : null
|
||||
selector = parseSelector(selector)
|
||||
}
|
||||
|
||||
return selector
|
||||
|
@@ -9,6 +9,20 @@ const MAX_UID = 1_000_000
|
||||
const MILLISECONDS_MULTIPLIER = 1000
|
||||
const TRANSITION_END = 'transitionend'
|
||||
|
||||
/**
|
||||
* Properly escape IDs selectors to handle weird IDs
|
||||
* @param {string} selector
|
||||
* @returns {string}
|
||||
*/
|
||||
const parseSelector = selector => {
|
||||
if (selector && window.CSS && window.CSS.escape) {
|
||||
// document.querySelector needs escaping to handle IDs (html5+) containing for instance /
|
||||
selector = selector.replaceAll(/#([^\s"#']+)/g, (match, id) => '#' + CSS.escape(id))
|
||||
}
|
||||
|
||||
return selector
|
||||
}
|
||||
|
||||
// Shout-out Angus Croll (https://goo.gl/pxwQGp)
|
||||
const toType = object => {
|
||||
if (object === null || object === undefined) {
|
||||
@@ -76,7 +90,7 @@ const getElement = object => {
|
||||
}
|
||||
|
||||
if (typeof object === 'string' && object.length > 0) {
|
||||
return document.querySelector(object)
|
||||
return document.querySelector(parseSelector(object))
|
||||
}
|
||||
|
||||
return null
|
||||
@@ -285,6 +299,7 @@ export {
|
||||
isVisible,
|
||||
noop,
|
||||
onDOMContentLoaded,
|
||||
parseSelector,
|
||||
reflow,
|
||||
triggerTransitionEnd,
|
||||
toType
|
||||
|
Reference in New Issue
Block a user