mirror of
https://github.com/twbs/bootstrap.git
synced 2025-09-26 05:19:15 +02:00
Comply to the new rules.
This commit is contained in:
@@ -18,26 +18,61 @@ import Polyfill from './polyfill'
|
||||
|
||||
const namespaceRegex = /[^.]*(?=\..*)\.|.*/
|
||||
const stripNameRegex = /\..*/
|
||||
const keyEventRegex = /^key/
|
||||
const stripUidRegex = /::\d+$/
|
||||
const eventRegistry = {} // Events storage
|
||||
let uidEvent = 1
|
||||
const customEvents = {
|
||||
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',
|
||||
'keydown', 'keypress', 'keyup',
|
||||
const nativeEvents = [
|
||||
'click',
|
||||
'dblclick',
|
||||
'mouseup',
|
||||
'mousedown',
|
||||
'contextmenu',
|
||||
'mousewheel',
|
||||
'DOMMouseScroll',
|
||||
'mouseover',
|
||||
'mouseout',
|
||||
'mousemove',
|
||||
'selectstart',
|
||||
'selectend',
|
||||
'keydown',
|
||||
'keypress',
|
||||
'keyup',
|
||||
'orientationchange',
|
||||
'touchstart', 'touchmove', 'touchend', 'touchcancel',
|
||||
'pointerdown', 'pointermove', 'pointerup', 'pointerleave', 'pointercancel',
|
||||
'gesturestart', 'gesturechange', 'gestureend',
|
||||
'focus', 'blur', 'change', 'reset', 'select', 'submit', 'focusin', 'focusout',
|
||||
'load', 'unload', 'beforeunload', 'resize', 'move', 'DOMContentLoaded', 'readystatechange',
|
||||
'error', 'abort', 'scroll'
|
||||
'touchstart',
|
||||
'touchmove',
|
||||
'touchend',
|
||||
'touchcancel',
|
||||
'pointerdown',
|
||||
'pointermove',
|
||||
'pointerup',
|
||||
'pointerleave',
|
||||
'pointercancel',
|
||||
'gesturestart',
|
||||
'gesturechange',
|
||||
'gestureend',
|
||||
'focus',
|
||||
'blur',
|
||||
'change',
|
||||
'reset',
|
||||
'select',
|
||||
'submit',
|
||||
'focusin',
|
||||
'focusout',
|
||||
'load',
|
||||
'unload',
|
||||
'beforeunload',
|
||||
'resize',
|
||||
'move',
|
||||
'DOMContentLoaded',
|
||||
'readystatechange',
|
||||
'error',
|
||||
'abort',
|
||||
'scroll'
|
||||
]
|
||||
|
||||
/**
|
||||
@@ -60,7 +95,7 @@ function getEvent(element) {
|
||||
function fixEvent(event, element) {
|
||||
// Add which for key events
|
||||
if (event.which === null && keyEventRegex.test(event.type)) {
|
||||
event.which = event.charCode !== null ? event.charCode : event.keyCode
|
||||
event.which = event.charCode === null ? event.keyCode : event.charCode
|
||||
}
|
||||
|
||||
event.delegateTarget = element
|
||||
@@ -81,7 +116,7 @@ function bootstrapDelegationHandler(element, selector, fn) {
|
||||
return function handler(event) {
|
||||
const domElements = element.querySelectorAll(selector)
|
||||
|
||||
for (let target = event.target; target && target !== this; target = target.parentNode) {
|
||||
for (let { target } = event; target && target !== this; target = target.parentNode) {
|
||||
for (let i = domElements.length; i--;) {
|
||||
if (domElements[i] === target) {
|
||||
fixEvent(event, target)
|
||||
@@ -147,8 +182,8 @@ function addHandler(element, originalTypeEvent, handler, delegationFn, oneOff) {
|
||||
}
|
||||
|
||||
const [delegation, originalHandler, typeEvent] = normalizeParams(originalTypeEvent, handler, delegationFn)
|
||||
const events = getEvent(element)
|
||||
const handlers = events[typeEvent] || (events[typeEvent] = {})
|
||||
const events = getEvent(element)
|
||||
const handlers = events[typeEvent] || (events[typeEvent] = {})
|
||||
const previousFn = findHandler(handlers, originalHandler, delegation ? handler : null)
|
||||
|
||||
if (previousFn) {
|
||||
@@ -158,7 +193,7 @@ function addHandler(element, originalTypeEvent, handler, delegationFn, oneOff) {
|
||||
}
|
||||
|
||||
const uid = getUidEvent(originalHandler, originalTypeEvent.replace(namespaceRegex, ''))
|
||||
const fn = !delegation ? bootstrapHandler(element, handler) : bootstrapDelegationHandler(element, handler, delegationFn)
|
||||
const fn = delegation ? bootstrapDelegationHandler(element, handler, delegationFn) : bootstrapHandler(element, handler)
|
||||
|
||||
fn.delegationSelector = delegation ? handler : null
|
||||
fn.originalHandler = originalHandler
|
||||
@@ -184,7 +219,7 @@ function removeNamespacedHandlers(element, events, typeEvent, namespace) {
|
||||
const storeElementEvent = events[typeEvent] || {}
|
||||
|
||||
Object.keys(storeElementEvent)
|
||||
.forEach((handlerKey) => {
|
||||
.forEach(handlerKey => {
|
||||
if (handlerKey.indexOf(namespace) > -1) {
|
||||
const event = storeElementEvent[handlerKey]
|
||||
|
||||
@@ -224,14 +259,14 @@ const EventHandler = {
|
||||
|
||||
if (isNamespace) {
|
||||
Object.keys(events)
|
||||
.forEach((elementEvent) => {
|
||||
.forEach(elementEvent => {
|
||||
removeNamespacedHandlers(element, events, elementEvent, originalTypeEvent.substr(1))
|
||||
})
|
||||
}
|
||||
|
||||
const storeElementEvent = events[typeEvent] || {}
|
||||
Object.keys(storeElementEvent)
|
||||
.forEach((keyHandlers) => {
|
||||
.forEach(keyHandlers => {
|
||||
const handlerKey = keyHandlers.replace(stripUidRegex, '')
|
||||
|
||||
if (!inNamespace || originalTypeEvent.indexOf(handlerKey) > -1) {
|
||||
@@ -247,9 +282,9 @@ const EventHandler = {
|
||||
return null
|
||||
}
|
||||
|
||||
const typeEvent = event.replace(stripNameRegex, '')
|
||||
const typeEvent = event.replace(stripNameRegex, '')
|
||||
const inNamespace = event !== typeEvent
|
||||
const isNative = nativeEvents.indexOf(typeEvent) > -1
|
||||
const isNative = nativeEvents.indexOf(typeEvent) > -1
|
||||
|
||||
let jQueryEvent
|
||||
let bubbles = true
|
||||
@@ -279,7 +314,7 @@ const EventHandler = {
|
||||
// merge custom informations in our event
|
||||
if (typeof args !== 'undefined') {
|
||||
Object.keys(args)
|
||||
.forEach((key) => {
|
||||
.forEach(key => {
|
||||
Object.defineProperty(evt, key, {
|
||||
get() {
|
||||
return args[key]
|
||||
|
Reference in New Issue
Block a user