diff --git a/assets/javascripts/app/settings.coffee b/assets/javascripts/app/settings.coffee index 32c4a757..c4377223 100644 --- a/assets/javascripts/app/settings.coffee +++ b/assets/javascripts/app/settings.coffee @@ -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 diff --git a/assets/javascripts/views/layout/document.coffee b/assets/javascripts/views/layout/document.coffee index 6d7e5d9a..70937344 100644 --- a/assets/javascripts/views/layout/document.coffee +++ b/assets/javascripts/views/layout/document.coffee @@ -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' diff --git a/assets/javascripts/views/layout/resizer.coffee b/assets/javascripts/views/layout/resizer.coffee index 7cb3e4ed..1384002e 100644 --- a/assets/javascripts/views/layout/resizer.coffee +++ b/assets/javascripts/views/layout/resizer.coffee @@ -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) diff --git a/assets/javascripts/views/search/search.coffee b/assets/javascripts/views/search/search.coffee index addd030e..8a70c1f8 100644 --- a/assets/javascripts/views/search/search.coffee +++ b/assets/javascripts/views/search/search.coffee @@ -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