#About Backbone Hotkeys is an extension to the standard Backbone View which lets you easily add and remove handlers for keyboard events supporting almost any key combination. Uses the jquery.hotkey.js library written by: [John Resig] (http://github.com/jeresig/jquery.hotkeys).
Supported types are 'keydown'
and 'keyup'
.
Include jquery.hotkeys.js and backbone-hotkeys.js after backbone.js in your app.
App.SomeView = Backbone.View.extend({
el: 'some-container',
events: {
'keyup[esc] body': 'someMethod',
'keyup[Alt+m] body': 'someMethod',
'keyup[Ctrl+left] body': 'someMethod'
}
});
If a selector is defined on a hotkey event then it is used as a filter for the target function.
There are 4 arguments in the events binding, which are:
keyup
: when key action should trigger the event[esc]
: the key (or key-combination, separated with +) to trigger the eventbody
: the DOM element this should bind to (ie. event must bubble up to this).someMethod
: The method to execute when a matching key combination is found (same as normal Backbone events).
Works with jQuery 1.8.3 and Backbone 1.1.2.
- 1.2 Added automatic event unbinding for events bound to
document
- see #4. - 1.10 Bound to
document
as default and added jQuery selector parameter as filter for target function. - 1.0 Initial release