Expand/collapse directories when their disclosure arrow is clicked

This commit is contained in:
Nathan Sobo
2012-04-23 15:29:16 -06:00
parent b23785f28f
commit 607dfb4987
3 changed files with 43 additions and 15 deletions

View File

@@ -16,15 +16,11 @@ class TreeView extends View
class DirectoryView extends View
@content: ({directory, isExpanded}) ->
@li class: 'directory', =>
@disclosureArrow(isExpanded)
@span '', class: 'disclosure-arrow', outlet: 'disclosureArrow', click: 'toggleExpansion'
@span directory.getName() + '/', class: 'name'
@disclosureArrow: (isExpanded) ->
arrowCharacter = if isExpanded then '' else ''
@span arrowCharacter, class: 'disclosure'
initialize: ({@directory, @isExpanded}) ->
@buildEntries() if @isExpanded
@expand() if @isExpanded
buildEntries: ->
contents = $$ -> @ol class: 'entries'
@@ -34,3 +30,20 @@ class DirectoryView extends View
else
contents.append $$ -> @li entry.getName(), class: 'file'
@append(contents)
toggleExpansion: ->
if @isExpanded then @collapse() else @expand()
expand: ->
@disclosureArrow.text('')
@buildEntries()
@isExpanded = true
collapse: ->
@disclosureArrow.text('')
@find('.entries').remove()
@isExpanded = false