Unified · Split
| @@ -82,10 +82,9 @@ class app.Settings · 81 unmodified lines | |||
| 82 | hasLayout: (name) -> | 82 | hasLayout: (name) -> |
| 83 | try | 83 | try |
| 84 | layout = (Cookies.get(LAYOUT_KEY) || '').split(' ') | 84 | layout = (Cookies.get(LAYOUT_KEY) || '').split(' ') |
| 85 | $.arrayDelete(layout, '') | 85 | layout.indexOf(name) isnt -1 |
| 86 | return layout.indexOf(name) isnt -1 | ||
| 87 | catch | 86 | catch |
| 88 | return false | 87 | false |
| 89 | 88 | ||
| 90 | setSize: (value) -> | 89 | setSize: (value) -> |
| 91 | try | 90 | try |
| @@ -20,6 +20,10 @@ class app.views.Document extends app.View · 19 unmodified lines | |||
| 20 | @addSubview @content = new app.views.Content | 20 | @addSubview @content = new app.views.Content |
| 21 | @addSubview @path = new app.views.Path unless app.isSingleDoc() or app.isMobile() | 21 | @addSubview @path = new app.views.Path unless app.isSingleDoc() or app.isMobile() |
| 22 | 22 | ||
| 23 | @sidebar.search | ||
| 24 | .on 'searching', @onSearching | ||
| 25 | .on 'clear', @onSearchClear | ||
| 26 | |||
| 23 | @activate() | 27 | @activate() |
| 24 | return | 28 | return |
| 25 | 29 | ||
| @@ -39,17 +43,32 @@ class app.views.Document extends app.View · 13 unmodified lines | |||
| 39 | app.appCache?.updateInBackground() | 43 | app.appCache?.updateInBackground() |
| 40 | return | 44 | return |
| 41 | 45 | ||
| 42 | toggleSidebar: (saveLayout = true) -> | 46 | showSidebar: (options = {}) -> |
| 43 | hasHiddenClass = app.el.classList.contains(HIDE_SIDEBAR_CLASS) | 47 | @toggleSidebar(options, true) |
| 44 | forceShow = (!hasHiddenClass || !@hasSidebar()) && !saveLayout | 48 | return |
| 45 | app.el.classList[if hasHiddenClass or forceShow then 'remove' else 'add'](HIDE_SIDEBAR_CLASS) | 49 | |
| 46 | return unless saveLayout | 50 | hideSidebar: (options = {}) -> |
| 47 | app.settings.setLayout(HIDE_SIDEBAR_CLASS, !hasHiddenClass) | 51 | @toggleSidebar(options, false) |
| 48 | app.appCache?.updateInBackground() | 52 | return |
| 53 | |||
| 54 | toggleSidebar: (options = {}, shouldShow) -> | ||
| 55 | shouldShow ?= if options.save then !@hasSidebar() else app.el.classList.contains(HIDE_SIDEBAR_CLASS) | ||
| 56 | app.el.classList[if shouldShow then 'remove' else 'add'](HIDE_SIDEBAR_CLASS) | ||
| 57 | app.settings.setLayout(HIDE_SIDEBAR_CLASS, !shouldShow) if options.save | ||
| 49 | return | 58 | return |
| 50 | 59 | ||
| 51 | hasSidebar: -> | 60 | hasSidebar: -> |
| 52 | return !app.el.classList.contains(HIDE_SIDEBAR_CLASS) && !app.settings.hasLayout(HIDE_SIDEBAR_CLASS) | 61 | !app.settings.hasLayout(HIDE_SIDEBAR_CLASS) |
| 62 | |||
| 63 | onSearching: => | ||
| 64 | unless @hasSidebar() | ||
| 65 | @showSidebar() | ||
| 66 | return | ||
| 67 | |||
| 68 | onSearchClear: => | ||
| 69 | unless @hasSidebar() | ||
| 70 | @hideSidebar() | ||
| 71 | return | ||
| 53 | 72 | ||
| 54 | setTitle: (title) -> | 73 | setTitle: (title) -> |
| 55 | @el.title = if title then "DevDocs - #{title}" else 'DevDocs API Documentation' | 74 | @el.title = if title then "DevDocs - #{title}" else 'DevDocs API Documentation' |
| @@ -14,7 +14,7 @@ class app.views.Resizer extends app.View · 13 unmodified lines | |||
| 14 | @appendTo $('._app') | 14 | @appendTo $('._app') |
| 15 | 15 | ||
| 16 | @style = $('style[data-resizer]') | 16 | @style = $('style[data-resizer]') |
| 17 | @size = @style.getAttribute('data-size') | 17 | @size = @savedSize = @style.getAttribute('data-size') |
| 18 | return | 18 | return |
| 19 | 19 | ||
| 20 | MIN = 260 | 20 | MIN = 260 |
| @@ -22,18 +22,27 @@ class app.views.Resizer extends app.View · 1 unmodified line | |||
| 22 | 22 | ||
| 23 | resize: (value, save) -> | 23 | resize: (value, save) -> |
| 24 | value -= app.el.offsetLeft | 24 | value -= app.el.offsetLeft |
| 25 | return unless value > 0 | 25 | return unless value >= 0 |
| 26 | value = Math.min(Math.max(Math.round(value), MIN), MAX) | 26 | |
| 27 | newSize = "#{value}px" | 27 | if value <= 5 |
| 28 | app.document.hideSidebar({save}) | ||
| 29 | newSize = @savedSize | ||
| 30 | else | ||
| 31 | app.document.showSidebar({save}) | ||
| 32 | value = Math.min(Math.max(Math.round(value), MIN), MAX) | ||
| 33 | newSize = "#{value}px" | ||
| 34 | |||
| 28 | @style.innerHTML = @style.innerHTML.replace(new RegExp(@size, 'g'), newSize) | 35 | @style.innerHTML = @style.innerHTML.replace(new RegExp(@size, 'g'), newSize) |
| 29 | @size = newSize | 36 | @size = newSize |
| 37 | |||
| 30 | if save | 38 | if save |
| 31 | app.settings.setSize(value) | 39 | @savedSize = @size |
| 40 | app.settings.setSize(parseInt(@savedSize)) | ||
| 32 | app.appCache?.updateInBackground() | 41 | app.appCache?.updateInBackground() |
| 33 | return | 42 | return |
| 34 | 43 | ||
| 35 | onDblClick: (event) -> | 44 | onDblClick: (event) -> |
| 36 | app.document.toggleSidebar() | 45 | app.document.toggleSidebar(save: true) |
| 37 | return | 46 | return |
| 38 | 47 | ||
| 39 | onDragStart: (event) => | 48 | onDragStart: (event) => |
| @@ -55,12 +64,7 @@ class app.views.Resizer extends app.View · 15 unmodified lines | |||
| 55 | onDragEnd: (event) => | 64 | onDragEnd: (event) => |
| 56 | $.off(window, 'dragover', @onDrag) | 65 | $.off(window, 'dragover', @onDrag) |
| 57 | value = event.pageX or (event.screenX - window.screenX) | 66 | value = event.pageX or (event.screenX - window.screenX) |
| 58 | if value <= 5 | 67 | if @lastDragValue and value > 0 and not (@lastDragValue - 5 < value < @lastDragValue + 5) # https://github.com/Thibaut/devdocs/issues/265 |
| 59 | app.document.toggleSidebar() | ||
| 60 | return | ||
| 61 | else if !app.document.hasSidebar() | ||
| 62 | app.document.toggleSidebar(true) | ||
| 63 | if @lastDragValue and not (@lastDragValue - 5 < value < @lastDragValue + 5) # https://github.com/Thibaut/devdocs/issues/265 | ||
| 64 | value = @lastDragValue | 68 | value = @lastDragValue |
| 65 | @resize(value, true) | 69 | @resize(value, true) |
| 66 | return | 70 | return |
| @@ -68,10 +68,8 @@ class app.views.Search extends app.View · 67 unmodified lines | |||
| 68 | @value = @input.value | 68 | @value = @input.value |
| 69 | 69 | ||
| 70 | if @value.length | 70 | if @value.length |
| 71 | app.document.toggleSidebar(false) | ||
| 72 | @search() | 71 | @search() |
| 73 | else | 72 | else |
| 74 | app.document.toggleSidebar() unless app.document.hasSidebar() | ||
| 75 | @clear() | 73 | @clear() |
| 76 | return | 74 | return |
| 77 | 75 | ||