Skip to content

Commit

Permalink
add panButton option
Browse files Browse the repository at this point in the history
  • Loading branch information
RickyTB committed Jun 19, 2023
1 parent 17a433d commit 8c14e65
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,18 @@ panzoom(element, {
});
```

## Change pan mouse button

When using a mouse, the default behaviour is clicking with the left button and drag to
pan, you can specify which mouse button you prefer with the option `panButton`, the
possible options are `left` or `middle`.

``` js
panzoom(element, {
panButton: 'left'
});
```

## Zoom Speed

You can adjust how fast it zooms, by passing optional `zoomSpeed` argument:
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ declare module "panzoom" {
enableTextSelection?: boolean;
disableKeyboardInteraction?: boolean;
transformOrigin?: TransformOrigin;
panButton?: 'left' | 'middle';
}

export interface PanZoom {
Expand Down
20 changes: 15 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ function createPanZoom(domElement, options) {
var speed = typeof options.zoomSpeed === 'number' ? options.zoomSpeed : defaultZoomSpeed;
var transformOrigin = parseTransformOrigin(options.transformOrigin);
var textSelection = options.enableTextSelection ? fakeTextSelectorInterceptor : domTextSelectionInterceptor;
var panButton = options.panButton || 'left';

validateBounds(bounds);

Expand Down Expand Up @@ -787,11 +788,20 @@ function createPanZoom(domElement, options) {
e.stopPropagation();
return false;
}
// for IE, left click == 1
// for Firefox, left click == 0
var isLeftButton =
(e.button === 1 && window.event !== null) || e.button === 0;
if (!isLeftButton) return;

if (panButton === 'left') {
// for IE, left click == 1
// for Firefox, left click == 0
var isLeftButton =
(e.button === 1 && window.event !== null) || e.button === 0;
if (!isLeftButton) return;
}

if (panButton === 'middle') {
var isMiddleButton =
(e.button === 3 && window.event !== null) || e.button === 1;
if (!isMiddleButton) return;
}

smoothScroll.cancel();

Expand Down

0 comments on commit 8c14e65

Please sign in to comment.