From 2386900e29d315ef7ee7b350d1b69a23ecf2a8f3 Mon Sep 17 00:00:00 2001 From: Antoine Vandecreme Date: Sun, 20 Mar 2016 11:01:26 -0400 Subject: [PATCH] Fix drag with panHorizontal/panVertical set to false. --- src/viewer.js | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/viewer.js b/src/viewer.js index 2154a094..a74292c0 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -2542,27 +2542,25 @@ function onCanvasDrag( event ) { } function onCanvasDragEnd( event ) { - var gestureSettings; - - if ( !event.preventDefaultAction && this.viewport ) { - gestureSettings = this.gestureSettingsByDeviceType( event.pointerType ); + if (!event.preventDefaultAction && this.viewport) { + var gestureSettings = this.gestureSettingsByDeviceType(event.pointerType); if (gestureSettings.flickEnabled && event.speed >= gestureSettings.flickMinSpeed) { - var amplitudeX = gestureSettings.flickMomentum * event.speed * - Math.cos(event.direction); - var amplitudeY = gestureSettings.flickMomentum * event.speed * - Math.sin(event.direction); + var amplitudeX = 0; + if (this.panHorizontal) { + amplitudeX = gestureSettings.flickMomentum * event.speed * + Math.cos(event.direction); + } + var amplitudeY = 0; + if (this.panVertical) { + amplitudeY = gestureSettings.flickMomentum * event.speed * + Math.sin(event.direction); + } var center = this.viewport.pixelFromPoint( this.viewport.getCenter(true)); var target = this.viewport.pointFromPixel( new $.Point(center.x - amplitudeX, center.y - amplitudeY)); - if( !this.panHorizontal ) { - target.x = center.x; - } - if( !this.panVertical ) { - target.y = center.y; - } - this.viewport.panTo( target, false ); + this.viewport.panTo(target, false); } this.viewport.applyConstraints(); } @@ -2581,7 +2579,7 @@ function onCanvasDragEnd( event ) { * @property {Object} originalEvent - The original DOM event. * @property {?Object} userData - Arbitrary subscriber-defined object. */ - this.raiseEvent( 'canvas-drag-end', { + this.raiseEvent('canvas-drag-end', { tracker: event.eventSource, position: event.position, speed: event.speed,