mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-22 13:16:10 +03:00
Merge pull request #1288 from ooystein/dblClick
Manage preventDefaultAction flag inside canvas-double-click viewer event
This commit is contained in:
commit
ed42a7feee
@ -2611,16 +2611,14 @@ function onCanvasClick( event ) {
|
|||||||
function onCanvasDblClick( event ) {
|
function onCanvasDblClick( event ) {
|
||||||
var gestureSettings;
|
var gestureSettings;
|
||||||
|
|
||||||
if ( !event.preventDefaultAction && this.viewport ) {
|
var canvasDblClickEventArgs = {
|
||||||
gestureSettings = this.gestureSettingsByDeviceType( event.pointerType );
|
tracker: event.eventSource,
|
||||||
if ( gestureSettings.dblClickToZoom ) {
|
position: event.position,
|
||||||
this.viewport.zoomBy(
|
shift: event.shift,
|
||||||
event.shift ? 1.0 / this.zoomPerClick : this.zoomPerClick,
|
originalEvent: event.originalEvent,
|
||||||
this.viewport.pointFromPixel( event.position, true )
|
preventDefaultAction: event.preventDefaultAction
|
||||||
);
|
};
|
||||||
this.viewport.applyConstraints();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* Raised when a double mouse press/release or touch/remove occurs on the {@link OpenSeadragon.Viewer#canvas} element.
|
* Raised when a double mouse press/release or touch/remove occurs on the {@link OpenSeadragon.Viewer#canvas} element.
|
||||||
*
|
*
|
||||||
@ -2632,14 +2630,21 @@ function onCanvasDblClick( event ) {
|
|||||||
* @property {OpenSeadragon.Point} position - The position of the event relative to the tracked element.
|
* @property {OpenSeadragon.Point} position - The position of the event relative to the tracked element.
|
||||||
* @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 double tap to zoom behaviour. Default: false.
|
||||||
* @property {?Object} userData - Arbitrary subscriber-defined object.
|
* @property {?Object} userData - Arbitrary subscriber-defined object.
|
||||||
*/
|
*/
|
||||||
this.raiseEvent( 'canvas-double-click', {
|
this.raiseEvent( 'canvas-double-click', canvasDblClickEventArgs);
|
||||||
tracker: event.eventSource,
|
|
||||||
position: event.position,
|
if ( !canvasDblClickEventArgs.preventDefaultAction && this.viewport ) {
|
||||||
shift: event.shift,
|
gestureSettings = this.gestureSettingsByDeviceType( event.pointerType );
|
||||||
originalEvent: event.originalEvent
|
if ( gestureSettings.dblClickToZoom ) {
|
||||||
});
|
this.viewport.zoomBy(
|
||||||
|
event.shift ? 1.0 / this.zoomPerClick : this.zoomPerClick,
|
||||||
|
this.viewport.pointFromPixel( event.position, true )
|
||||||
|
);
|
||||||
|
this.viewport.applyConstraints();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onCanvasDrag( event ) {
|
function onCanvasDrag( event ) {
|
||||||
|
@ -833,6 +833,79 @@
|
|||||||
viewer.open('/test/data/testpattern.dzi');
|
viewer.open('/test/data/testpattern.dzi');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// ----------
|
||||||
|
asyncTest('Viewer: preventDefaultAction in dblClickHandler', function() {
|
||||||
|
var tracker = viewer.innerTracker;
|
||||||
|
var epsilon = 0.0000001;
|
||||||
|
|
||||||
|
function simulateDblTap() {
|
||||||
|
var touches = [];
|
||||||
|
TouchUtil.reset();
|
||||||
|
|
||||||
|
touches.push(TouchUtil.start([0,0]));
|
||||||
|
TouchUtil.end( touches[0] );
|
||||||
|
touches.push(TouchUtil.start([0,0]));
|
||||||
|
TouchUtil.end( touches[1] );
|
||||||
|
}
|
||||||
|
|
||||||
|
var onOpen = function() {
|
||||||
|
viewer.removeHandler('open', onOpen);
|
||||||
|
|
||||||
|
var originalZoom = viewer.viewport.getZoom();
|
||||||
|
|
||||||
|
var origDblClickHandler = tracker.dblClickHandler;
|
||||||
|
tracker.dblClickHandler = function(event) {
|
||||||
|
event.preventDefaultAction = true;
|
||||||
|
return origDblClickHandler(event);
|
||||||
|
};
|
||||||
|
|
||||||
|
TouchUtil.initTracker(tracker);
|
||||||
|
simulateDblTap();
|
||||||
|
|
||||||
|
var zoom = viewer.viewport.getZoom();
|
||||||
|
Util.assessNumericValue(originalZoom, zoom, epsilon,
|
||||||
|
"Zoom on double tap should be prevented");
|
||||||
|
|
||||||
|
// Reset event handler to original
|
||||||
|
tracker.dblClickHandler = origDblClickHandler;
|
||||||
|
|
||||||
|
simulateDblTap();
|
||||||
|
originalZoom = originalZoom * viewer.zoomPerClick;
|
||||||
|
|
||||||
|
var zoom = viewer.viewport.getZoom();
|
||||||
|
Util.assessNumericValue(originalZoom, zoom, epsilon,
|
||||||
|
"Zoom on double tap should not be prevented");
|
||||||
|
|
||||||
|
|
||||||
|
var dblClickHandler = function(event) {
|
||||||
|
event.preventDefaultAction = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
viewer.addHandler('canvas-double-click', dblClickHandler);
|
||||||
|
|
||||||
|
var zoom = viewer.viewport.getZoom();
|
||||||
|
Util.assessNumericValue(originalZoom, zoom, epsilon,
|
||||||
|
"Zoom on double tap should be prevented");
|
||||||
|
|
||||||
|
// Remove custom event handler
|
||||||
|
viewer.removeHandler('canvas-double-click', dblClickHandler);
|
||||||
|
|
||||||
|
simulateDblTap();
|
||||||
|
originalZoom = originalZoom * viewer.zoomPerClick;
|
||||||
|
|
||||||
|
var zoom = viewer.viewport.getZoom();
|
||||||
|
Util.assessNumericValue(originalZoom, zoom, epsilon,
|
||||||
|
"Zoom on double tap should not be prevented");
|
||||||
|
|
||||||
|
TouchUtil.resetTracker(tracker);
|
||||||
|
viewer.close();
|
||||||
|
start();
|
||||||
|
};
|
||||||
|
|
||||||
|
viewer.addHandler('open', onOpen);
|
||||||
|
viewer.open('/test/data/testpattern.dzi');
|
||||||
|
});
|
||||||
|
|
||||||
// ----------
|
// ----------
|
||||||
asyncTest( 'EventSource/MouseTracker/Viewer: event.originalEvent event.userData canvas-drag canvas-drag-end canvas-release canvas-click', function () {
|
asyncTest( 'EventSource/MouseTracker/Viewer: event.originalEvent event.userData canvas-drag canvas-drag-end canvas-release canvas-click', function () {
|
||||||
var $canvas = $( viewer.element ).find( '.openseadragon-canvas' ).not( '.navigator .openseadragon-canvas' ),
|
var $canvas = $( viewer.element ).find( '.openseadragon-canvas' ).not( '.navigator .openseadragon-canvas' ),
|
||||||
|
Loading…
Reference in New Issue
Block a user