preventDefaultAction support

This commit is contained in:
Francesco Cretti 2018-06-20 18:07:43 +02:00
parent 57654cf1cf
commit 2eb6eaf52f

View File

@ -405,18 +405,14 @@ $.extend( $.Navigator.prototype, $.EventSource.prototype, $.Viewer.prototype, /*
* @function * @function
*/ */
function onCanvasClick( event ) { function onCanvasClick( event ) {
if (event.quick && this.viewer.viewport && (this.panVertical || this.panHorizontal)) { var canvasClickEventArgs = {
var target = this.viewport.pointFromPixel(event.position); tracker: event.eventSource,
if (!this.panVertical) { position: event.position,
// perform only horizonal pan quick: event.quick,
target.y = this.viewer.viewport.getCenter(true).y; shift: event.shift,
} else if (!this.panHorizontal) { originalEvent: event.originalEvent,
// perform only vertical pan preventDefaultAction: event.preventDefaultAction
target.x = this.viewer.viewport.getCenter(true).x; };
}
this.viewer.viewport.panTo(target);
this.viewer.viewport.applyConstraints();
}
/** /**
* Raised when a click event occurs on the {@link OpenSeadragon.Viewer#navigator} element. * 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 {Boolean} shift - True if the shift key was pressed during this event.
* @property {Object} originalEvent - The original DOM event. * @property {Object} originalEvent - The original DOM event.
* @property {?Object} userData - Arbitrary subscriber-defined object. * @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, this.viewer.raiseEvent('navigator-click', canvasClickEventArgs);
position: event.position,
quick: event.quick, if ( !canvasClickEventArgs.preventDefaultAction && event.quick && this.viewer.viewport && (this.panVertical || this.panHorizontal)) {
shift: event.shift, var target = this.viewport.pointFromPixel(event.position);
originalEvent: event.originalEvent 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();
}
} }
/** /**