mirror of
https://github.com/twbs/bootstrap.git
synced 2025-03-15 15:29:22 +01:00
remove polyfills which override browsers default
This commit is contained in:
parent
f0c6b24bd7
commit
764bab2941
@ -23,40 +23,13 @@ const Polyfill = (() => {
|
|||||||
return e.defaultPrevented
|
return e.defaultPrevented
|
||||||
})()
|
})()
|
||||||
|
|
||||||
// Event constructor shim
|
let find = Element.prototype.querySelectorAll
|
||||||
if (!window.Event || typeof window.Event !== 'function') {
|
let findOne = Element.prototype.querySelector
|
||||||
const origEvent = window.Event
|
|
||||||
window.Event = (inType, params) => {
|
|
||||||
params = params || {}
|
|
||||||
const e = document.createEvent('Event')
|
|
||||||
e.initEvent(inType, Boolean(params.bubbles), Boolean(params.cancelable))
|
|
||||||
return e
|
|
||||||
}
|
|
||||||
window.Event.prototype = origEvent.prototype
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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)) {
|
|
||||||
return ancestor
|
|
||||||
}
|
|
||||||
|
|
||||||
ancestor = ancestor.parentElement
|
|
||||||
} while (ancestor !== null && ancestor.nodeType === Node.ELEMENT_NODE && ancestor.nodeType !== nodeText)
|
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
closest = (element, selector) => element.closest(selector)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
const scopeSelectorRegex = /:scope\b/
|
||||||
const supportScopeQuery = (() => {
|
const supportScopeQuery = (() => {
|
||||||
const element = document.createElement('div')
|
const element = document.createElement('div')
|
||||||
|
|
||||||
try {
|
try {
|
||||||
element.querySelectorAll(':scope *')
|
element.querySelectorAll(':scope *')
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -66,10 +39,6 @@ const Polyfill = (() => {
|
|||||||
return true
|
return true
|
||||||
})()
|
})()
|
||||||
|
|
||||||
const scopeSelectorRegex = /:scope\b/
|
|
||||||
let find = Element.prototype.querySelectorAll
|
|
||||||
let findOne = Element.prototype.querySelector
|
|
||||||
|
|
||||||
if (!supportScopeQuery) {
|
if (!supportScopeQuery) {
|
||||||
find = function (selector) {
|
find = function (selector) {
|
||||||
if (!scopeSelectorRegex.test(selector)) {
|
if (!scopeSelectorRegex.test(selector)) {
|
||||||
@ -77,6 +46,7 @@ const Polyfill = (() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const hasId = Boolean(this.id)
|
const hasId = Boolean(this.id)
|
||||||
|
|
||||||
if (!hasId) {
|
if (!hasId) {
|
||||||
this.id = Util.getUID('scope')
|
this.id = Util.getUID('scope')
|
||||||
}
|
}
|
||||||
@ -100,6 +70,7 @@ const Polyfill = (() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const matches = find.call(this, selector)
|
const matches = find.call(this, selector)
|
||||||
|
|
||||||
if (typeof matches[0] !== 'undefined') {
|
if (typeof matches[0] !== 'undefined') {
|
||||||
return matches[0]
|
return matches[0]
|
||||||
}
|
}
|
||||||
@ -108,37 +79,8 @@ const Polyfill = (() => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof Object.assign !== 'function') {
|
|
||||||
Object.defineProperty(Object, 'assign', {
|
|
||||||
value: (target, ...args) => {
|
|
||||||
if (target === null || typeof target === 'undefined') {
|
|
||||||
throw new TypeError('Cannot convert undefined or null to object')
|
|
||||||
}
|
|
||||||
|
|
||||||
const to = Object(target)
|
|
||||||
|
|
||||||
for (let index = 1; index < args.length; index++) {
|
|
||||||
const nextSource = args[index]
|
|
||||||
|
|
||||||
if (nextSource !== null || !nextSource) {
|
|
||||||
for (const nextKey in nextSource) {
|
|
||||||
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
|
|
||||||
to[nextKey] = nextSource[nextKey]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return to
|
|
||||||
},
|
|
||||||
writable: true,
|
|
||||||
configurable: true
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
defaultPreventedPreservedOnDispatch,
|
defaultPreventedPreservedOnDispatch,
|
||||||
focusIn: typeof window.onfocusin === 'undefined',
|
|
||||||
closest,
|
|
||||||
find,
|
find,
|
||||||
findOne
|
findOne
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
import Polyfill from './polyfill'
|
|
||||||
import Util from '../util'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* --------------------------------------------------------------------------
|
* --------------------------------------------------------------------------
|
||||||
* Bootstrap (v4.3.1): dom/selectorEngine.js
|
* Bootstrap (v4.3.1): dom/selectorEngine.js
|
||||||
@ -8,21 +5,22 @@ import Util from '../util'
|
|||||||
* --------------------------------------------------------------------------
|
* --------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import Polyfill from './polyfill'
|
||||||
|
import Util from '../util'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ------------------------------------------------------------------------
|
* ------------------------------------------------------------------------
|
||||||
* Constants
|
* Constants
|
||||||
* ------------------------------------------------------------------------
|
* ------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const closest = Polyfill.closest
|
const findFn = Polyfill.find
|
||||||
const matchesFn = Element.prototype.matches
|
|
||||||
const find = Polyfill.find
|
|
||||||
const findOne = Polyfill.findOne
|
const findOne = Polyfill.findOne
|
||||||
const nodeText = 3
|
const NODE_TEXT = 3
|
||||||
|
|
||||||
const SelectorEngine = {
|
const SelectorEngine = {
|
||||||
matches(element, selector) {
|
matches(element, selector) {
|
||||||
return matchesFn.call(element, selector)
|
return element.matches(selector)
|
||||||
},
|
},
|
||||||
|
|
||||||
find(selector, element = document.documentElement) {
|
find(selector, element = document.documentElement) {
|
||||||
@ -30,7 +28,7 @@ const SelectorEngine = {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
return find.call(element, selector)
|
return findFn.call(element, selector)
|
||||||
},
|
},
|
||||||
|
|
||||||
findOne(selector, element = document.documentElement) {
|
findOne(selector, element = document.documentElement) {
|
||||||
@ -47,6 +45,7 @@ const SelectorEngine = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const children = Util.makeArray(element.children)
|
const children = Util.makeArray(element.children)
|
||||||
|
|
||||||
return children.filter((child) => this.matches(child, selector))
|
return children.filter((child) => this.matches(child, selector))
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -56,9 +55,9 @@ const SelectorEngine = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const parents = []
|
const parents = []
|
||||||
|
|
||||||
let ancestor = element.parentNode
|
let ancestor = element.parentNode
|
||||||
while (ancestor && ancestor.nodeType === Node.ELEMENT_NODE && ancestor.nodeType !== nodeText) {
|
|
||||||
|
while (ancestor && ancestor.nodeType === Node.ELEMENT_NODE && ancestor.nodeType !== NODE_TEXT) {
|
||||||
if (this.matches(ancestor, selector)) {
|
if (this.matches(ancestor, selector)) {
|
||||||
parents.push(ancestor)
|
parents.push(ancestor)
|
||||||
}
|
}
|
||||||
@ -74,7 +73,7 @@ const SelectorEngine = {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
return closest(element, selector)
|
return element.closest(selector)
|
||||||
},
|
},
|
||||||
|
|
||||||
prev(element, selector) {
|
prev(element, selector) {
|
||||||
@ -83,9 +82,9 @@ const SelectorEngine = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const siblings = []
|
const siblings = []
|
||||||
|
|
||||||
let previous = element.previousSibling
|
let previous = element.previousSibling
|
||||||
while (previous && previous.nodeType === Node.ELEMENT_NODE && previous.nodeType !== nodeText) {
|
|
||||||
|
while (previous && previous.nodeType === Node.ELEMENT_NODE && previous.nodeType !== NODE_TEXT) {
|
||||||
if (this.matches(previous, selector)) {
|
if (this.matches(previous, selector)) {
|
||||||
siblings.push(previous)
|
siblings.push(previous)
|
||||||
}
|
}
|
||||||
|
@ -230,13 +230,13 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
document.querySelectorAll('[data-toggle="popover"]')
|
[].slice.call(document.querySelectorAll('[data-toggle="popover"]'))
|
||||||
.forEach(function (popover) {
|
.forEach(function (popover) {
|
||||||
new Popover(popover)
|
new Popover(popover)
|
||||||
})
|
})
|
||||||
|
|
||||||
document.querySelectorAll('[data-toggle="tooltip"]')
|
var tooltipList = [].slice.call(document.querySelectorAll('[data-toggle="tooltip"]'))
|
||||||
.forEach(function (tooltip) {
|
tooltipList.forEach(function (tooltip) {
|
||||||
new Tooltip(tooltip)
|
new Tooltip(tooltip)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
<script src="../../dist/popover.js"></script>
|
<script src="../../dist/popover.js"></script>
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener('DOMContentLoaded', function () {
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
document.querySelectorAll('[data-toggle="popover"]')
|
[].slice.call(document.querySelectorAll('[data-toggle="popover"]'))
|
||||||
.forEach(function (popover) {
|
.forEach(function (popover) {
|
||||||
new Popover(popover)
|
new Popover(popover)
|
||||||
})
|
})
|
||||||
|
@ -97,7 +97,7 @@
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
document.querySelectorAll('[data-toggle="tooltip"]')
|
[].slice.call(document.querySelectorAll('[data-toggle="tooltip"]'))
|
||||||
.forEach(function (tooltip) {
|
.forEach(function (tooltip) {
|
||||||
new Tooltip(tooltip)
|
new Tooltip(tooltip)
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user