Skip to content

Commit

Permalink
pointerEvents: add origin option
Browse files Browse the repository at this point in the history
Close #389
  • Loading branch information
taye committed Aug 27, 2016
1 parent 6cbaad6 commit 7823bb9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/pointerEvents/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -254,6 +266,7 @@ defaults.pointerEvents = {
holdDuration: 600,
ignoreFrom : null,
allowFrom : null,
origin : { x: 0, y: 0 },
};

module.exports = scope.pointerEvents = {
Expand Down
8 changes: 8 additions & 0 deletions src/pointerEvents/interactableTargets.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,18 @@ 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) {
extend(this.events.options, options);

return this;
};

Interactable.settingsMethods.push('pointerEvents');

0 comments on commit 7823bb9

Please sign in to comment.