Skip to content

Instantly share code, notes, and snippets.

@jbasdf
Created February 25, 2014 04:12
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 jbasdf/9202561 to your computer and use it in GitHub Desktop.
Save jbasdf/9202561 to your computer and use it in GitHub Desktop.
Ember bind arrow keys
App.Textfield = Ember.TextField.extend({
init: function() {
this._super();
this.on("keyUp", this, this.interpretKeyEvents);
},
interpretKeyEvents: function(event){
var map = TM.Textfield .KEY_EVENTS;
var method = map[event.keyCode];
if (method){
return this[method](event);
} else {
this._super(event);
}
},
arrowUp: function(event){
this.sendAction('arrow-up', this, event);
},
arrowDown: function(event){
this.sendAction('arrow-down', this, event);
}
});
App.Textfield.KEY_EVENTS = {
38: 'arrowUp',
40: 'arrowDown'
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment