From 2eb6eaf52ff26ecae721fcd4f07e0efe93a62733 Mon Sep 17 00:00:00 2001 From: Francesco Cretti Date: Wed, 20 Jun 2018 18:07:43 +0200 Subject: [PATCH] preventDefaultAction support --- src/navigator.js | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/src/navigator.js b/src/navigator.js index 392d9e15..944892d0 100644 --- a/src/navigator.js +++ b/src/navigator.js @@ -405,18 +405,14 @@ $.extend( $.Navigator.prototype, $.EventSource.prototype, $.Viewer.prototype, /* * @function */ function onCanvasClick( event ) { - if (event.quick && this.viewer.viewport && (this.panVertical || this.panHorizontal)) { - var target = this.viewport.pointFromPixel(event.position); - if (!this.panVertical) { - // perform only horizonal pan - target.y = this.viewer.viewport.getCenter(true).y; - } else if (!this.panHorizontal) { - // perform only vertical pan - target.x = this.viewer.viewport.getCenter(true).x; - } - this.viewer.viewport.panTo(target); - this.viewer.viewport.applyConstraints(); - } + var canvasClickEventArgs = { + tracker: event.eventSource, + position: event.position, + quick: event.quick, + shift: event.shift, + originalEvent: event.originalEvent, + preventDefaultAction: event.preventDefaultAction + }; /** * Raised when a click event occurs on the {@link OpenSeadragon.Viewer#navigator} element. * @@ -430,14 +426,24 @@ function onCanvasClick( event ) { * @property {Boolean} shift - True if the shift key was pressed during this event. * @property {Object} originalEvent - The original DOM event. * @property {?Object} userData - Arbitrary subscriber-defined object. + * @property {Boolean} preventDefaultAction - Set to true to prevent default click to zoom behaviour. Default: false. */ - this.viewer.raiseEvent('navigator-click', { - tracker: event.eventSource, - position: event.position, - quick: event.quick, - shift: event.shift, - originalEvent: event.originalEvent - }); + + this.viewer.raiseEvent('navigator-click', canvasClickEventArgs); + + if ( !canvasClickEventArgs.preventDefaultAction && event.quick && this.viewer.viewport && (this.panVertical || this.panHorizontal)) { + var target = this.viewport.pointFromPixel(event.position); + if (!this.panVertical) { + // perform only horizonal pan + target.y = this.viewer.viewport.getCenter(true).y; + } else if (!this.panHorizontal) { + // perform only vertical pan + target.x = this.viewer.viewport.getCenter(true).x; + } + this.viewer.viewport.panTo(target); + this.viewer.viewport.applyConstraints(); + } + } /**