Skip to content

Commit 31495ff

Browse files
committed
Tweak dbclick-to-toggle-sidebar code
1 parent 4cb0d7a commit 31495ff

12 files changed

Lines changed: 50 additions & 41 deletions

File tree

assets/javascripts/app/app.coffee

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,6 @@
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-
190182
onBootError: (args...) ->
191183
@trigger 'bootError'
192184
@hideLoading()

assets/javascripts/app/settings.coffee

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

98
@defaults:
109
count: 0
@@ -63,10 +62,18 @@ class app.Settings
6362
catch
6463
return
6564

66-
setLayout: (value) ->
65+
setLayout: (name, enable) ->
6766
try
68-
if value
69-
Cookies.set LAYOUT_KEY, value, path: '/', expires: 1e8
67+
layout = (Cookies.get(LAYOUT_KEY) || '').split(' ')
68+
$.arrayDelete(layout, '')
69+
70+
if enable
71+
layout.push(name) if layout.indexOf(name) is -1
72+
else
73+
$.arrayDelete(layout, name)
74+
75+
if layout.length > 0
76+
Cookies.set LAYOUT_KEY, layout.join(' '), path: '/', expires: 1e8
7077
else
7178
Cookies.expire LAYOUT_KEY
7279
catch
@@ -78,17 +85,10 @@ class app.Settings
7885
catch
7986
return
8087

81-
setSidebar: (value) ->
82-
try
83-
Cookies.set SIDEBAR_KEY, value, path: '/', expires: 1e8
84-
catch
85-
return
86-
8788
reset: ->
8889
try Cookies.expire DOCS_KEY
8990
try Cookies.expire DARK_KEY
9091
try Cookies.expire LAYOUT_KEY
9192
try Cookies.expire SIZE_KEY
92-
try Cookies.expire SIDEBAR_KEY
9393
try @store.del(SETTINGS_KEY)
9494
return

assets/javascripts/views/layout/document.coffee

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
class app.views.Document extends app.View
22
MAX_WIDTH_CLASS = '_max-width'
3+
HIDE_SIDEBAR_CLASS = '_sidebar-hidden'
34

45
@el: document
56

@@ -34,7 +35,14 @@ class app.views.Document extends app.View
3435
toggleLayout: ->
3536
wantsMaxWidth = !app.el.classList.contains(MAX_WIDTH_CLASS)
3637
app.el.classList[if wantsMaxWidth then 'add' else 'remove'](MAX_WIDTH_CLASS)
37-
app.settings.setLayout(if wantsMaxWidth then MAX_WIDTH_CLASS else false)
38+
app.settings.setLayout(MAX_WIDTH_CLASS, wantsMaxWidth)
39+
app.appCache?.updateInBackground()
40+
return
41+
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)
3846
app.appCache?.updateInBackground()
3947
return
4048

assets/javascripts/views/layout/resizer.coffee

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

99
@isSupported: ->
1010
'ondragstart' of document.createElement('div') and !app.isMobile()
@@ -32,8 +32,8 @@ class app.views.Resizer extends app.View
3232
app.appCache?.updateInBackground()
3333
return
3434

35-
onDbLClick: (event) =>
36-
app.toggleSidebar()
35+
onDblClick: (event) ->
36+
app.document.toggleSidebar()
3737
return
3838

3939
onDragStart: (event) =>

assets/stylesheets/components/_content.scss

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

13-
._app[data-sidebar="hidden"] & {
14-
margin-left: 0;
15-
}
16-
1713
@media #{$mediumScreen} { margin-left: $sidebarMediumWidth; }
14+
15+
._sidebar-hidden & { margin-left: $sidebarHiddenWidth; }
1816
}
1917

2018
._content {

assets/stylesheets/components/_notice.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
@media #{$mediumScreen} { left: $sidebarMediumWidth; }
1313

14+
._sidebar-hidden & { left: $sidebarHiddenWidth; }
15+
1416
&:not(._top) ~ ._container { padding-bottom: 2.5rem; }
1517

1618
&._top {

assets/stylesheets/components/_path.scss

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

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

16+
._sidebar-hidden & { left: $sidebarHiddenWidth; }
17+
2018
~ ._container { padding-bottom: 2rem; }
2119
a:focus { outline: 0; }
2220
}

assets/stylesheets/components/_sidebar.scss

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
a:focus { outline: 0; }
3636

37-
._app[data-sidebar="hidden"] & {
37+
._sidebar-hidden & {
3838
display: none;
3939
}
4040
}
@@ -49,11 +49,24 @@
4949
width: 3px;
5050
cursor: col-resize;
5151

52-
._app[data-sidebar="hidden"] & {
53-
border: 1px solid $headerBorder;
54-
background-color: $headerBackground;
52+
._sidebar-hidden & {
53+
left: 0;
5554
margin-left: 0;
56-
left: 1px;
55+
background: $headerBackground;
56+
border-right: 1px solid $headerBorder;
57+
width: 8px;
58+
59+
&:before {
60+
content: '';
61+
position: absolute;
62+
top: 50%;
63+
left: 3px;
64+
margin-top: -.5rem;
65+
width: 1px;
66+
height: 1rem;
67+
border-left: 1px solid $textColorLighter;
68+
border-right: 1px solid $textColorLighter;
69+
}
5770
}
5871
}
5972

assets/stylesheets/global/_variables.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ $maxWidth: 80rem;
77
$headerHeight: 3rem;
88
$sidebarWidth: 18rem;
99
$sidebarMediumWidth: 16rem;
10+
$sidebarHiddenWidth: 9px;
1011

1112
$contentBackground: #fff;
1213
$documentBackground: #fafafa;

assets/stylesheets/global/variables-dark.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ $maxWidth: 80rem;
77
$headerHeight: 3rem;
88
$sidebarWidth: 18rem;
99
$sidebarMediumWidth: 16rem;
10+
$sidebarHiddenWidth: 9px;
1011

1112
$contentBackground: #303030;
1213
$documentBackground: #404040;

0 commit comments

Comments
 (0)