1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-09-28 14:29:07 +02:00

Refactor util plugin and some tests

This commit is contained in:
Johann-S
2018-09-14 14:27:30 +02:00
committed by XhmikosR
parent 19b836c907
commit a2f1d79045
12 changed files with 458 additions and 448 deletions

View File

@@ -77,8 +77,9 @@ const Polyfill = (() => {
}
// matches polyfill (see: https://mzl.la/2ikXneG)
if (!Element.prototype.matches) {
Element.prototype.matches =
let matches = Element.prototype.matches
if (!matches) {
matches =
Element.prototype.msMatchesSelector ||
Element.prototype.webkitMatchesSelector
}
@@ -86,15 +87,16 @@ const Polyfill = (() => {
// closest polyfill (see: https://mzl.la/2vXggaI)
let closest
if (!Element.prototype.closest) {
const nodeText = 3
closest = (element, selector) => {
let ancestor = element
do {
if (ancestor.matches(selector)) {
if (matches.call(ancestor, selector)) {
return ancestor
}
ancestor = ancestor.parentElement
} while (ancestor !== null && ancestor.nodeType === Node.ELEMENT_NODE)
} while (ancestor !== null && ancestor.nodeType === Node.ELEMENT_NODE && ancestor.nodeType !== nodeText)
return null
}
@@ -186,6 +188,7 @@ const Polyfill = (() => {
defaultPreventedPreservedOnDispatch,
focusIn: typeof window.onfocusin === 'undefined',
closest,
matches,
find,
findOne
}