Skip to content

Commit dd4b9bf

Browse files
ccorcoveanuThibaut
authored andcommitted
Hide/Show sidebar when dragging it or typing into the search input
1 parent a83c491 commit dd4b9bf

4 files changed

Lines changed: 24 additions & 4 deletions

File tree

‎assets/javascripts/app/settings.coffee‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ class app.Settings
7979
catch
8080
return
8181

82+
hasLayout: (name) ->
83+
try
84+
layout = (Cookies.get(LAYOUT_KEY) || '').split(' ')
85+
$.arrayDelete(layout, '')
86+
return layout.indexOf(name) isnt -1
87+
catch
88+
return false
89+
8290
setSize: (value) ->
8391
try
8492
Cookies.set SIZE_KEY, value, path: '/', expires: 1e8

‎assets/javascripts/views/layout/document.coffee‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,18 @@ class app.views.Document extends app.View
3939
app.appCache?.updateInBackground()
4040
return
4141

42-
toggleSidebar: ->
43-
sidebarHidden = app.el.classList.contains(HIDE_SIDEBAR_CLASS)
44-
app.el.classList[if sidebarHidden then 'remove' else 'add'](HIDE_SIDEBAR_CLASS)
45-
app.settings.setLayout(HIDE_SIDEBAR_CLASS, !sidebarHidden)
42+
toggleSidebar: (saveLayout = true) ->
43+
hasHiddenClass = app.el.classList.contains(HIDE_SIDEBAR_CLASS)
44+
forceShow = (!hasHiddenClass || !@hasSidebar()) && !saveLayout
45+
app.el.classList[if hasHiddenClass or forceShow then 'remove' else 'add'](HIDE_SIDEBAR_CLASS)
46+
return unless saveLayout
47+
app.settings.setLayout(HIDE_SIDEBAR_CLASS, !hasHiddenClass)
4648
app.appCache?.updateInBackground()
4749
return
4850

51+
hasSidebar: ->
52+
return !app.el.classList.contains(HIDE_SIDEBAR_CLASS) && !app.settings.hasLayout(HIDE_SIDEBAR_CLASS)
53+
4954
setTitle: (title) ->
5055
@el.title = if title then "DevDocs - #{title}" else 'DevDocs API Documentation'
5156

‎assets/javascripts/views/layout/resizer.coffee‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ class app.views.Resizer extends app.View
5555
onDragEnd: (event) =>
5656
$.off(window, 'dragover', @onDrag)
5757
value = event.pageX or (event.screenX - window.screenX)
58+
if value <= 5
59+
app.document.toggleSidebar()
60+
return
61+
else if !app.document.hasSidebar()
62+
app.document.toggleSidebar(true)
5863
if @lastDragValue and not (@lastDragValue - 5 < value < @lastDragValue + 5) # https://github.com/Thibaut/devdocs/issues/265
5964
value = @lastDragValue
6065
@resize(value, true)

‎assets/javascripts/views/search/search.coffee‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ class app.views.Search extends app.View
6868
@value = @input.value
6969

7070
if @value.length
71+
app.document.toggleSidebar(false)
7172
@search()
7273
else
74+
app.document.toggleSidebar() unless app.document.hasSidebar()
7375
@clear()
7476
return
7577

0 commit comments

Comments
 (0)