Skip to content

Commit 4cb0d7a

Browse files
ccorcoveanuThibaut
authored andcommitted
Add double click event to toggle the sidebar
1 parent 664711e commit 4cb0d7a

8 files changed

Lines changed: 45 additions & 1 deletion

File tree

assets/javascripts/app/app.coffee

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,14 @@
179179
# enabled because it doesn't support caching URLs that use CORS.
180180
@config[if @appCache and @settings.hasDocs() then 'index_path' else 'docs_host']
181181

182+
toggleSidebar: ->
183+
state = @el.getAttribute('data-sidebar')
184+
newState = if state == 'visible' then 'hidden' else 'visible'
185+
@el.setAttribute('data-sidebar', newState)
186+
@settings.setSidebar(newState)
187+
@appCache?.updateInBackground()
188+
return
189+
182190
onBootError: (args...) ->
183191
@trigger 'bootError'
184192
@hideLoading()

assets/javascripts/app/settings.coffee

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ class app.Settings
44
DARK_KEY = 'dark'
55
LAYOUT_KEY = 'layout'
66
SIZE_KEY = 'size'
7+
SIDEBAR_KEY = 'sidebar'
78

89
@defaults:
910
count: 0
@@ -77,10 +78,17 @@ class app.Settings
7778
catch
7879
return
7980

81+
setSidebar: (value) ->
82+
try
83+
Cookies.set SIDEBAR_KEY, value, path: '/', expires: 1e8
84+
catch
85+
return
86+
8087
reset: ->
8188
try Cookies.expire DOCS_KEY
8289
try Cookies.expire DARK_KEY
8390
try Cookies.expire LAYOUT_KEY
8491
try Cookies.expire SIZE_KEY
92+
try Cookies.expire SIDEBAR_KEY
8593
try @store.del(SETTINGS_KEY)
8694
return

assets/javascripts/views/layout/resizer.coffee

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ class app.views.Resizer extends app.View
44
@events:
55
dragstart: 'onDragStart'
66
dragend: 'onDragEnd'
7+
dblclick: 'onDbLClick'
78

89
@isSupported: ->
910
'ondragstart' of document.createElement('div') and !app.isMobile()
@@ -31,6 +32,10 @@ class app.views.Resizer extends app.View
3132
app.appCache?.updateInBackground()
3233
return
3334

35+
onDbLClick: (event) =>
36+
app.toggleSidebar()
37+
return
38+
3439
onDragStart: (event) =>
3540
@style.removeAttribute('disabled')
3641
event.dataTransfer.effectAllowed = 'link'

assets/stylesheets/components/_content.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
pointer-events: none;
1111
@extend %border-box;
1212

13+
._app[data-sidebar="hidden"] & {
14+
margin-left: 0;
15+
}
16+
1317
@media #{$mediumScreen} { margin-left: $sidebarMediumWidth; }
1418
}
1519

assets/stylesheets/components/_path.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
background: $pathBackground;
1212
box-shadow: inset 0 1px $pathBorder;
1313

14+
._app[data-sidebar="hidden"] & {
15+
left: 0;
16+
}
17+
1418
@media #{$mediumScreen} { left: $sidebarMediumWidth; }
1519

1620
~ ._container { padding-bottom: 2rem; }

assets/stylesheets/components/_sidebar.scss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
}
3434

3535
a:focus { outline: 0; }
36+
37+
._app[data-sidebar="hidden"] & {
38+
display: none;
39+
}
3640
}
3741

3842
._resizer {
@@ -44,6 +48,13 @@
4448
margin-left: -2px;
4549
width: 3px;
4650
cursor: col-resize;
51+
52+
._app[data-sidebar="hidden"] & {
53+
border: 1px solid $headerBorder;
54+
background-color: $headerBackground;
55+
margin-left: 0;
56+
left: 1px;
57+
}
4758
}
4859

4960
//

lib/app.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ def dark_theme?
185185
app_theme == 'dark'
186186
end
187187

188+
def app_sidebar
189+
cookies[:sidebar].nil? ? 'visible' : cookies[:sidebar]
190+
end
191+
188192
def redirect_via_js(path) # courtesy of HTML5 App Cache
189193
response.set_cookie :initial_path, value: path, expires: Time.now + 15, path: '/'
190194
redirect '/', 302

views/app.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="_app<%= " #{app_layout}" if app_layout %>">
1+
<div class="_app<%= " #{app_layout}" if app_layout %>" data-sidebar="<%= "#{app_sidebar}" if app_sidebar %>">
22
<header class="_header">
33
<a class="_home-link"></a>
44
<a class="_menu-link"></a>

0 commit comments

Comments
 (0)