History

Add double click event to toggle the sidebar

cristian.corcoveanu committed 10 years ago

Commit 4cb0d7a1 parent 664711e8 files · +45 −1Browse files

Unified · Split

8 files
  1. assets/javascripts/app/app.coffee +8 −0
  2. assets/javascripts/app/settings.coffee +8 −0
  3. assets/javascripts/views/layout/resizer.coffee +5 −0
  4. assets/stylesheets/components/_content.scss +4 −0
  5. assets/stylesheets/components/_path.scss +4 −0
  6. assets/stylesheets/components/_sidebar.scss +11 −0
  7. lib/app.rb +4 −0
  8. views/app.erb +1 −1
assets/javascripts/app/app.coffee+8−0
@@ -179,6 +179,14 @@ · 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+
182190 onBootError: (args...) ->
183191 @trigger 'bootError'
184192 @hideLoading()
assets/javascripts/app/settings.coffee+8−0
@@ -4,6 +4,7 @@ class app.Settings · 3 unmodified lines
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 · 67 unmodified lines
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+5−0
@@ -4,6 +4,7 @@ class app.views.Resizer extends app.View · 3 unmodified lines
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 · 21 unmodified lines
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+4−0
@@ -10,6 +10,10 @@ · 9 unmodified lines
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+4−0
@@ -11,6 +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+
1418 @media #{$mediumScreen} { left: $sidebarMediumWidth; }
1519
1620 ~ ._container { padding-bottom: 2rem; }
assets/stylesheets/components/_sidebar.scss+11−0
@@ -33,6 +33,10 @@ · 32 unmodified lines
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 @@ · 5 unmodified lines
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+4−0
@@ -185,6 +185,10 @@ 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+
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+1−1
@@ -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>