Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keyboard handlers patch #1414

Merged

Conversation

francescocretti
Copy link
Contributor

@francescocretti francescocretti commented Mar 6, 2018

Fixes #1405.

Keyboard handlers patch:

  • event firing added
  • possibility of preventing default keyboard behaviour
  • possibility of preventing vertical and/or horizontal pan with keyboard

Example of usage:

viewer.addHandler('canvas-key', function (e) {
   e.preventDefault = true; // disable default keyboard controls
   e.preventVerticalPan = true; // disable vertical panning with arrows and W or S keys
   e.preventHorizontalPan = true; // disable horizontal panning with arrows and A or D keys
});

Built and tested with grunt:

>> 223 tests completed with 0 failed, 0 skipped, and 0 todo. 
>> 2051 assertions (in 45948ms), passed: 2051, failed: 0

Copy link
Member

@iangilman iangilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Just one comment.

Also, please add doc comments in for the event... You can look at other raiseEvent calls in the file to see examples. Here's what they end up looking like once they are processed:

http://openseadragon.github.io/docs/OpenSeadragon.Viewer.html#.event:canvas-click

src/viewer.js Outdated
preventHorizontalPan: event.preventHorizontalPan
};

this.raiseEvent( 'canvas-key-down', canvasKeyDownEventArgs);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that we're using just one event name instead of differentiating between key down and key press (which seems like it would be unnecessary in our context). I'm a little concerned that calling it canvas-key-down implies that it's specifically a key down event. Maybe we should call it just canvas-key?

Copy link
Contributor Author

@francescocretti francescocretti Mar 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I used the same name so it's more "transparent" for the user, that does not need to know about the difference in the backend.

Sure, I agree about changing the event name. ;)

@iangilman
Copy link
Member

Now that I think of it, I think we only need one copy of the doc comment, even though it's raised in two places. I'll delete one after I merge this.

Thank you for making this patch; it came together nicely!

@iangilman iangilman merged commit 6c7fcb1 into openseadragon:master Mar 7, 2018
iangilman added a commit that referenced this pull request Mar 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants