You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
devdocs/assets/javascripts/views/sidebar/sidebar.coffee

90 lines
1.9 KiB

11 years ago
class app.views.Sidebar extends app.View
@el: '._sidebar'
@events:
focus: 'onFocus'
click: 'onClick'
11 years ago
@shortcuts:
escape: 'onEscape'
init: ->
@addSubview @hover = new app.views.SidebarHover @el unless $.isTouchScreen()
11 years ago
@addSubview @search = new app.views.Search
@search
.on('searching', @showResults)
.on('clear', @showDocList)
@results = new app.views.Results @search
@docList = new app.views.DocList
@docPicker = new app.views.DocPicker unless app.isSingleDoc()
11 years ago
app.on 'ready', @showDocList
$.on document, 'click', @onGlobalClick if @docPicker
return
show: (view) ->
unless @view is view
@hover?.hide()
11 years ago
@saveScrollPosition()
@view?.deactivate()
@html @view = view
@append @tmpl('sidebarSettings') if @view is @docList and @docPicker
@view.activate()
@restoreScrollPosition()
return
showDocList: (reset) =>
11 years ago
@show @docList
@docList.reset() if reset is true
11 years ago
return
showDocPicker: =>
@show @docPicker
return
showResults: =>
@show @results
return
saveScrollPosition: ->
if @view is @docList
@scrollTop = @el.scrollTop
return
restoreScrollPosition: ->
if @view is @docList and @scrollTop
@el.scrollTop = @scrollTop
@scrollTop = null
else
@scrollToTop()
return
scrollToTop: ->
@el.scrollTop = 0
return
onFocus: (event) =>
$.scrollTo event.target, @el, 'continuous', bottomGap: 2
return
onClick: (event) =>
if event.target.hasAttribute? 'data-reset-list'
$.stopEvent(event)
@showDocList true
11 years ago
return
onGlobalClick: (event) =>
if event.target.hasAttribute? 'data-pick-docs'
$.stopEvent(event)
@showDocPicker()
else if @view is @docPicker
@showDocList() unless $.hasChild @el, event.target
return
onEscape: =>
@showDocList true
@scrollToTop()
return