Merge branch 'fix-firefox-preferences' into service-worker

pull/1022/head
Jasper van Merle 6 years ago
commit 5edbb16c1b

@ -26,6 +26,8 @@
@document = new app.views.Document @document = new app.views.Document
@mobile = new app.views.Mobile if @isMobile() @mobile = new app.views.Mobile if @isMobile()
@settings.initLayout()
if document.body.hasAttribute('data-doc') if document.body.hasAttribute('data-doc')
@DOC = JSON.parse(document.body.getAttribute('data-doc')) @DOC = JSON.parse(document.body.getAttribute('data-doc'))
@bootOne() @bootOne()

@ -19,6 +19,9 @@ class app.Settings
'news' 'news'
] ]
LAYOUTS: ['_max-width', '_sidebar-hidden', '_native-scrollbars']
SIDEBAR_HIDDEN_LAYOUT = '_sidebar-hidden'
@defaults: @defaults:
count: 0 count: 0
hideDisabled: false hideDisabled: false
@ -38,6 +41,7 @@ class app.Settings
set: (key, value) -> set: (key, value) ->
@store.set(key, value) @store.set(key, value)
delete @cache[key] delete @cache[key]
@toggleDark(value) if key == 'dark'
return return
del: (key) -> del: (key) ->
@ -63,6 +67,8 @@ class app.Settings
return return
setLayout: (name, enable) -> setLayout: (name, enable) ->
@toggleLayout(name, enable)
layout = (@store.get('layout') || '').split(' ') layout = (@store.get('layout') || '').split(' ')
$.arrayDelete(layout, '') $.arrayDelete(layout, '')
@ -104,3 +110,17 @@ class app.Settings
@store.reset() @store.reset()
@cache = {} @cache = {}
return return
initLayout: ->
@toggleDark(@get('dark'))
@toggleLayout(layout, @hasLayout(layout)) for layout in @LAYOUTS
toggleDark: (enable) ->
classList = document.documentElement.classList
classList[if enable then 'remove' else 'add']('_theme-default')
classList[if enable then 'add' else 'remove']('_theme-dark')
toggleLayout: (layout, enable) ->
classList = document.body.classList
classList[if enable then 'add' else 'remove'](layout) unless layout is SIDEBAR_HIDDEN_LAYOUT
classList[if $.overlayScrollbarsEnabled() then 'add' else 'remove']('_overlay-scrollbars')

@ -1,7 +1,4 @@
class app.views.SettingsPage extends app.View class app.views.SettingsPage extends app.View
LAYOUTS = ['_max-width', '_sidebar-hidden', '_native-scrollbars']
SIDEBAR_HIDDEN_LAYOUT = '_sidebar-hidden'
@className: '_static' @className: '_static'
@events: @events:
@ -17,23 +14,18 @@ class app.views.SettingsPage extends app.View
settings.dark = app.settings.get('dark') settings.dark = app.settings.get('dark')
settings.smoothScroll = !app.settings.get('fastScroll') settings.smoothScroll = !app.settings.get('fastScroll')
settings.arrowScroll = app.settings.get('arrowScroll') settings.arrowScroll = app.settings.get('arrowScroll')
settings[layout] = app.settings.hasLayout(layout) for layout in LAYOUTS settings[layout] = app.settings.hasLayout(layout) for layout in app.settings.LAYOUTS
settings settings
getTitle: -> getTitle: ->
'Preferences' 'Preferences'
toggleDark: (enable) -> toggleDark: (enable) ->
html = document.documentElement
html.classList.toggle('_theme-default')
html.classList.toggle('_theme-dark')
app.settings.set('dark', !!enable) app.settings.set('dark', !!enable)
app.appCache?.updateInBackground() app.appCache?.updateInBackground()
return return
toggleLayout: (layout, enable) -> toggleLayout: (layout, enable) ->
document.body.classList[if enable then 'add' else 'remove'](layout) unless layout is SIDEBAR_HIDDEN_LAYOUT
document.body.classList[if $.overlayScrollbarsEnabled() then 'add' else 'remove']('_overlay-scrollbars')
app.settings.setLayout(layout, enable) app.settings.setLayout(layout, enable)
app.appCache?.updateInBackground() app.appCache?.updateInBackground()
return return

Loading…
Cancel
Save