mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-09 23:26:40 +02:00
Wrap our objects into IIFE
This commit is contained in:
@@ -5,7 +5,16 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
const mapData = (() => {
|
||||
const Data = (() => {
|
||||
|
||||
/**
|
||||
* ------------------------------------------------------------------------
|
||||
* Constants
|
||||
* ------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
const mapData = (() => {
|
||||
const storeData = {}
|
||||
let id = 1
|
||||
return {
|
||||
@@ -43,9 +52,9 @@ const mapData = (() => {
|
||||
}
|
||||
}
|
||||
}
|
||||
})()
|
||||
})()
|
||||
|
||||
const Data = {
|
||||
return {
|
||||
setData(instance, key, data) {
|
||||
mapData.set(instance, key, data)
|
||||
},
|
||||
@@ -55,6 +64,7 @@ const Data = {
|
||||
removeData(instance, key) {
|
||||
mapData.delete(instance, key)
|
||||
}
|
||||
}
|
||||
}
|
||||
})()
|
||||
|
||||
export default Data
|
||||
|
@@ -7,19 +7,27 @@ import Util from '../util'
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
// defaultPrevented is broken in IE.
|
||||
// https://connect.microsoft.com/IE/feedback/details/790389/event-defaultprevented-returns-false-after-preventdefault-was-called
|
||||
const workingDefaultPrevented = (() => {
|
||||
const EventHandler = (() => {
|
||||
|
||||
/**
|
||||
* ------------------------------------------------------------------------
|
||||
* Polyfills
|
||||
* ------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
// defaultPrevented is broken in IE.
|
||||
// https://connect.microsoft.com/IE/feedback/details/790389/event-defaultprevented-returns-false-after-preventdefault-was-called
|
||||
const workingDefaultPrevented = (() => {
|
||||
const e = document.createEvent('CustomEvent')
|
||||
e.initEvent('Bootstrap', true, true)
|
||||
e.preventDefault()
|
||||
return e.defaultPrevented
|
||||
})()
|
||||
})()
|
||||
|
||||
let defaultPreventedPreservedOnDispatch = true
|
||||
let defaultPreventedPreservedOnDispatch = true
|
||||
|
||||
// CustomEvent polyfill for IE (see: https://mzl.la/2v76Zvn)
|
||||
if (typeof window.CustomEvent !== 'function') {
|
||||
// CustomEvent polyfill for IE (see: https://mzl.la/2v76Zvn)
|
||||
if (typeof window.CustomEvent !== 'function') {
|
||||
window.CustomEvent = (event, params) => {
|
||||
params = params || {
|
||||
bubbles: false,
|
||||
@@ -48,7 +56,7 @@ if (typeof window.CustomEvent !== 'function') {
|
||||
}
|
||||
|
||||
window.CustomEvent.prototype = window.Event.prototype
|
||||
} else {
|
||||
} else {
|
||||
// MSEdge resets defaultPrevented flag upon dispatchEvent call if at least one listener is attached
|
||||
defaultPreventedPreservedOnDispatch = (() => {
|
||||
const e = new CustomEvent('Bootstrap', {
|
||||
@@ -62,10 +70,10 @@ if (typeof window.CustomEvent !== 'function') {
|
||||
element.dispatchEvent(e)
|
||||
return e.defaultPrevented
|
||||
})()
|
||||
}
|
||||
}
|
||||
|
||||
// Event constructor shim
|
||||
if (!window.Event || typeof window.Event !== 'function') {
|
||||
// Event constructor shim
|
||||
if (!window.Event || typeof window.Event !== 'function') {
|
||||
const origEvent = window.Event
|
||||
window.Event = (inType, params) => {
|
||||
params = params || {}
|
||||
@@ -74,27 +82,29 @@ if (!window.Event || typeof window.Event !== 'function') {
|
||||
return e
|
||||
}
|
||||
window.Event.prototype = origEvent.prototype
|
||||
}
|
||||
}
|
||||
|
||||
const namespaceRegex = /[^.]*(?=\..*)\.|.*/
|
||||
const stripNameRegex = /\..*/
|
||||
const keyEventRegex = /^key/
|
||||
const stripUidRegex = /::\d+$/
|
||||
/**
|
||||
* ------------------------------------------------------------------------
|
||||
* Constants
|
||||
* ------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
// Events storage
|
||||
const eventRegistry = {}
|
||||
let uidEvent = 1
|
||||
|
||||
function getUidEvent(element, uid) {
|
||||
return element.uidEvent = uid && `${uid}::${uidEvent++}` || element.uidEvent || uidEvent++
|
||||
}
|
||||
|
||||
function getEvent(element) {
|
||||
const uid = getUidEvent(element)
|
||||
return eventRegistry[uid] = eventRegistry[uid] || {}
|
||||
}
|
||||
|
||||
const nativeEvents = [
|
||||
const TransitionEndEvent = {
|
||||
WebkitTransition : 'webkitTransitionEnd',
|
||||
transition : 'transitionend'
|
||||
}
|
||||
const namespaceRegex = /[^.]*(?=\..*)\.|.*/
|
||||
const stripNameRegex = /\..*/
|
||||
const keyEventRegex = /^key/
|
||||
const stripUidRegex = /::\d+$/
|
||||
const eventRegistry = {} // Events storage
|
||||
let uidEvent = 1
|
||||
const customEvents = {
|
||||
mouseenter: 'mouseover',
|
||||
mouseleave: 'mouseout'
|
||||
}
|
||||
const nativeEvents = [
|
||||
'click', 'dblclick', 'mouseup', 'mousedown', 'contextmenu',
|
||||
'mousewheel', 'DOMMouseScroll',
|
||||
'mouseover', 'mouseout', 'mousemove', 'selectstart', 'selectend',
|
||||
@@ -105,29 +115,40 @@ const nativeEvents = [
|
||||
'focus', 'blur', 'change', 'reset', 'select', 'submit', 'focusin', 'focusout',
|
||||
'load', 'unload', 'beforeunload', 'resize', 'move', 'DOMContentLoaded', 'readystatechange',
|
||||
'error', 'abort', 'scroll'
|
||||
]
|
||||
]
|
||||
|
||||
const customEvents = {
|
||||
mouseenter: 'mouseover',
|
||||
mouseleave: 'mouseout'
|
||||
}
|
||||
/**
|
||||
* ------------------------------------------------------------------------
|
||||
* Private methods
|
||||
* ------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
function fixEvent(event) {
|
||||
|
||||
function getUidEvent(element, uid) {
|
||||
return element.uidEvent = uid && `${uid}::${uidEvent++}` || element.uidEvent || uidEvent++
|
||||
}
|
||||
|
||||
function getEvent(element) {
|
||||
const uid = getUidEvent(element)
|
||||
return eventRegistry[uid] = eventRegistry[uid] || {}
|
||||
}
|
||||
|
||||
function fixEvent(event) {
|
||||
// Add which for key events
|
||||
if (event.which === null && keyEventRegex.test(event.type)) {
|
||||
event.which = event.charCode !== null ? event.charCode : event.keyCode
|
||||
}
|
||||
return event
|
||||
}
|
||||
}
|
||||
|
||||
function bootstrapHandler(element, fn) {
|
||||
function bootstrapHandler(element, fn) {
|
||||
return function (event) {
|
||||
event = fixEvent(event)
|
||||
return fn.apply(element, [event])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function bootstrapDelegationHandler(element, selector, fn) {
|
||||
function bootstrapDelegationHandler(element, selector, fn) {
|
||||
return function (event) {
|
||||
event = fixEvent(event)
|
||||
const domElements = element.querySelectorAll(selector)
|
||||
@@ -141,16 +162,16 @@ function bootstrapDelegationHandler(element, selector, fn) {
|
||||
// To please ESLint
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function removeHandler(element, events, typeEvent, handler) {
|
||||
function removeHandler(element, events, typeEvent, handler) {
|
||||
const uidEvent = handler.uidEvent
|
||||
const fn = events[typeEvent][uidEvent]
|
||||
element.removeEventListener(typeEvent, fn, fn.delegation)
|
||||
delete events[typeEvent][uidEvent]
|
||||
}
|
||||
}
|
||||
|
||||
function removeNamespacedHandlers(element, events, typeEvent, namespace) {
|
||||
function removeNamespacedHandlers(element, events, typeEvent, namespace) {
|
||||
const storeElementEvent = events[typeEvent] || {}
|
||||
for (const handlerKey in storeElementEvent) {
|
||||
if (!Object.prototype.hasOwnProperty.call(storeElementEvent, handlerKey)) {
|
||||
@@ -161,9 +182,9 @@ function removeNamespacedHandlers(element, events, typeEvent, namespace) {
|
||||
removeHandler(element, events, typeEvent, storeElementEvent[handlerKey].originalHandler)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const EventHandler = {
|
||||
return {
|
||||
on(element, originalTypeEvent, handler, delegationFn) {
|
||||
if (typeof originalTypeEvent !== 'string' ||
|
||||
(typeof element === 'undefined' || element === null)) {
|
||||
@@ -325,7 +346,8 @@ const EventHandler = {
|
||||
|
||||
return evt
|
||||
}
|
||||
}
|
||||
}
|
||||
})()
|
||||
|
||||
// focusin and focusout polyfill
|
||||
if (typeof window.onfocusin === 'undefined') {
|
||||
|
@@ -5,19 +5,28 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
// matches polyfill (see: https://mzl.la/2ikXneG)
|
||||
let fnMatches = null
|
||||
if (!Element.prototype.matches) {
|
||||
const SelectorEngine = (() => {
|
||||
|
||||
|
||||
/**
|
||||
* ------------------------------------------------------------------------
|
||||
* Polyfills
|
||||
* ------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
// matches polyfill (see: https://mzl.la/2ikXneG)
|
||||
let fnMatches = null
|
||||
if (!Element.prototype.matches) {
|
||||
fnMatches =
|
||||
Element.prototype.msMatchesSelector ||
|
||||
Element.prototype.webkitMatchesSelector
|
||||
} else {
|
||||
} else {
|
||||
fnMatches = Element.prototype.matches
|
||||
}
|
||||
}
|
||||
|
||||
// closest polyfill (see: https://mzl.la/2vXggaI)
|
||||
let fnClosest = null
|
||||
if (!Element.prototype.closest) {
|
||||
// closest polyfill (see: https://mzl.la/2vXggaI)
|
||||
let fnClosest = null
|
||||
if (!Element.prototype.closest) {
|
||||
fnClosest = (element, selector) => {
|
||||
let ancestor = element
|
||||
if (!document.documentElement.contains(element)) {
|
||||
@@ -34,14 +43,14 @@ if (!Element.prototype.closest) {
|
||||
|
||||
return null
|
||||
}
|
||||
} else {
|
||||
} else {
|
||||
// eslint-disable-next-line arrow-body-style
|
||||
fnClosest = (element, selector) => {
|
||||
return element.closest(selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const SelectorEngine = {
|
||||
return {
|
||||
matches(element, selector) {
|
||||
return fnMatches.call(element, selector)
|
||||
},
|
||||
@@ -75,6 +84,7 @@ const SelectorEngine = {
|
||||
closest(element, selector) {
|
||||
return fnClosest(element, selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
})()
|
||||
|
||||
export default SelectorEngine
|
||||
|
Reference in New Issue
Block a user