Skip to content

Commit ef82822

Browse files
committed
refactor: simplify custom events regex and move it to a variable
requested by GeoSot - #33310 (comment)
1 parent e20e7d0 commit ef82822

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

js/src/dom/event-handler.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const customEvents = {
2222
mouseenter: 'mouseover',
2323
mouseleave: 'mouseout'
2424
}
25+
const customEventsRegex = /^(mouseenter|mouseleave)/i
2526
const nativeEvents = new Set([
2627
'click',
2728
'dblclick',
@@ -165,8 +166,8 @@ function addHandler(element, originalTypeEvent, handler, delegationFn, oneOff) {
165166
}
166167

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

0 commit comments

Comments
 (0)