2
0
mirror of https://github.com/tenrok/bootstrap.git synced 2026-06-17 19:21:23 +03:00

Fix delegation events

This commit is contained in:
Johann-S
2017-09-01 11:17:49 +02:00
committed by XhmikosR
parent 7d7873b6f2
commit 47242cd0fe
+4 -3
View File
@@ -115,7 +115,8 @@ const EventHandler = {
return return
} }
const delegation = typeof handler === 'string' const delegation = typeof handler === 'string'
const originalHandler = delegation ? delegationFn : handler
// allow to get the native events from namespaced events ('click.bs.button' --> 'click') // allow to get the native events from namespaced events ('click.bs.button' --> 'click')
let typeEvent = originalTypeEvent.replace(stripNameRegex, '') let typeEvent = originalTypeEvent.replace(stripNameRegex, '')
const isNative = nativeEvents.indexOf(typeEvent) > -1 const isNative = nativeEvents.indexOf(typeEvent) > -1
@@ -124,14 +125,14 @@ const EventHandler = {
} }
const events = getEvent(element) const events = getEvent(element)
const handlers = events[typeEvent] || (events[typeEvent] = {}) const handlers = events[typeEvent] || (events[typeEvent] = {})
const uid = getUidEvent(handler, originalTypeEvent.replace(namespaceRegex, '')) const uid = getUidEvent(originalHandler, originalTypeEvent.replace(namespaceRegex, ''))
if (handlers[uid]) { if (handlers[uid]) {
return return
} }
const fn = !delegation ? bootstrapHandler(element, handler) : bootstrapDelegationHandler(handler, delegationFn) const fn = !delegation ? bootstrapHandler(element, handler) : bootstrapDelegationHandler(handler, delegationFn)
handlers[uid] = fn handlers[uid] = fn
handler.uidEvent = uid originalHandler.uidEvent = uid
element.addEventListener(typeEvent, fn, false) element.addEventListener(typeEvent, fn, false)
}, },