Unified · Split
| @@ -179,14 +179,6 @@ · 178 unmodified lines | ||
| 179 | 179 | # enabled because it doesn't support caching URLs that use CORS. |
| 180 | 180 | @config[if @appCache and @settings.hasDocs() then 'index_path' else 'docs_host'] |
| 181 | 181 | |
| 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 | − | |
| 190 | 182 | onBootError: (args...) -> |
| 191 | 183 | @trigger 'bootError' |
| 192 | 184 | @hideLoading() |
| @@ -4,7 +4,6 @@ class app.Settings · 3 unmodified lines | ||
| 4 | 4 | DARK_KEY = 'dark' |
| 5 | 5 | LAYOUT_KEY = 'layout' |
| 6 | 6 | SIZE_KEY = 'size' |
| 7 | − SIDEBAR_KEY = 'sidebar' | |
| 8 | 7 | |
| 9 | 8 | @defaults: |
| 10 | 9 | count: 0 |
| @@ -63,10 +62,18 @@ class app.Settings · 52 unmodified lines | ||
| 63 | 62 | catch |
| 64 | 63 | return |
| 65 | 64 | |
| 66 | − setLayout: (value) -> | |
| 65 | + setLayout: (name, enable) -> | |
| 67 | 66 | 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 | |
| 70 | 77 | else |
| 71 | 78 | Cookies.expire LAYOUT_KEY |
| 72 | 79 | catch |
| @@ -78,17 +85,10 @@ class app.Settings · 5 unmodified lines | ||
| 78 | 85 | catch |
| 79 | 86 | return |
| 80 | 87 | |
| 81 | − setSidebar: (value) -> | |
| 82 | − try | |
| 83 | − Cookies.set SIDEBAR_KEY, value, path: '/', expires: 1e8 | |
| 84 | − catch | |
| 85 | − return | |
| 86 | − | |
| 87 | 88 | reset: -> |
| 88 | 89 | try Cookies.expire DOCS_KEY |
| 89 | 90 | try Cookies.expire DARK_KEY |
| 90 | 91 | try Cookies.expire LAYOUT_KEY |
| 91 | 92 | try Cookies.expire SIZE_KEY |
| 92 | − try Cookies.expire SIDEBAR_KEY | |
| 93 | 93 | try @store.del(SETTINGS_KEY) |
| 94 | 94 | return |
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | class app.views.Document extends app.View |
| 2 | 2 | MAX_WIDTH_CLASS = '_max-width' |
| 3 | + HIDE_SIDEBAR_CLASS = '_sidebar-hidden' | |
| 3 | 4 | |
| 4 | 5 | @el: document |
| 5 | 6 | |
| @@ -34,7 +35,14 @@ class app.views.Document extends app.View · 28 unmodified lines | ||
| 34 | 35 | toggleLayout: -> |
| 35 | 36 | wantsMaxWidth = !app.el.classList.contains(MAX_WIDTH_CLASS) |
| 36 | 37 | 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) | |
| 38 | 46 | app.appCache?.updateInBackground() |
| 39 | 47 | return |
| 40 | 48 | |
| @@ -4,7 +4,7 @@ class app.views.Resizer extends app.View · 3 unmodified lines | ||
| 4 | 4 | @events: |
| 5 | 5 | dragstart: 'onDragStart' |
| 6 | 6 | dragend: 'onDragEnd' |
| 7 | − dblclick: 'onDbLClick' | |
| 7 | + dblclick: 'onDblClick' | |
| 8 | 8 | |
| 9 | 9 | @isSupported: -> |
| 10 | 10 | 'ondragstart' of document.createElement('div') and !app.isMobile() |
| @@ -32,8 +32,8 @@ class app.views.Resizer extends app.View · 21 unmodified lines | ||
| 32 | 32 | app.appCache?.updateInBackground() |
| 33 | 33 | return |
| 34 | 34 | |
| 35 | − onDbLClick: (event) => | |
| 36 | − app.toggleSidebar() | |
| 35 | + onDblClick: (event) -> | |
| 36 | + app.document.toggleSidebar() | |
| 37 | 37 | return |
| 38 | 38 | |
| 39 | 39 | onDragStart: (event) => |
| @@ -10,11 +10,9 @@ · 9 unmodified lines | ||
| 10 | 10 | pointer-events: none; |
| 11 | 11 | @extend %border-box; |
| 12 | 12 | |
| 13 | − ._app[data-sidebar="hidden"] & { | |
| 14 | − margin-left: 0; | |
| 15 | − } | |
| 16 | − | |
| 17 | 13 | @media #{$mediumScreen} { margin-left: $sidebarMediumWidth; } |
| 14 | + | |
| 15 | + ._sidebar-hidden & { margin-left: $sidebarHiddenWidth; } | |
| 18 | 16 | } |
| 19 | 17 | |
| 20 | 18 | ._content { |
| @@ -11,6 +11,8 @@ · 10 unmodified lines | ||
| 11 | 11 | |
| 12 | 12 | @media #{$mediumScreen} { left: $sidebarMediumWidth; } |
| 13 | 13 | |
| 14 | + ._sidebar-hidden & { left: $sidebarHiddenWidth; } | |
| 15 | + | |
| 14 | 16 | &:not(._top) ~ ._container { padding-bottom: 2.5rem; } |
| 15 | 17 | |
| 16 | 18 | &._top { |
| @@ -11,12 +11,10 @@ · 10 unmodified lines | ||
| 11 | 11 | background: $pathBackground; |
| 12 | 12 | box-shadow: inset 0 1px $pathBorder; |
| 13 | 13 | |
| 14 | − ._app[data-sidebar="hidden"] & { | |
| 15 | − left: 0; | |
| 16 | − } | |
| 17 | − | |
| 18 | 14 | @media #{$mediumScreen} { left: $sidebarMediumWidth; } |
| 19 | 15 | |
| 16 | + ._sidebar-hidden & { left: $sidebarHiddenWidth; } | |
| 17 | + | |
| 20 | 18 | ~ ._container { padding-bottom: 2rem; } |
| 21 | 19 | a:focus { outline: 0; } |
| 22 | 20 | } |
| @@ -34,7 +34,7 @@ · 33 unmodified lines | ||
| 34 | 34 | |
| 35 | 35 | a:focus { outline: 0; } |
| 36 | 36 | |
| 37 | − ._app[data-sidebar="hidden"] & { | |
| 37 | + ._sidebar-hidden & { | |
| 38 | 38 | display: none; |
| 39 | 39 | } |
| 40 | 40 | } |
| @@ -49,11 +49,24 @@ · 8 unmodified lines | ||
| 49 | 49 | width: 3px; |
| 50 | 50 | cursor: col-resize; |
| 51 | 51 | |
| 52 | − ._app[data-sidebar="hidden"] & { | |
| 53 | − border: 1px solid $headerBorder; | |
| 54 | − background-color: $headerBackground; | |
| 52 | + ._sidebar-hidden & { | |
| 53 | + left: 0; | |
| 55 | 54 | 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 | + } | |
| 57 | 70 | } |
| 58 | 71 | } |
| 59 | 72 | |
| @@ -7,6 +7,7 @@ $maxWidth: 80rem; · 6 unmodified lines | ||
| 7 | 7 | $headerHeight: 3rem; |
| 8 | 8 | $sidebarWidth: 18rem; |
| 9 | 9 | $sidebarMediumWidth: 16rem; |
| 10 | +$sidebarHiddenWidth: 9px; | |
| 10 | 11 | |
| 11 | 12 | $contentBackground: #fff; |
| 12 | 13 | $documentBackground: #fafafa; |
| @@ -7,6 +7,7 @@ $maxWidth: 80rem; · 6 unmodified lines | ||
| 7 | 7 | $headerHeight: 3rem; |
| 8 | 8 | $sidebarWidth: 18rem; |
| 9 | 9 | $sidebarMediumWidth: 16rem; |
| 10 | +$sidebarHiddenWidth: 9px; | |
| 10 | 11 | |
| 11 | 12 | $contentBackground: #303030; |
| 12 | 13 | $documentBackground: #404040; |
| @@ -185,10 +185,6 @@ class App < Sinatra::Application · 184 unmodified lines | ||
| 185 | 185 | app_theme == 'dark' |
| 186 | 186 | end |
| 187 | 187 | |
| 188 | − def app_sidebar | |
| 189 | − cookies[:sidebar].nil? ? 'visible' : cookies[:sidebar] | |
| 190 | − end | |
| 191 | − | |
| 192 | 188 | def redirect_via_js(path) # courtesy of HTML5 App Cache |
| 193 | 189 | response.set_cookie :initial_path, value: path, expires: Time.now + 15, path: '/' |
| 194 | 190 | redirect '/', 302 |
| @@ -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 %>"> | |
| 2 | 2 | <header class="_header"> |
| 3 | 3 | <a class="_home-link"></a> |
| 4 | 4 | <a class="_menu-link"></a> |