Add core:move-to-top and core:move-to-bottom support to tree view

This commit is contained in:
Kevin Sawicki
2012-10-05 15:25:52 -07:00
parent c09f7ebc60
commit 4b20a26974
3 changed files with 36 additions and 1 deletions

View File

@@ -314,7 +314,7 @@ describe "TreeView", ->
afterEach ->
expect(treeView.find('.selected').length).toBeLessThan 2
describe "move-down", ->
describe "core:move-down", ->
describe "when a collapsed directory is selected", ->
it "skips to the next directory", ->
treeView.root.find('.directory:eq(0)').click()
@@ -408,6 +408,33 @@ describe "TreeView", ->
treeView.trigger 'core:move-up'
expect(treeView.root).toHaveClass 'selected'
describe "core:move-to-top", ->
it "scrolls to the top", ->
treeView.height(100)
treeView.attachToDom()
$(element).view().expand() for element in treeView.find('.directory')
expect(treeView.prop('scrollHeight')).toBeGreaterThan treeView.outerHeight()
expect(treeView.scrollTop()).toBe 0
entryCount = treeView.find(".entry").length
_.times entryCount, -> treeView.moveDown()
expect(treeView.scrollTop()).toBeGreaterThan 0
treeView.trigger 'core:move-to-top'
expect(treeView.scrollTop()).toBe 0
describe "core:move-to-bottom", ->
it "scrolls to the bottom", ->
treeView.height(100)
treeView.attachToDom()
$(element).view().expand() for element in treeView.find('.directory')
expect(treeView.prop('scrollHeight')).toBeGreaterThan treeView.outerHeight()
expect(treeView.scrollTop()).toBe 0
treeView.trigger 'core:move-to-bottom'
expect(treeView.scrollBottom()).toBe treeView.prop('scrollHeight')
describe "movement outside of viewable region", ->
it "scrolls the tree view to the selected item", ->
treeView.height(100)

View File

@@ -48,6 +48,8 @@ class TreeView extends View
@on 'click', '.entry', (e) => @entryClicked(e)
@on 'core:move-up', => @moveUp()
@on 'core:move-down', => @moveDown()
@on 'core:move-to-top', => @scrollToTop()
@on 'core:move-to-bottom', => @scrollToBottom()
@on 'tree-view:expand-directory', => @expandDirectory()
@on 'tree-view:collapse-directory', => @collapseDirectory()
@on 'tree-view:open-selected-entry', => @openSelectedEntry(true)

View File

@@ -6,6 +6,12 @@ $.fn.scrollBottom = (newValue) ->
else
@scrollTop() + @height()
$.fn.scrollToTop = ->
@scrollTop(0)
$.fn.scrollToBottom = ->
@scrollTop(@prop('scrollHeight'))
$.fn.scrollRight = (newValue) ->
if newValue?
@scrollLeft(newValue - @width())