Skip to content

Instantly share code, notes, and snippets.

@abhiaiyer91
Created December 12, 2015 22:01
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 abhiaiyer91/dfc53be84042ae2d6e1f to your computer and use it in GitHub Desktop.
Save abhiaiyer91/dfc53be84042ae2d6e1f to your computer and use it in GitHub Desktop.
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