Created
December 30, 2013 16:01
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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