From 027dac0d8e46e937e0309d6aa8da6d6e7314aeb3 Mon Sep 17 00:00:00 2001 From: Francesco Cretti Date: Wed, 7 Mar 2018 11:25:33 +0100 Subject: [PATCH 1/4] navigato minimap onClick vertical/horizontal pan fix --- src/navigator.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/navigator.js b/src/navigator.js index 4c9848cf..45b56b6c 100644 --- a/src/navigator.js +++ b/src/navigator.js @@ -405,10 +405,26 @@ $.extend( $.Navigator.prototype, $.EventSource.prototype, $.Viewer.prototype, /* * @function */ function onCanvasClick( event ) { - if ( event.quick && this.viewer.viewport ) { - this.viewer.viewport.panTo(this.viewport.pointFromPixel(event.position)); - this.viewer.viewport.applyConstraints(); + if (event.quick && this.viewer.viewport && (this.panVertical || this.panHorizontal)) { + var target, + posX, + posY; + if (!this.panVertical) { + // perform only horizonal pan + posX = this.viewport.pointFromPixel(event.position).x; + posY = this.viewport.getCenter().y; + target = new $.Point(posX, posY); + } else if (!this.panHorizontal) { + // perform only vertical pan + posX = this.viewport.getCenter().x; + posY = this.viewport.pointFromPixel(event.position).y; + target = new $.Point(posX, posY); + } else { + target = this.viewport.pointFromPixel(event.position); } + this.viewer.viewport.panTo(target); + this.viewer.viewport.applyConstraints(); + } } /** From 12be95c8c3526f99717dba728a347826da613fcd Mon Sep 17 00:00:00 2001 From: Francesco Cretti Date: Sun, 11 Mar 2018 13:05:19 +0100 Subject: [PATCH 2/4] getCenter fixed when clicking on minimap --- src/navigator.js | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/navigator.js b/src/navigator.js index 45b56b6c..84e3ad51 100644 --- a/src/navigator.js +++ b/src/navigator.js @@ -406,21 +406,13 @@ $.extend( $.Navigator.prototype, $.EventSource.prototype, $.Viewer.prototype, /* */ function onCanvasClick( event ) { if (event.quick && this.viewer.viewport && (this.panVertical || this.panHorizontal)) { - var target, - posX, - posY; + var target = this.viewport.pointFromPixel(event.position); if (!this.panVertical) { // perform only horizonal pan - posX = this.viewport.pointFromPixel(event.position).x; - posY = this.viewport.getCenter().y; - target = new $.Point(posX, posY); + target.y = this.viewer.viewport.getCenter(true).y; } else if (!this.panHorizontal) { // perform only vertical pan - posX = this.viewport.getCenter().x; - posY = this.viewport.pointFromPixel(event.position).y; - target = new $.Point(posX, posY); - } else { - target = this.viewport.pointFromPixel(event.position); + target.x = this.viewer.viewport.getCenter(true).x; } this.viewer.viewport.panTo(target); this.viewer.viewport.applyConstraints(); From 57654cf1cf768a3171ff95e614647b66965dbf4d Mon Sep 17 00:00:00 2001 From: Francesco Cretti Date: Sun, 11 Mar 2018 13:24:29 +0100 Subject: [PATCH 3/4] raise event for navigator click --- src/navigator.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/navigator.js b/src/navigator.js index 84e3ad51..392d9e15 100644 --- a/src/navigator.js +++ b/src/navigator.js @@ -417,6 +417,27 @@ function onCanvasClick( event ) { this.viewer.viewport.panTo(target); this.viewer.viewport.applyConstraints(); } + /** + * Raised when a click event occurs on the {@link OpenSeadragon.Viewer#navigator} element. + * + * @event navigator-click + * @memberof OpenSeadragon.Viewer + * @type {object} + * @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised this event. + * @property {OpenSeadragon.MouseTracker} tracker - A reference to the MouseTracker which originated this event. + * @property {OpenSeadragon.Point} position - The position of the event relative to the tracked element. + * @property {Boolean} quick - True only if the clickDistThreshold and clickTimeThreshold are both passed. Useful for differentiating between clicks and drags. + * @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. + */ + this.viewer.raiseEvent('navigator-click', { + tracker: event.eventSource, + position: event.position, + quick: event.quick, + shift: event.shift, + originalEvent: event.originalEvent + }); } /** From 2eb6eaf52ff26ecae721fcd4f07e0efe93a62733 Mon Sep 17 00:00:00 2001 From: Francesco Cretti Date: Wed, 20 Jun 2018 18:07:43 +0200 Subject: [PATCH 4/4] 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(); + } + } /**