Skip to content

Instantly share code, notes, and snippets.

@marcysutton
Last active August 29, 2015 14: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 marcysutton/2b56bb2832395eb0978b to your computer and use it in GitHub Desktop.
Save marcysutton/2b56bb2832395eb0978b to your computer and use it in GitHub Desktop.
Keyboards FTW
a, button
&:hover, &:focus
color: orange
.profile-list-item
&.selected
background-color: $dark-gray
class SortableListObserver
constructor: ->
$('body')
.on('focus', '[data-behavior=sort-handle]', @_handleListItemFocus)
.on('blur', '[data-behavior=sort-handle]', @_handleListItemBlur)
.on('keydown', '[data-behavior=sort-handle]', @_handleListItemKeypress)
.on('keydown', @_handleEscapeKey)
_handleListItemFocus: (event) =>
$(event.target).closest('li').addClass('selected')
_handleListItemBlur: (event) =>
$(event.target).closest('li').removeClass('selected')
_handleListItemKeypress: (event) ->
listItem = $(event.target).closest('li')
switch event.which
when App.Keys.ARROW_UP then @_handleArrows(event, listItem, listItem.index() - 1)
when App.Keys.ARROW_DOWN then @_handleArrows(event, listItem, listItem.index() + 1)
_handleEscapeKey: (event) ->
if event.which is App.Keys.ESCAPE
App.PageController.trigger('disableSorting', event)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment