Created
May 1, 2012 14:33
-
-
Save paulspringett/2568346 to your computer and use it in GitHub Desktop.
Bind a function to escape keypress
This file contains hidden or 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
# $.esc | |
# Binds the given callback function to the keyup | |
# event for the "Escape" key | |
# Example usage: | |
# $.esc(function(event) { | |
# alert("Escape key pressed!"); | |
# }); | |
# Compatible with jQuery or Zepto | |
$.esc = (callback) -> | |
$(document).on 'keyup', (event) -> | |
callback?(event) if event.keyCode is 27 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example use: