Skip to content

Commit bfa7cea

Browse files
committed
Change isMouseEvent() to compare event type to mouse event list
The original check isn’t valid anymore. It seems that jQuery 3.x is being “helpful” by normalizing all events to include pageX and pageY properties, even if the event that triggered it doesn’t supply that information. In jQuery versions 1 and 2 these properties are undefined if there was no relevant data, but in jQuery 3 they are set to `0`. This patch changes the check to match the event type to a list of known mouse events that are expected to supply valid pageX and pageY data. Part of issue #158.
1 parent 9e2d1a6 commit bfa7cea

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/core.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,19 @@ var DATA_DISPLAYCONTROLLER = 'displayController',
2323
DATA_POWERTIPJQ = 'powertipjq',
2424
DATA_POWERTIPTARGET = 'powertiptarget',
2525
EVENT_NAMESPACE = '.powertip',
26-
RAD2DEG = 180 / Math.PI;
26+
RAD2DEG = 180 / Math.PI,
27+
MOUSE_EVENTS = [
28+
'click',
29+
'dblclick',
30+
'mousedown',
31+
'mouseup',
32+
'mousemove',
33+
'mouseover',
34+
'mouseout',
35+
'mouseenter',
36+
'mouseleave',
37+
'contextmenu'
38+
];
2739

2840
/**
2941
* Session data

src/utility.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ function isSvgElement(element) {
2424
* @return {boolean} True if there is mouse data, otherwise false.
2525
*/
2626
function isMouseEvent(event) {
27-
return Boolean(event && typeof event.pageX === 'number');
27+
return Boolean(event && $.inArray(event.type, MOUSE_EVENTS) > -1 &&
28+
typeof event.pageX === 'number');
2829
}
2930

3031
/**

0 commit comments

Comments
 (0)