From 3947c81726a3944575d29764d8c233310d8df6da Mon Sep 17 00:00:00 2001 From: Mark Salsbery <> Date: Tue, 16 Mar 2021 10:40:36 -0700 Subject: [PATCH] Added dragToPan to the GestureSettings class, implemented in Viewer --- changelog.txt | 1 + src/navigator.js | 17 ++++++++++++----- src/openseadragon.js | 7 +++++++ src/referencestrip.js | 16 ++++++++++------ src/viewer.js | 5 +++-- 5 files changed, 33 insertions(+), 13 deletions(-) diff --git a/changelog.txt b/changelog.txt index ab324cfb..f6050b1d 100644 --- a/changelog.txt +++ b/changelog.txt @@ -38,6 +38,7 @@ OPENSEADRAGON CHANGELOG * Added preventDefault option to MouseTracker.contextMenuHandler and Viewer 'canvas-contextmenu' event args (#1951 @msalsbery) * MouseTracker: Added preProcessEventHandler for keydown, keyup, keypress, focus, blur Events (#1951 @msalsbery) * Fixed preventDefaultAction functionality in viewer events (#1953 @msalsbery) +* Added dragToPan to the GestureSettings class, implemented in Viewer (# @msalsbery) 2.4.2: diff --git a/src/navigator.js b/src/navigator.js index 82d2cbad..e59e325a 100644 --- a/src/navigator.js +++ b/src/navigator.js @@ -230,7 +230,18 @@ $.Navigator = function( options ){ dragHandler: $.delegate( this, onCanvasDrag ), clickHandler: $.delegate( this, onCanvasClick ), releaseHandler: $.delegate( this, onCanvasRelease ), - scrollHandler: $.delegate( this, onCanvasScroll ) + scrollHandler: $.delegate( this, onCanvasScroll ), + preProcessEventHandler: function (eventInfo) { + switch (eventInfo.eventType) { + case 'wheel': + //don't scroll the page up and down if the user is scrolling + //in the navigator + eventInfo.preventDefault = true; + break; + default: + break; + } + } }); this.outerTracker.userData = 'Navigator.outerTracker'; @@ -607,10 +618,6 @@ function onCanvasScroll( event ) { shift: event.shift, originalEvent: event.originalEvent }); - - //don't scroll the page up and down if the user is scrolling - //in the navigator - return false; } /** diff --git a/src/openseadragon.js b/src/openseadragon.js index f61e0133..c78948df 100644 --- a/src/openseadragon.js +++ b/src/openseadragon.js @@ -320,6 +320,7 @@ * * @property {OpenSeadragon.GestureSettings} [gestureSettingsMouse] * Settings for gestures generated by a mouse pointer device. (See {@link OpenSeadragon.GestureSettings}) + * @property {Boolean} [gestureSettingsMouse.dragToPan=true] - Pan on drag gesture * @property {Boolean} [gestureSettingsMouse.scrollToZoom=true] - Zoom on scroll gesture * @property {Boolean} [gestureSettingsMouse.clickToZoom=true] - Zoom on click gesture * @property {Boolean} [gestureSettingsMouse.dblClickToZoom=false] - Zoom on double-click gesture. Note: If set to true @@ -334,6 +335,7 @@ * * @property {OpenSeadragon.GestureSettings} [gestureSettingsTouch] * Settings for gestures generated by a touch pointer device. (See {@link OpenSeadragon.GestureSettings}) + * @property {Boolean} [gestureSettingsMouse.dragToPan=true] - Pan on drag gesture * @property {Boolean} [gestureSettingsTouch.scrollToZoom=false] - Zoom on scroll gesture * @property {Boolean} [gestureSettingsTouch.clickToZoom=false] - Zoom on click gesture * @property {Boolean} [gestureSettingsTouch.dblClickToZoom=true] - Zoom on double-click gesture. Note: If set to true @@ -348,6 +350,7 @@ * * @property {OpenSeadragon.GestureSettings} [gestureSettingsPen] * Settings for gestures generated by a pen pointer device. (See {@link OpenSeadragon.GestureSettings}) + * @property {Boolean} [gestureSettingsMouse.dragToPan=true] - Pan on drag gesture * @property {Boolean} [gestureSettingsPen.scrollToZoom=false] - Zoom on scroll gesture * @property {Boolean} [gestureSettingsPen.clickToZoom=true] - Zoom on click gesture * @property {Boolean} [gestureSettingsPen.dblClickToZoom=false] - Zoom on double-click gesture. Note: If set to true @@ -362,6 +365,7 @@ * * @property {OpenSeadragon.GestureSettings} [gestureSettingsUnknown] * Settings for gestures generated by unknown pointer devices. (See {@link OpenSeadragon.GestureSettings}) + * @property {Boolean} [gestureSettingsMouse.dragToPan=true] - Pan on drag gesture * @property {Boolean} [gestureSettingsUnknown.scrollToZoom=true] - Zoom on scroll gesture * @property {Boolean} [gestureSettingsUnknown.clickToZoom=false] - Zoom on click gesture * @property {Boolean} [gestureSettingsUnknown.dblClickToZoom=true] - Zoom on double-click gesture. Note: If set to true @@ -651,6 +655,9 @@ * @typedef {Object} GestureSettings * @memberof OpenSeadragon * + * @property {Boolean} dragToPan + * Set to false to disable panning on drag gestures. + * * @property {Boolean} scrollToZoom * Set to false to disable zooming on scroll gestures. * diff --git a/src/referencestrip.js b/src/referencestrip.js index 80ebf566..00b62a47 100644 --- a/src/referencestrip.js +++ b/src/referencestrip.js @@ -121,7 +121,16 @@ $.ReferenceStrip = function ( options ) { enterHandler: $.delegate( this, onStripEnter ), leaveHandler: $.delegate( this, onStripLeave ), keyDownHandler: $.delegate( this, onKeyDown ), - keyHandler: $.delegate( this, onKeyPress ) + keyHandler: $.delegate( this, onKeyPress ), + preProcessEventHandler: function (eventInfo) { + switch (eventInfo.eventType) { + case 'wheel': + eventInfo.preventDefault = true; + break; + default: + break; + } + } } ); //Controls the position and orientation of the reference strip and sets the @@ -348,7 +357,6 @@ function onStripDrag( event ) { } } } - return false; } @@ -397,8 +405,6 @@ function onStripScroll( event ) { } } } - //cancels event - return false; } @@ -489,7 +495,6 @@ function onStripEnter( event ) { element.style.marginLeft = "0px"; } - return false; } @@ -512,7 +517,6 @@ function onStripLeave( event ) { element.style.marginLeft = "-" + ( $.getElementSize( element ).x / 2 ) + "px"; } - return false; } diff --git a/src/viewer.js b/src/viewer.js index 6e9c65b1..c22d3f34 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -2846,8 +2846,9 @@ function onCanvasDrag( event ) { */ this.raiseEvent( 'canvas-drag', canvasDragEventArgs); - if ( !canvasDragEventArgs.preventDefaultAction && this.viewport ) { - gestureSettings = this.gestureSettingsByDeviceType( event.pointerType ); + gestureSettings = this.gestureSettingsByDeviceType( event.pointerType ); + + if ( gestureSettings.dragToPan && !canvasDragEventArgs.preventDefaultAction && this.viewport ) { if( !this.panHorizontal ){ event.delta.x = 0; }