manage preventDefaultAction flag inside the canvas-drag viewer event. Trigger the canvas-drag event before default drag happens on the viewer

This commit is contained in:
kinto 2017-03-15 09:51:44 +01:00
parent 199e960d22
commit 741745433d

View File

@ -2532,20 +2532,16 @@ function onCanvasDblClick( event ) {
function onCanvasDrag( event ) { function onCanvasDrag( event ) {
var gestureSettings; var gestureSettings;
var canvasDragEventArgs = {
if ( !event.preventDefaultAction && this.viewport ) { tracker: event.eventSource,
gestureSettings = this.gestureSettingsByDeviceType( event.pointerType ); position: event.position,
if( !this.panHorizontal ){ delta: event.delta,
event.delta.x = 0; speed: event.speed,
} direction: event.direction,
if( !this.panVertical ){ shift: event.shift,
event.delta.y = 0; originalEvent: event.originalEvent,
} preventDefaultAction: event.preventDefaultAction
this.viewport.panBy( this.viewport.deltaPointsFromPixels( event.delta.negate() ), gestureSettings.flickEnabled ); };
if( this.constrainDuringPan ){
this.viewport.applyConstraints();
}
}
/** /**
* Raised when a mouse or touch drag operation occurs on the {@link OpenSeadragon.Viewer#canvas} element. * Raised when a mouse or touch drag operation occurs on the {@link OpenSeadragon.Viewer#canvas} element.
* *
@ -2560,17 +2556,23 @@ function onCanvasDrag( event ) {
* @property {Number} direction - Current computed direction, expressed as an angle counterclockwise relative to the positive X axis (-pi to pi, in radians). Only valid if speed > 0. * @property {Number} direction - Current computed direction, expressed as an angle counterclockwise relative to the positive X axis (-pi to pi, in radians). Only valid if speed > 0.
* @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 {Boolean} preventDefaultAction - Set to true to prevent default drag behaviour. Default: false.
* @property {?Object} userData - Arbitrary subscriber-defined object. * @property {?Object} userData - Arbitrary subscriber-defined object.
*/ */
this.raiseEvent( 'canvas-drag', { this.raiseEvent( 'canvas-drag', canvasDragEventArgs);
tracker: event.eventSource, if ( !canvasDragEventArgs.preventDefaultAction && this.viewport ) {
position: event.position, gestureSettings = this.gestureSettingsByDeviceType( event.pointerType );
delta: event.delta, if( !this.panHorizontal ){
speed: event.speed, event.delta.x = 0;
direction: event.direction, }
shift: event.shift, if( !this.panVertical ){
originalEvent: event.originalEvent event.delta.y = 0;
}); }
this.viewport.panBy( this.viewport.deltaPointsFromPixels( event.delta.negate() ), gestureSettings.flickEnabled );
if( this.constrainDuringPan ){
this.viewport.applyConstraints();
}
}
} }
function onCanvasDragEnd( event ) { function onCanvasDragEnd( event ) {