Skip to content

Instantly share code, notes, and snippets.

@karlbright
Created March 16, 2012 00:10
Show Gist options
  • Save karlbright/2047784 to your computer and use it in GitHub Desktop.
Save karlbright/2047784 to your computer and use it in GitHub Desktop.
Which one looks nicer?
keyDown: (event) ->
switch event.keyCode
# Backspace
when 8
if @el.val() is ''
token = @tokens.pop()
token.remove()
# Enter
when 13 then Houston.nextStep() if @el.autocomplete 'option', 'disabled'
# @
when 50 @enableAutocomplete if event.shiftKey is true
else setTimeout @check, 100 unless event.keyCode in @ignoredKeys
keyDown: (event) ->
# Backspace
if @el.val() is '' and event.keyCode is 8
if @tokens.length > 0
token = @tokens.pop()
token.remove()
else if @el.autocomplete('option','disabled')
# Onto the next step if enter has been pressed
Houston.nextStep() if event.keyCode is 13
# Enable autocomplete if the user enters a '@' symbol
@enableAutocomplete() if event.keyCode is 50 and event.shiftKey is true
else
# Set timeout before checking this string. If we check too quickly the value will not be grabbed correctly.
setTimeout @check, 100 unless event.keyCode in @ignoredKeys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment