0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-12-01 13:24:25 +01:00

EventHandler: change check method for custom events, avoiding regex

This commit is contained in:
GeoSot 2022-04-18 01:30:56 +03:00 committed by Mark Otto
parent 9a614a7e1d
commit 3edead4ffe

View File

@ -20,7 +20,7 @@ const customEvents = {
mouseenter: 'mouseover', mouseenter: 'mouseover',
mouseleave: 'mouseout' mouseleave: 'mouseout'
} }
const customEventsRegex = /^(mouseenter|mouseleave)/i
const nativeEvents = new Set([ const nativeEvents = new Set([
'click', 'click',
'dblclick', 'dblclick',
@ -150,7 +150,7 @@ function addHandler(element, originalTypeEvent, handler, delegationFunction, one
// in case of mouseenter or mouseleave wrap the handler within a function that checks for its DOM position // in case of mouseenter or mouseleave wrap the handler within a function that checks for its DOM position
// this prevents the handler from being dispatched the same way as mouseover or mouseout does // this prevents the handler from being dispatched the same way as mouseover or mouseout does
if (customEventsRegex.test(originalTypeEvent)) { if (originalTypeEvent in customEvents) {
const wrapFunction = fn => { const wrapFunction = fn => {
return function (event) { return function (event) {
if (!event.relatedTarget || (event.relatedTarget !== event.delegateTarget && !event.delegateTarget.contains(event.relatedTarget))) { if (!event.relatedTarget || (event.relatedTarget !== event.delegateTarget && !event.delegateTarget.contains(event.relatedTarget))) {