Skip to content

Commit

Permalink
actions: only use left mouse button by default
Browse files Browse the repository at this point in the history
This can be changed for drag and resize actions:

    interact(target)
    .draggable({
      mouseButtons: buttonsMask,
    })
    .resizeable({
      mouseButtons: buttonsMask,
    });

buttonMask may be:

 1 for only the left button (default)
 2 for only the right button
 4 for only the middle (wheel) button

or any logical OR of those values to allow from any one of several
buttons. E.g. 2|4 = 6 for either the right or middle button.

See https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons#Return_value

Close #376
  • Loading branch information
taye committed Nov 30, 2016
1 parent bb503b5 commit 54ebdc3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/actions/drag.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const defaultOptions = require('../defaultOptions');

const drag = {
defaults: {
enabled : false,
enabled : false,
mouseButtons: null,

origin : null,
snap : null,
Expand Down
3 changes: 2 additions & 1 deletion src/actions/resize.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const defaultMargin = browser.supportsTouch || browser.supportsPointerEvent? 20:

const resize = {
defaults: {
enabled : false,
enabled : false,
mouseButtons: null,

origin : null,
snap : null,
Expand Down
7 changes: 7 additions & 0 deletions src/autoStart/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,13 @@ Interactable.prototype.defaultActionChecker = function (pointer, event, interact
let action = null;

for (const actionName of actions.names) {
// check mouseButton setting if the pointer is down
if (interaction.pointerIsDown
&& interaction.mouse
&& (event.buttons & this.options[actionName].mouseButtons) === 0) {
continue;
}

action = actions[actionName].checker(pointer, event, this, element, interaction, rect);

if (action) {
Expand Down
4 changes: 4 additions & 0 deletions src/defaultOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ module.exports = {
perAction: {
origin: { x: 0, y: 0 },

// only allow left button by default
// see https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons#Return_value
mouseButtons: 1,

inertia: {
enabled : false,
resistance : 10, // the lambda in exponential decay
Expand Down

0 comments on commit 54ebdc3

Please sign in to comment.