From 3947c81726a3944575d29764d8c233310d8df6da Mon Sep 17 00:00:00 2001 From: Mark Salsbery <> Date: Tue, 16 Mar 2021 10:40:36 -0700 Subject: [PATCH 1/4] 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; } From 84c23c3729420e4325e4a84c6d58d899b6c704bf Mon Sep 17 00:00:00 2001 From: Mark Salsbery <> Date: Tue, 16 Mar 2021 10:42:54 -0700 Subject: [PATCH 2/4] changelog update --- changelog.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.txt b/changelog.txt index f6050b1d..56b97c66 100644 --- a/changelog.txt +++ b/changelog.txt @@ -38,7 +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) +* Added dragToPan to the GestureSettings class, implemented in Viewer (#1956 @msalsbery) 2.4.2: From 033c16ca85e8658af5e4aad74f871b3a838ab40a Mon Sep 17 00:00:00 2001 From: Mark Salsbery <> Date: Tue, 16 Mar 2021 11:27:48 -0700 Subject: [PATCH 3/4] Remember to initialize new properties! Code cleanup... --- src/navigator.js | 12 ++++-------- src/openseadragon.js | 4 ++++ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/navigator.js b/src/navigator.js index e59e325a..d088c098 100644 --- a/src/navigator.js +++ b/src/navigator.js @@ -232,14 +232,10 @@ $.Navigator = function( options ){ releaseHandler: $.delegate( this, onCanvasRelease ), 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; + if (eventInfo.eventType === 'wheel') { + //don't scroll the page up and down if the user is scrolling + //in the navigator + eventInfo.preventDefault = true; } } }); diff --git a/src/openseadragon.js b/src/openseadragon.js index c78948df..542a3abf 100644 --- a/src/openseadragon.js +++ b/src/openseadragon.js @@ -1144,6 +1144,7 @@ function OpenSeadragon( options ){ springStiffness: 6.5, animationTime: 1.2, gestureSettingsMouse: { + dragToPan: true, scrollToZoom: true, clickToZoom: true, dblClickToZoom: false, @@ -1155,6 +1156,7 @@ function OpenSeadragon( options ){ pinchRotate: false }, gestureSettingsTouch: { + dragToPan: true, scrollToZoom: false, clickToZoom: false, dblClickToZoom: true, @@ -1166,6 +1168,7 @@ function OpenSeadragon( options ){ pinchRotate: false }, gestureSettingsPen: { + dragToPan: true, scrollToZoom: false, clickToZoom: true, dblClickToZoom: false, @@ -1177,6 +1180,7 @@ function OpenSeadragon( options ){ pinchRotate: false }, gestureSettingsUnknown: { + dragToPan: true, scrollToZoom: false, clickToZoom: false, dblClickToZoom: true, From 38a6189c20ac6452a968cdc5d41acffcdb1fd1a3 Mon Sep 17 00:00:00 2001 From: Mark Salsbery <> Date: Tue, 16 Mar 2021 11:37:32 -0700 Subject: [PATCH 4/4] code cleanup --- src/referencestrip.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/referencestrip.js b/src/referencestrip.js index 00b62a47..738a55ab 100644 --- a/src/referencestrip.js +++ b/src/referencestrip.js @@ -123,12 +123,8 @@ $.ReferenceStrip = function ( options ) { keyDownHandler: $.delegate( this, onKeyDown ), keyHandler: $.delegate( this, onKeyPress ), preProcessEventHandler: function (eventInfo) { - switch (eventInfo.eventType) { - case 'wheel': - eventInfo.preventDefault = true; - break; - default: - break; + if (eventInfo.eventType === 'wheel') { + eventInfo.preventDefault = true; } } } );