Created
December 10, 2014 04:38
-
-
Save typeoneerror/cced1471919ac7769e40 to your computer and use it in GitHub Desktop.
ember mixin for jquery hotkeys + lodash/underscore
This file contains 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
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