Skip to content

Instantly share code, notes, and snippets.

@garth
Created December 30, 2013 16:01
Show Gist options
  • Save garth/8183889 to your computer and use it in GitHub Desktop.
Save garth/8183889 to your computer and use it in GitHub Desktop.
Add support for keyboard shortcuts in emberjs views. Include keymaster.js and emberViewExtension.js and then see the example usage.
// enable keyboard shortcuts in views
Ember.View.reopen({
bindKey: function (shortcut, action) {
var controller = this.controller;
window.key(shortcut, function () {
controller.send(action);
});
},
unbindKey: function (shortcut) {
window.key.unbind(shortcut);
}
});
App.MyController = Ember.ObjectController.extend({
actions: {
save: function () {
// ...
}
}
});
App.MyView = Ember.View.extend({
setup: function () {
this.bindKey('s', 'save');
}.on('didInsertElement'),
teardown: function () {
this.unbindKey('s');
}.on('willDestroyElement')
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment