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