Skip to content

Commit

Permalink
EventHandler: change check method for custom events, avoiding regex
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoSot authored and mdo committed Apr 26, 2022
1 parent 9a614a7 commit 3edead4
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions js/src/dom/event-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const customEvents = {
mouseenter: 'mouseover',
mouseleave: 'mouseout'
}
const customEventsRegex = /^(mouseenter|mouseleave)/i

const nativeEvents = new Set([
'click',
'dblclick',
Expand Down Expand Up @@ -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
// 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 => {
return function (event) {
if (!event.relatedTarget || (event.relatedTarget !== event.delegateTarget && !event.delegateTarget.contains(event.relatedTarget))) {
Expand Down

0 comments on commit 3edead4

Please sign in to comment.