Last active
August 29, 2015 14:01
-
-
Save marcysutton/2b56bb2832395eb0978b to your computer and use it in GitHub Desktop.
Keyboards FTW
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
a, button | |
&:hover, &:focus | |
color: orange | |
.profile-list-item | |
&.selected | |
background-color: $dark-gray |
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
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