Created
February 25, 2014 04:12
-
-
Save jbasdf/9202561 to your computer and use it in GitHub Desktop.
Ember bind arrow keys
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
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