2014-10-20 16:48:07 -04:00
|
|
|
class @TreeView
|
2013-06-26 09:58:56 -04:00
|
|
|
constructor: ->
|
|
|
|
@initKeyNav()
|
2012-10-03 17:01:16 -04:00
|
|
|
|
2013-06-26 09:58:56 -04:00
|
|
|
# Code browser tree slider
|
|
|
|
# Make the entire tree-item row clickable, but not if clicking another link (like a commit message)
|
|
|
|
$(".tree-content-holder .tree-item").on 'click', (e) ->
|
|
|
|
if (e.target.nodeName != "A")
|
|
|
|
path = $('.tree-item-file-name a', this).attr('href')
|
|
|
|
Turbolinks.visit(path)
|
2012-11-09 18:03:46 -05:00
|
|
|
|
2013-06-26 09:58:56 -04:00
|
|
|
# Show the "Loading commit data" for only the first element
|
|
|
|
$('span.log_loading:first').removeClass('hide')
|
2012-11-09 18:03:46 -05:00
|
|
|
|
2013-06-26 09:58:56 -04:00
|
|
|
initKeyNav: ->
|
|
|
|
li = $("tr.tree-item")
|
|
|
|
liSelected = null
|
|
|
|
$('body').keydown (e) ->
|
|
|
|
if e.which is 40
|
|
|
|
if liSelected
|
|
|
|
next = liSelected.next()
|
|
|
|
if next.length > 0
|
|
|
|
liSelected.removeClass "selected"
|
|
|
|
liSelected = next.addClass("selected")
|
|
|
|
else
|
|
|
|
liSelected = li.eq(0).addClass("selected")
|
2012-11-09 18:03:46 -05:00
|
|
|
|
2013-06-26 09:58:56 -04:00
|
|
|
$(liSelected).focus()
|
|
|
|
else if e.which is 38
|
|
|
|
if liSelected
|
|
|
|
next = liSelected.prev()
|
|
|
|
if next.length > 0
|
|
|
|
liSelected.removeClass "selected"
|
|
|
|
liSelected = next.addClass("selected")
|
|
|
|
else
|
|
|
|
liSelected = li.last().addClass("selected")
|
|
|
|
|
|
|
|
$(liSelected).focus()
|
|
|
|
else if e.which is 13
|
|
|
|
path = $('.tree-item.selected .tree-item-file-name a').attr('href')
|
|
|
|
Turbolinks.visit(path)
|