Hide/Show sidebar when dragging it or typing into the search input

pull/412/merge
cristian.corcoveanu 9 years ago committed by Thibaut Courouble
parent a83c49189a
commit dd4b9bfa1f

@ -79,6 +79,14 @@ class app.Settings
catch
return
hasLayout: (name) ->
try
layout = (Cookies.get(LAYOUT_KEY) || '').split(' ')
$.arrayDelete(layout, '')
return layout.indexOf(name) isnt -1
catch
return false
setSize: (value) ->
try
Cookies.set SIZE_KEY, value, path: '/', expires: 1e8

@ -39,13 +39,18 @@ class app.views.Document extends app.View
app.appCache?.updateInBackground()
return
toggleSidebar: ->
sidebarHidden = app.el.classList.contains(HIDE_SIDEBAR_CLASS)
app.el.classList[if sidebarHidden then 'remove' else 'add'](HIDE_SIDEBAR_CLASS)
app.settings.setLayout(HIDE_SIDEBAR_CLASS, !sidebarHidden)
toggleSidebar: (saveLayout = true) ->
hasHiddenClass = app.el.classList.contains(HIDE_SIDEBAR_CLASS)
forceShow = (!hasHiddenClass || !@hasSidebar()) && !saveLayout
app.el.classList[if hasHiddenClass or forceShow then 'remove' else 'add'](HIDE_SIDEBAR_CLASS)
return unless saveLayout
app.settings.setLayout(HIDE_SIDEBAR_CLASS, !hasHiddenClass)
app.appCache?.updateInBackground()
return
hasSidebar: ->
return !app.el.classList.contains(HIDE_SIDEBAR_CLASS) && !app.settings.hasLayout(HIDE_SIDEBAR_CLASS)
setTitle: (title) ->
@el.title = if title then "DevDocs - #{title}" else 'DevDocs API Documentation'

@ -55,6 +55,11 @@ class app.views.Resizer extends app.View
onDragEnd: (event) =>
$.off(window, 'dragover', @onDrag)
value = event.pageX or (event.screenX - window.screenX)
if value <= 5
app.document.toggleSidebar()
return
else if !app.document.hasSidebar()
app.document.toggleSidebar(true)
if @lastDragValue and not (@lastDragValue - 5 < value < @lastDragValue + 5) # https://github.com/Thibaut/devdocs/issues/265
value = @lastDragValue
@resize(value, true)

@ -68,8 +68,10 @@ class app.views.Search extends app.View
@value = @input.value
if @value.length
app.document.toggleSidebar(false)
@search()
else
app.document.toggleSidebar() unless app.document.hasSidebar()
@clear()
return

Loading…
Cancel
Save