0
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-03-02 02:29:24 +01:00

Wrap our objects into IIFE

This commit is contained in:
Johann-S 2017-09-20 14:19:10 +02:00 committed by XhmikosR
parent bcbea02886
commit 7c1d0a1097
3 changed files with 419 additions and 377 deletions

View File

@ -5,6 +5,15 @@
* --------------------------------------------------------------------------
*/
const Data = (() => {
/**
* ------------------------------------------------------------------------
* Constants
* ------------------------------------------------------------------------
*/
const mapData = (() => {
const storeData = {}
let id = 1
@ -45,7 +54,7 @@ const mapData = (() => {
}
})()
const Data = {
return {
setData(instance, key, data) {
mapData.set(instance, key, data)
},
@ -56,5 +65,6 @@ const Data = {
mapData.delete(instance, key)
}
}
})()
export default Data

View File

@ -7,6 +7,14 @@ import Util from '../util'
* --------------------------------------------------------------------------
*/
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 = (() => {
@ -76,24 +84,26 @@ if (!window.Event || typeof window.Event !== 'function') {
window.Event.prototype = origEvent.prototype
}
/**
* ------------------------------------------------------------------------
* Constants
* ------------------------------------------------------------------------
*/
const TransitionEndEvent = {
WebkitTransition : 'webkitTransitionEnd',
transition : 'transitionend'
}
const namespaceRegex = /[^.]*(?=\..*)\.|.*/
const stripNameRegex = /\..*/
const keyEventRegex = /^key/
const stripUidRegex = /::\d+$/
// Events storage
const eventRegistry = {}
const eventRegistry = {} // Events storage
let uidEvent = 1
function getUidEvent(element, uid) {
return element.uidEvent = uid && `${uid}::${uidEvent++}` || element.uidEvent || uidEvent++
const customEvents = {
mouseenter: 'mouseover',
mouseleave: 'mouseout'
}
function getEvent(element) {
const uid = getUidEvent(element)
return eventRegistry[uid] = eventRegistry[uid] || {}
}
const nativeEvents = [
'click', 'dblclick', 'mouseup', 'mousedown', 'contextmenu',
'mousewheel', 'DOMMouseScroll',
@ -107,9 +117,20 @@ const nativeEvents = [
'error', 'abort', 'scroll'
]
const customEvents = {
mouseenter: 'mouseover',
mouseleave: 'mouseout'
/**
* ------------------------------------------------------------------------
* Private methods
* ------------------------------------------------------------------------
*/
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) {
@ -163,7 +184,7 @@ function removeNamespacedHandlers(element, events, typeEvent, namespace) {
}
}
const EventHandler = {
return {
on(element, originalTypeEvent, handler, delegationFn) {
if (typeof originalTypeEvent !== 'string' ||
(typeof element === 'undefined' || element === null)) {
@ -326,6 +347,7 @@ const EventHandler = {
return evt
}
}
})()
// focusin and focusout polyfill
if (typeof window.onfocusin === 'undefined') {

View File

@ -5,6 +5,15 @@
* --------------------------------------------------------------------------
*/
const SelectorEngine = (() => {
/**
* ------------------------------------------------------------------------
* Polyfills
* ------------------------------------------------------------------------
*/
// matches polyfill (see: https://mzl.la/2ikXneG)
let fnMatches = null
if (!Element.prototype.matches) {
@ -41,7 +50,7 @@ if (!Element.prototype.closest) {
}
}
const SelectorEngine = {
return {
matches(element, selector) {
return fnMatches.call(element, selector)
},
@ -76,5 +85,6 @@ const SelectorEngine = {
return fnClosest(element, selector)
}
}
})()
export default SelectorEngine