History

Tweak dbclick-to-toggle-sidebar code

Thibaut Courouble committed 10 years ago

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

Showing the changes to assets/javascripts (4 of 12 files). Show all

Unified · Split

4 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
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) =>