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