Skip to content

Commit

Permalink
fix(events): use the standard wheel event (#208)
Browse files Browse the repository at this point in the history
This event is now supported by all the browsers we care about. There's no need anymore to listen to the legacy events.
  • Loading branch information
Tyler-Maclachlan authored and Thomaash committed Nov 8, 2019
1 parent 46316d6 commit aa7e664
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 19 deletions.
3 changes: 1 addition & 2 deletions lib/network/modules/Canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,7 @@ class Canvas {
this.hammer.on('pinch', (event) => {this.body.eventListeners.onPinch(event)});

// TODO: neatly cleanup these handlers when re-creating the Canvas, IF these are done with hammer, event.stopPropagation will not work?
this.frame.canvas.addEventListener('mousewheel', (event) => {this.body.eventListeners.onMouseWheel(event)});
this.frame.canvas.addEventListener('DOMMouseScroll', (event) => {this.body.eventListeners.onMouseWheel(event)});
this.frame.canvas.addEventListener('wheel', (event) => {this.body.eventListeners.onMouseWheel(event)});

this.frame.canvas.addEventListener('mousemove', (event) => {this.body.eventListeners.onMouseMove(event)});
this.frame.canvas.addEventListener('contextmenu', (event) => {this.body.eventListeners.onContext(event)});
Expand Down
19 changes: 2 additions & 17 deletions lib/network/modules/InteractionHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -503,29 +503,14 @@ class InteractionHandler {
*/
onMouseWheel(event) {
if (this.options.zoomView === true) {
// retrieve delta
let delta = 0;
if (event.wheelDelta) { /* IE/Opera. */
delta = event.wheelDelta / 120;
}
else if (event.detail) { /* Mozilla case. */
// In Mozilla, sign of delta is different than in IE.
// Also, delta is multiple of 3.
delta = -event.detail / 3;
}

// If delta is nonzero, handle it.
// Basically, delta is now positive if wheel was scrolled up,
// and negative, if wheel was scrolled down.
if (delta !== 0) {
if (event.deltaY !== 0) {

// calculate the new scale
let scale = this.body.view.scale;
let zoom = delta * (this.options.zoomSpeed / 10);
if (delta < 0) {
zoom = zoom / (1 - zoom);
}
scale *= (1 + zoom);
scale *= 1 + (event.deltaY < 0 ? 1 : -1) * (this.options.zoomSpeed * 0.1);

// calculate the pointer location
let pointer = this.getPointer({x: event.clientX, y: event.clientY});
Expand Down

0 comments on commit aa7e664

Please sign in to comment.