Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempting to get the original target for click events #2037

Merged
merged 3 commits into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions src/mousetracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,8 @@
* True if the original event is a touch event, otherwise false. <span style="color:red;">Deprecated. Use pointerType and/or originalEvent instead.</span>
* @param {Object} event.originalEvent
* The original event object.
* @param {Element} event.originalTarget
* The DOM element clicked on.
* @param {Object} event.userData
* Arbitrary user-defined object.
*/
Expand Down Expand Up @@ -1191,7 +1193,7 @@
* the emulated event, a synthetic event object created with values from the actual DOM event,
* or null if no DOM event applies. Emulated events can occur on eventType "wheel" on legacy mouse-scroll
* event emitting user agents.
* @property {Boolean} isStopable
* @property {Boolean} isStoppable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix! ;-)

* True if propagation of the event (e.g. bubbling) can be stopped with stopPropagation/stopImmediatePropagation.
* @property {Boolean} isCancelable
* True if the event's default handling by the browser can be prevented with preventDefault.
Expand Down Expand Up @@ -2838,7 +2840,7 @@
function getEventProcessDefaults( tracker, eventInfo ) {
switch ( eventInfo.eventType ) {
case 'pointermove':
eventInfo.isStopable = true;
eventInfo.isStoppable = true;
eventInfo.isCancelable = true;
eventInfo.preventDefault = false;
eventInfo.preventGesture = !tracker.hasGestureHandlers;
Expand All @@ -2850,28 +2852,28 @@
case 'keydown':
case 'keyup':
case 'keypress':
eventInfo.isStopable = true;
eventInfo.isStoppable = true;
eventInfo.isCancelable = true;
eventInfo.preventDefault = false; // onContextMenu(), onKeyDown(), onKeyUp(), onKeyPress() may set true
eventInfo.preventGesture = false;
eventInfo.stopPropagation = false;
break;
case 'pointerdown':
eventInfo.isStopable = true;
eventInfo.isStoppable = true;
eventInfo.isCancelable = true;
eventInfo.preventDefault = false; // updatePointerDown() may set true (tracker.hasGestureHandlers)
eventInfo.preventGesture = !tracker.hasGestureHandlers;
eventInfo.stopPropagation = false;
break;
case 'pointerup':
eventInfo.isStopable = true;
eventInfo.isStoppable = true;
eventInfo.isCancelable = true;
eventInfo.preventDefault = false;
eventInfo.preventGesture = !tracker.hasGestureHandlers;
eventInfo.stopPropagation = false;
break;
case 'wheel':
eventInfo.isStopable = true;
eventInfo.isStoppable = true;
eventInfo.isCancelable = true;
eventInfo.preventDefault = false; // handleWheelEvent() may set true
eventInfo.preventGesture = !tracker.hasScrollHandler;
Expand All @@ -2880,21 +2882,21 @@
case 'gotpointercapture':
case 'lostpointercapture':
case 'pointercancel':
eventInfo.isStopable = true;
eventInfo.isStoppable = true;
eventInfo.isCancelable = false;
eventInfo.preventDefault = false;
eventInfo.preventGesture = false;
eventInfo.stopPropagation = false;
break;
case 'click':
eventInfo.isStopable = true;
eventInfo.isStoppable = true;
eventInfo.isCancelable = true;
eventInfo.preventDefault = !!tracker.clickHandler;
eventInfo.preventGesture = false;
eventInfo.stopPropagation = false;
break;
case 'dblclick':
eventInfo.isStopable = true;
eventInfo.isStoppable = true;
eventInfo.isCancelable = true;
eventInfo.preventDefault = !!tracker.dblClickHandler;
eventInfo.preventGesture = false;
Expand All @@ -2905,7 +2907,7 @@
case 'pointerenter':
case 'pointerleave':
default:
eventInfo.isStopable = false;
eventInfo.isStoppable = false;
eventInfo.isCancelable = false;
eventInfo.preventDefault = false;
eventInfo.preventGesture = false;
Expand Down Expand Up @@ -3272,6 +3274,7 @@
//updateGPoint.captured = true; // Handled by updatePointerCaptured()
updateGPoint.insideElementPressed = true;
updateGPoint.insideElement = true;
updateGPoint.originalTarget = eventInfo.originalEvent.target;
updateGPoint.contactPos = gPoint.currentPos;
updateGPoint.contactTime = gPoint.currentTime;
updateGPoint.lastPos = updateGPoint.currentPos;
Expand All @@ -3286,6 +3289,7 @@
gPoint.captured = false; // Handled by updatePointerCaptured()
gPoint.insideElementPressed = true;
gPoint.insideElement = true;
gPoint.originalTarget = eventInfo.originalEvent.target;
startTrackingPointer( pointsList, gPoint );
return;
}
Expand Down Expand Up @@ -3504,6 +3508,7 @@
shift: eventInfo.originalEvent.shiftKey,
isTouchEvent: updateGPoint.type === 'touch',
originalEvent: eventInfo.originalEvent,
originalTarget: updateGPoint.originalTarget,
userData: tracker.userData
}
);
Expand Down
2 changes: 2 additions & 0 deletions src/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2850,6 +2850,7 @@ function onCanvasClick( event ) {
quick: event.quick,
shift: event.shift,
originalEvent: event.originalEvent,
originalTarget: event.originalTarget,
preventDefaultAction: false
};

Expand All @@ -2865,6 +2866,7 @@ function onCanvasClick( event ) {
* @property {Boolean} quick - True only if the clickDistThreshold and clickTimeThreshold are both passed. Useful for differentiating between clicks and drags.
* @property {Boolean} shift - True if the shift key was pressed during this event.
* @property {Object} originalEvent - The original DOM event.
* @property {Element} originalTarget - The DOM element clicked on.
* @property {Boolean} preventDefaultAction - Set to true to prevent default click to zoom behaviour. Default: false.
* @property {?Object} userData - Arbitrary subscriber-defined object.
*/
Expand Down