Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var DEFAULT_SUBMISSION_KEYS = [13, 188];
/**
* Register a mixin for key events
*/
ZenMixins.registerMixin('keyEvents', {
/**
* Decides whether the given event is a keyup for the 'Enter' key.
*
* @param event
* @returns {boolean} - True if the event is keyup on enter key
*/
keyEventIsEnter: function (event) {
var code = event.keyCode || event.which;
return code === 13;
},
/**
* Decides whether the given event is a keyup for the 'comma' key.
*
* @param event
* @returns {boolean} - True if the event is keyup on comma key
*
**/
keyEventIsComma: function (event) {
var code = event.keyCode || event.which;
return code === 188;
},
/**
* Decides whether the given event is a keyup for the key whitelisted for submission events.
*
* @param event
* @returns {boolean}
*
**/
keyEventsForTokenSubmission: function (event) {
var code = event.keyCode || event.which;
return _.contains(DEFAULT_SUBMISSION_KEYS, code);
}
});
// Now if we ever need to do some keyup events in some typeahead or an input bar we can use this in views!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment