Created
April 9, 2014 00:05
-
-
Save samccone/10211371 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
App.module "Behaviors", (Behaviors, App, Backbone, Marionette) -> | |
class Behaviors.KeyEvents extends Marionette.Behavior | |
onShow: -> | |
$(window).on 'keydown', @checkKey | |
onClose: -> | |
$(window).off 'keydown', @checkKey | |
shouldIgnore: -> | |
a = document.activeElement.tagName | |
return if a is "INPUT" or a is "TEXTAREA" | |
checkKey: (e) => | |
return if @shouldIgnore() | |
if toInvoke = @options[e.keyCode] | |
fn = toInvoke.call(@view) | |
if ~@options.preventDefault.indexOf(e.keyCode) | |
e.preventDefault() | |
return false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment