backbone.marionette.keyshortcuts
An extension to Backbone.Marionette.View
that adds a keyShortcuts
hash to the view object, allowing you to register keyboard commands using Mousetrap.js
.
Dependencies
- Marionette https://github.com/marionettejs/backbone.marionette
- Moustrap https://github.com/ccampbell/mousetrap
Installation
npm install backbone.marionette.keyshortcuts
If you are using requireJS
then you need to ensure that mousetrap
can be found on the default path, or is defined in your require config.
paths:'backbone.marionette.keyShortcuts': '/vendor/marionette/backbone.marionette.keyshortcuts''mousetrap':'/vendor/mousetrap/mousetrap.min'
Usage
In your View
class, simply add a keyShortcuts
like you would for the events
hash.
It supports single keys and key combinations. To define the event trigger, add a colon followed by the event name after your key combination; 'd:keyup'
.
ViewMyForm = MarionetteItemView;
Or you can define them in a Behavior
class
ShortcutsBehaviour = MarionetteBehavior
ViewMyForm = MarionetteItemView;
Info
See https://craig.is/killing/mice for how to use Mousetrap.