Skip to content

Commit

Permalink
refactor: simplify custom events regex and move it to a variable
Browse files Browse the repository at this point in the history
requested by GeoSot - #33310 (comment)
  • Loading branch information
alpadev committed Apr 11, 2021
1 parent e20e7d0 commit ef82822
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions js/src/dom/event-handler.js
Expand Up @@ -22,6 +22,7 @@ const customEvents = {
mouseenter: 'mouseover',
mouseleave: 'mouseout'
}
const customEventsRegex = /^(mouseenter|mouseleave)/i
const nativeEvents = new Set([
'click',
'dblclick',
Expand Down Expand Up @@ -165,8 +166,8 @@ function addHandler(element, originalTypeEvent, handler, delegationFn, oneOff) {
}

// in case of mouseenter or mouseleave wrap the handler within a function that checks for its DOM position
// this prevents the handler getting triggered the same way as mouseover or mouseout does
if (/^mouse(enter|leave)/i.test(originalTypeEvent)) {
// this prevents the handler from being dispatched the same way as mouseover or mouseout does
if (customEventsRegex.test(originalTypeEvent)) {
const wrapFn = fn => {
return function (event) {
if (!event.relatedTarget || (event.relatedTarget !== event.delegateTarget && event.relatedTarget.contains(event.delegateTarget))) {
Expand Down

0 comments on commit ef82822

Please sign in to comment.