From 54ebdc3ee112eeb63bcdcaee5007566e226a9d07 Mon Sep 17 00:00:00 2001 From: Taye Adeyemi Date: Wed, 30 Nov 2016 02:31:02 +0000 Subject: [PATCH] actions: only use left mouse button by default 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 --- src/actions/drag.js | 3 ++- src/actions/resize.js | 3 ++- src/autoStart/index.js | 7 +++++++ src/defaultOptions.js | 4 ++++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/actions/drag.js b/src/actions/drag.js index 0286931fe..0284b295d 100644 --- a/src/actions/drag.js +++ b/src/actions/drag.js @@ -7,7 +7,8 @@ const defaultOptions = require('../defaultOptions'); const drag = { defaults: { - enabled : false, + enabled : false, + mouseButtons: null, origin : null, snap : null, diff --git a/src/actions/resize.js b/src/actions/resize.js index cd43c24ff..0b89a7433 100644 --- a/src/actions/resize.js +++ b/src/actions/resize.js @@ -11,7 +11,8 @@ const defaultMargin = browser.supportsTouch || browser.supportsPointerEvent? 20: const resize = { defaults: { - enabled : false, + enabled : false, + mouseButtons: null, origin : null, snap : null, diff --git a/src/autoStart/index.js b/src/autoStart/index.js index d9617d813..1a8afcff5 100644 --- a/src/autoStart/index.js +++ b/src/autoStart/index.js @@ -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) { diff --git a/src/defaultOptions.js b/src/defaultOptions.js index 311a6c3a3..9bfb44031 100644 --- a/src/defaultOptions.js +++ b/src/defaultOptions.js @@ -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