mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-25 06:36:11 +03:00
Merge pull request #2291 from MohitBansal321/keyboardHandling
Consolidate viewer keyboard handling into keydown handler
This commit is contained in:
commit
c7992411a5
103
src/viewer.js
103
src/viewer.js
@ -2757,7 +2757,7 @@ function onCanvasKeyDown( event ) {
|
|||||||
|
|
||||||
if ( !canvasKeyDownEventArgs.preventDefaultAction && !event.ctrl && !event.alt && !event.meta ) {
|
if ( !canvasKeyDownEventArgs.preventDefaultAction && !event.ctrl && !event.alt && !event.meta ) {
|
||||||
switch( event.keyCode ){
|
switch( event.keyCode ){
|
||||||
case 38://up arrow
|
case 38://up arrow/shift uparrow
|
||||||
if (!canvasKeyDownEventArgs.preventVerticalPan) {
|
if (!canvasKeyDownEventArgs.preventVerticalPan) {
|
||||||
if ( event.shift ) {
|
if ( event.shift ) {
|
||||||
this.viewport.zoomBy(1.1);
|
this.viewport.zoomBy(1.1);
|
||||||
@ -2768,7 +2768,7 @@ function onCanvasKeyDown( event ) {
|
|||||||
}
|
}
|
||||||
event.preventDefault = true;
|
event.preventDefault = true;
|
||||||
break;
|
break;
|
||||||
case 40://down arrow
|
case 40://down arrow/shift downarrow
|
||||||
if (!canvasKeyDownEventArgs.preventVerticalPan) {
|
if (!canvasKeyDownEventArgs.preventVerticalPan) {
|
||||||
if ( event.shift ) {
|
if ( event.shift ) {
|
||||||
this.viewport.zoomBy(0.9);
|
this.viewport.zoomBy(0.9);
|
||||||
@ -2793,47 +2793,12 @@ function onCanvasKeyDown( event ) {
|
|||||||
}
|
}
|
||||||
event.preventDefault = true;
|
event.preventDefault = true;
|
||||||
break;
|
break;
|
||||||
default:
|
case 187://=|+
|
||||||
//console.log( 'navigator keycode %s', event.keyCode );
|
|
||||||
event.preventDefault = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
event.preventDefault = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function onCanvasKeyPress( event ) {
|
|
||||||
var canvasKeyPressEventArgs = {
|
|
||||||
originalEvent: event.originalEvent,
|
|
||||||
preventDefaultAction: false,
|
|
||||||
preventVerticalPan: event.preventVerticalPan || !this.panVertical,
|
|
||||||
preventHorizontalPan: event.preventHorizontalPan || !this.panHorizontal
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Raised when a keyboard key is pressed and the focus is on the {@link OpenSeadragon.Viewer#canvas} element.
|
|
||||||
*
|
|
||||||
* @event canvas-key-press
|
|
||||||
* @memberof OpenSeadragon.Viewer
|
|
||||||
* @type {object}
|
|
||||||
* @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised this event.
|
|
||||||
* @property {Object} originalEvent - The original DOM event.
|
|
||||||
* @property {Boolean} preventDefaultAction - Set to true to prevent default keyboard behaviour. Default: false.
|
|
||||||
* @property {Boolean} preventVerticalPan - Set to true to prevent keyboard vertical panning. Default: false.
|
|
||||||
* @property {Boolean} preventHorizontalPan - Set to true to prevent keyboard horizontal panning. Default: false.
|
|
||||||
* @property {?Object} userData - Arbitrary subscriber-defined object.
|
|
||||||
*/
|
|
||||||
this.raiseEvent('canvas-key-press', canvasKeyPressEventArgs);
|
|
||||||
|
|
||||||
if ( !canvasKeyPressEventArgs.preventDefaultAction && !event.ctrl && !event.alt && !event.meta ) {
|
|
||||||
switch( event.keyCode ){
|
|
||||||
case 43://=|+
|
|
||||||
case 61://=|+
|
|
||||||
this.viewport.zoomBy(1.1);
|
this.viewport.zoomBy(1.1);
|
||||||
this.viewport.applyConstraints();
|
this.viewport.applyConstraints();
|
||||||
event.preventDefault = true;
|
event.preventDefault = true;
|
||||||
break;
|
break;
|
||||||
case 45://-|_
|
case 189://-|_
|
||||||
this.viewport.zoomBy(0.9);
|
this.viewport.zoomBy(0.9);
|
||||||
this.viewport.applyConstraints();
|
this.viewport.applyConstraints();
|
||||||
event.preventDefault = true;
|
event.preventDefault = true;
|
||||||
@ -2843,9 +2808,8 @@ function onCanvasKeyPress( event ) {
|
|||||||
this.viewport.applyConstraints();
|
this.viewport.applyConstraints();
|
||||||
event.preventDefault = true;
|
event.preventDefault = true;
|
||||||
break;
|
break;
|
||||||
case 119://w
|
case 87://W/w
|
||||||
case 87://W
|
if (!canvasKeyDownEventArgs.preventVerticalPan) {
|
||||||
if (!canvasKeyPressEventArgs.preventVerticalPan) {
|
|
||||||
if ( event.shift ) {
|
if ( event.shift ) {
|
||||||
this.viewport.zoomBy(1.1);
|
this.viewport.zoomBy(1.1);
|
||||||
} else {
|
} else {
|
||||||
@ -2855,9 +2819,8 @@ function onCanvasKeyPress( event ) {
|
|||||||
}
|
}
|
||||||
event.preventDefault = true;
|
event.preventDefault = true;
|
||||||
break;
|
break;
|
||||||
case 115://s
|
case 83://S/s
|
||||||
case 83://S
|
if (!canvasKeyDownEventArgs.preventVerticalPan) {
|
||||||
if (!canvasKeyPressEventArgs.preventVerticalPan) {
|
|
||||||
if ( event.shift ) {
|
if ( event.shift ) {
|
||||||
this.viewport.zoomBy(0.9);
|
this.viewport.zoomBy(0.9);
|
||||||
} else {
|
} else {
|
||||||
@ -2867,46 +2830,45 @@ function onCanvasKeyPress( event ) {
|
|||||||
}
|
}
|
||||||
event.preventDefault = true;
|
event.preventDefault = true;
|
||||||
break;
|
break;
|
||||||
case 97://a
|
case 65://a/A
|
||||||
if (!canvasKeyPressEventArgs.preventHorizontalPan) {
|
if (!canvasKeyDownEventArgs.preventHorizontalPan) {
|
||||||
this.viewport.panBy(this.viewport.deltaPointsFromPixels(new $.Point(-40, 0)));
|
this.viewport.panBy(this.viewport.deltaPointsFromPixels(new $.Point(-40, 0)));
|
||||||
this.viewport.applyConstraints();
|
this.viewport.applyConstraints();
|
||||||
}
|
}
|
||||||
event.preventDefault = true;
|
event.preventDefault = true;
|
||||||
break;
|
break;
|
||||||
case 100://d
|
case 68://d/D
|
||||||
if (!canvasKeyPressEventArgs.preventHorizontalPan) {
|
if (!canvasKeyDownEventArgs.preventHorizontalPan) {
|
||||||
this.viewport.panBy(this.viewport.deltaPointsFromPixels(new $.Point(40, 0)));
|
this.viewport.panBy(this.viewport.deltaPointsFromPixels(new $.Point(40, 0)));
|
||||||
this.viewport.applyConstraints();
|
this.viewport.applyConstraints();
|
||||||
}
|
}
|
||||||
event.preventDefault = true;
|
event.preventDefault = true;
|
||||||
break;
|
break;
|
||||||
case 114: //r - clockwise rotation
|
case 82: //r - clockwise rotation/R - counterclockwise rotation
|
||||||
if(this.viewport.flipped){
|
if(event.shift){
|
||||||
this.viewport.setRotation(this.viewport.getRotation() - this.rotationIncrement);
|
|
||||||
} else{
|
|
||||||
this.viewport.setRotation(this.viewport.getRotation() + this.rotationIncrement);
|
|
||||||
}
|
|
||||||
this.viewport.applyConstraints();
|
|
||||||
event.preventDefault = true;
|
|
||||||
break;
|
|
||||||
case 82: //R - counterclockwise rotation
|
|
||||||
if(this.viewport.flipped){
|
if(this.viewport.flipped){
|
||||||
this.viewport.setRotation(this.viewport.getRotation() + this.rotationIncrement);
|
this.viewport.setRotation(this.viewport.getRotation() + this.rotationIncrement);
|
||||||
} else{
|
} else{
|
||||||
this.viewport.setRotation(this.viewport.getRotation() - this.rotationIncrement);
|
this.viewport.setRotation(this.viewport.getRotation() - this.rotationIncrement);
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
if(this.viewport.flipped){
|
||||||
|
this.viewport.setRotation(this.viewport.getRotation() - this.rotationIncrement);
|
||||||
|
} else{
|
||||||
|
this.viewport.setRotation(this.viewport.getRotation() + this.rotationIncrement);
|
||||||
|
}
|
||||||
|
}
|
||||||
this.viewport.applyConstraints();
|
this.viewport.applyConstraints();
|
||||||
event.preventDefault = true;
|
event.preventDefault = true;
|
||||||
break;
|
break;
|
||||||
case 102: //f
|
case 70: //f/F
|
||||||
this.viewport.toggleFlip();
|
this.viewport.toggleFlip();
|
||||||
event.preventDefault = true;
|
event.preventDefault = true;
|
||||||
break;
|
break;
|
||||||
case 106: //j - previous image source
|
case 74: //j - previous image source
|
||||||
this.goToPreviousPage();
|
this.goToPreviousPage();
|
||||||
break;
|
break;
|
||||||
case 107: //k - next image source
|
case 75: //k - next image source
|
||||||
this.goToNextPage();
|
this.goToNextPage();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -2919,7 +2881,24 @@ function onCanvasKeyPress( event ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onCanvasKeyPress( event ) {
|
||||||
|
var canvasKeyPressEventArgs = {
|
||||||
|
originalEvent: event.originalEvent,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Raised when a keyboard key is pressed and the focus is on the {@link OpenSeadragon.Viewer#canvas} element.
|
||||||
|
*
|
||||||
|
* @event canvas-key-press
|
||||||
|
* @memberof OpenSeadragon.Viewer
|
||||||
|
* @type {object}
|
||||||
|
* @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised this event.
|
||||||
|
* @property {Object} originalEvent - The original DOM event.
|
||||||
|
* @property {?Object} userData - Arbitrary subscriber-defined object.
|
||||||
|
*/
|
||||||
|
|
||||||
|
this.raiseEvent('canvas-key-press', canvasKeyPressEventArgs);
|
||||||
|
}
|
||||||
|
|
||||||
function onCanvasClick( event ) {
|
function onCanvasClick( event ) {
|
||||||
var gestureSettings;
|
var gestureSettings;
|
||||||
|
Loading…
Reference in New Issue
Block a user