From 5d4044f9883116eb185a9c67cfe009bd3ae4727b Mon Sep 17 00:00:00 2001 From: jos Date: Fri, 22 Aug 2014 15:20:55 +0200 Subject: [PATCH] Fixed page scroll event not being blocked when moving around in Network using arrow keys --- HISTORY.md | 2 ++ lib/network/mixins/NavigationMixin.js | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index d9216d85..00739e10 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -18,6 +18,8 @@ http://visjs.org - Fixed physics solving stopping when a support node was not moving. - Added localization support. - Implemented option `activatable`. +- Fixed page scroll event not being blocked when moving around in Network + using arrow keys. ### Graph2D diff --git a/lib/network/mixins/NavigationMixin.js b/lib/network/mixins/NavigationMixin.js index 6eb34616..1342e3a0 100644 --- a/lib/network/mixins/NavigationMixin.js +++ b/lib/network/mixins/NavigationMixin.js @@ -65,6 +65,7 @@ exports._stopMovement = function() { exports._moveUp = function(event) { this.yIncrement = this.constants.keyboard.speed.y; this.start(); // if there is no node movement, the calculation wont be done + event.preventDefault(); }; @@ -75,6 +76,7 @@ exports._moveUp = function(event) { exports._moveDown = function(event) { this.yIncrement = -this.constants.keyboard.speed.y; this.start(); // if there is no node movement, the calculation wont be done + event.preventDefault(); }; @@ -85,6 +87,7 @@ exports._moveDown = function(event) { exports._moveLeft = function(event) { this.xIncrement = this.constants.keyboard.speed.x; this.start(); // if there is no node movement, the calculation wont be done + event.preventDefault(); }; @@ -95,6 +98,7 @@ exports._moveLeft = function(event) { exports._moveRight = function(event) { this.xIncrement = -this.constants.keyboard.speed.y; this.start(); // if there is no node movement, the calculation wont be done + event.preventDefault(); }; @@ -105,6 +109,7 @@ exports._moveRight = function(event) { exports._zoomIn = function(event) { this.zoomIncrement = this.constants.keyboard.speed.zoom; this.start(); // if there is no node movement, the calculation wont be done + event.preventDefault(); }; @@ -112,10 +117,10 @@ exports._zoomIn = function(event) { * Zoom out * @private */ -exports._zoomOut = function() { +exports._zoomOut = function(event) { this.zoomIncrement = -this.constants.keyboard.speed.zoom; this.start(); // if there is no node movement, the calculation wont be done - util.preventDefault(event); + event.preventDefault(); }; @@ -123,8 +128,9 @@ exports._zoomOut = function() { * Stop zooming and unhighlight the zoom controls * @private */ -exports._stopZoom = function() { +exports._stopZoom = function(event) { this.zoomIncrement = 0; + event && event.preventDefault(); }; @@ -132,8 +138,9 @@ exports._stopZoom = function() { * Stop moving in the Y direction and unHighlight the up and down * @private */ -exports._yStopMoving = function() { +exports._yStopMoving = function(event) { this.yIncrement = 0; + event && event.preventDefault(); }; @@ -141,6 +148,7 @@ exports._yStopMoving = function() { * Stop moving in the X direction and unHighlight left and right. * @private */ -exports._xStopMoving = function() { +exports._xStopMoving = function(event) { this.xIncrement = 0; + event && event.preventDefault(); };