History

Tweak dbclick-to-toggle-sidebar code

Thibaut Courouble committed 10 years ago

Commit 31495ff1 parent 4cb0d7a12 files · +50 −41Browse files

Unified · Split

12 files
  1. assets/javascripts/app/app.coffee +0 −8
  2. assets/javascripts/app/settings.coffee +11 −11
  3. assets/javascripts/views/layout/document.coffee +9 −1
  4. assets/javascripts/views/layout/resizer.coffee +3 −3
  5. assets/stylesheets/components/_content.scss +2 −4
  6. assets/stylesheets/components/_notice.scss +2 −0
  7. assets/stylesheets/components/_path.scss +2 −4
  8. assets/stylesheets/components/_sidebar.scss +18 −5
  9. assets/stylesheets/global/_variables.scss +1 −0
  10. assets/stylesheets/global/variables-dark.scss +1 −0
  11. lib/app.rb +0 −4
  12. views/app.erb +1 −1
assets/javascripts/app/app.coffee+0−8
@@ -179,14 +179,6 @@ · 178 unmodified lines
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+11−11
@@ -4,7 +4,6 @@ class app.Settings · 3 unmodified lines
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 · 52 unmodified lines
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 · 5 unmodified lines
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+9−1
@@ -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 · 28 unmodified lines
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+3−3
@@ -4,7 +4,7 @@ class app.views.Resizer extends app.View · 3 unmodified lines
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 · 21 unmodified lines
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+2−4
@@ -10,11 +10,9 @@ · 9 unmodified lines
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+2−0
@@ -11,6 +11,8 @@ · 10 unmodified lines
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+2−4
@@ -11,12 +11,10 @@ · 10 unmodified lines
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+18−5
@@ -34,7 +34,7 @@ · 33 unmodified lines
3434
3535 a:focus { outline: 0; }
3636
37− ._app[data-sidebar="hidden"] & {
37+ ._sidebar-hidden & {
3838 display: none;
3939 }
4040 }
@@ -49,11 +49,24 @@ · 8 unmodified lines
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+1−0
@@ -7,6 +7,7 @@ $maxWidth: 80rem; · 6 unmodified lines
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+1−0
@@ -7,6 +7,7 @@ $maxWidth: 80rem; · 6 unmodified lines
77 $headerHeight: 3rem;
88 $sidebarWidth: 18rem;
99 $sidebarMediumWidth: 16rem;
10+$sidebarHiddenWidth: 9px;
1011
1112 $contentBackground: #303030;
1213 $documentBackground: #404040;
lib/app.rb+0−4
@@ -185,10 +185,6 @@ class App < Sinatra::Application · 184 unmodified lines
185185 app_theme == 'dark'
186186 end
187187
188− def app_sidebar
189− cookies[:sidebar].nil? ? 'visible' : cookies[:sidebar]
190− end
191−
192188 def redirect_via_js(path) # courtesy of HTML5 App Cache
193189 response.set_cookie :initial_path, value: path, expires: Time.now + 15, path: '/'
194190 redirect '/', 302
views/app.erb+1−1
@@ -1,4 +1,4 @@
1−<div class="_app<%= " #{app_layout}" if app_layout %>" data-sidebar="<%= "#{app_sidebar}" if app_sidebar %>">
1+<div class="_app<%= " #{app_layout}" if app_layout %>">
22 <header class="_header">
33 <a class="_home-link"></a>
44 <a class="_menu-link"></a>