Skip to content

Instantly share code, notes, and snippets.

@typeoneerror
Created December 10, 2014 04:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save typeoneerror/cced1471919ac7769e40 to your computer and use it in GitHub Desktop.
Save typeoneerror/cced1471919ac7769e40 to your computer and use it in GitHub Desktop.
ember mixin for jquery hotkeys + lodash/underscore
import Ember from 'ember';
export default Ember.Mixin.create({
init: function() {
this._super();
this.setupHotkeys();
},
setupHotkeys: function() {
var hotkeys = this.get('hotkeys');
if (!Ember.isEmpty(hotkeys)) {
_.bindAll.apply(this, [this].concat(_.pluck(hotkeys, 'handler')));
}
},
enableKeyboard: function() {
var hotkeys = this.get('hotkeys');
if (!Ember.isEmpty(hotkeys)) {
hotkeys.forEach(function(binding) {
Ember.$(document).bind('keyup.doki.curriculum', binding.command, this[binding.handler]);
}, this);
}
},
disableKeyboard: function() {
Ember.$(document).unbind('keyup.doki.curriculum');
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment