From f0b15b5dc548925c26a49257502734e5ca5463eb Mon Sep 17 00:00:00 2001 From: Taye Adeyemi Date: Sat, 27 Aug 2016 12:55:42 +0200 Subject: [PATCH] pointerEvents: add origin option Close #389 --- src/pointerEvents/index.js | 13 +++++++++++++ src/pointerEvents/interactableTargets.js | 8 ++++++++ 2 files changed, 21 insertions(+) diff --git a/src/pointerEvents/index.js b/src/pointerEvents/index.js index df57e748d..f7711a892 100644 --- a/src/pointerEvents/index.js +++ b/src/pointerEvents/index.js @@ -86,8 +86,20 @@ function firePointers (interaction, pointer, event, eventTarget, targets, eventT pointerEvent[prop] = target.props[prop]; } + const { x: originX, y: originY } = utils.getOriginXY(target.eventable, target.element); + + pointerEvent.pageX -= originX; + pointerEvent.pageY -= originY; + pointerEvent.clientX -= originX; + pointerEvent.clientY -= originY; + target.eventable.fire(pointerEvent); + pointerEvent.pageX += originX; + pointerEvent.pageY += originY; + pointerEvent.clientX += originX; + pointerEvent.clientY += originY; + if (pointerEvent.immediatePropagationStopped || (pointerEvent.propagationStopped && (i + 1) < targets.length && targets[i + 1].element !== pointerEvent.currentTarget)) { @@ -254,6 +266,7 @@ defaults.pointerEvents = { holdDuration: 600, ignoreFrom : null, allowFrom : null, + origin : { x: 0, y: 0 }, }; module.exports = scope.pointerEvents = { diff --git a/src/pointerEvents/interactableTargets.js b/src/pointerEvents/interactableTargets.js index 72625803b..e7e76e342 100644 --- a/src/pointerEvents/interactableTargets.js +++ b/src/pointerEvents/interactableTargets.js @@ -49,6 +49,12 @@ pointerEvents.signals.on('collect-targets', function ({ targets, element, eventT scope.interactables.forEachSelector(collectSelectors); }); +Interactable.signals.on('new', function ({ interactable }) { + interactable.events.getRect = function (element) { + return interactable.getRect(element); + } +}); + merge(Interactable.eventTypes, pointerEvents.types); Interactable.prototype.pointerEvents = function (options) { @@ -56,3 +62,5 @@ Interactable.prototype.pointerEvents = function (options) { return this; }; + +Interactable.settingsMethods.push('pointerEvents');