mirror of https://github.com/freeCodeCamp/devdocs
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
117 lines
3.2 KiB
117 lines
3.2 KiB
8 years ago
|
class app.views.SettingsPage extends app.View
|
||
|
@className: '_static'
|
||
|
|
||
|
@events:
|
||
8 years ago
|
click: 'onClick'
|
||
8 years ago
|
change: 'onChange'
|
||
|
|
||
|
render: ->
|
||
|
@html @tmpl('settingsPage', @currentSettings())
|
||
|
return
|
||
|
|
||
|
currentSettings: ->
|
||
|
settings = {}
|
||
5 years ago
|
settings.theme = app.settings.get('theme')
|
||
8 years ago
|
settings.smoothScroll = !app.settings.get('fastScroll')
|
||
8 years ago
|
settings.arrowScroll = app.settings.get('arrowScroll')
|
||
2 years ago
|
settings.noAutofocus = app.settings.get('noAutofocus')
|
||
6 years ago
|
settings.autoInstall = app.settings.get('autoInstall')
|
||
6 years ago
|
settings.analyticsConsent = app.settings.get('analyticsConsent')
|
||
4 years ago
|
settings.spaceScroll = app.settings.get('spaceScroll')
|
||
4 years ago
|
settings.spaceTimeout = app.settings.get('spaceTimeout')
|
||
5 years ago
|
settings.autoSupported = app.settings.autoSupported
|
||
6 years ago
|
settings[layout] = app.settings.hasLayout(layout) for layout in app.settings.LAYOUTS
|
||
8 years ago
|
settings
|
||
|
|
||
|
getTitle: ->
|
||
|
'Preferences'
|
||
|
|
||
5 years ago
|
setTheme: (value) ->
|
||
|
app.settings.set('theme', value)
|
||
8 years ago
|
return
|
||
|
|
||
|
toggleLayout: (layout, enable) ->
|
||
|
app.settings.setLayout(layout, enable)
|
||
|
return
|
||
|
|
||
8 years ago
|
toggleSmoothScroll: (enable) ->
|
||
|
app.settings.set('fastScroll', !enable)
|
||
|
return
|
||
|
|
||
6 years ago
|
toggleAnalyticsConsent: (enable) ->
|
||
|
app.settings.set('analyticsConsent', if enable then '1' else '0')
|
||
|
resetAnalytics() unless enable
|
||
|
return
|
||
|
|
||
4 years ago
|
toggleSpaceScroll: (enable) ->
|
||
|
app.settings.set('spaceScroll', if enable then 1 else 0)
|
||
|
return
|
||
|
|
||
4 years ago
|
setScrollTimeout: (value) ->
|
||
|
app.settings.set('spaceTimeout', value)
|
||
|
|
||
8 years ago
|
toggle: (name, enable) ->
|
||
|
app.settings.set(name, enable)
|
||
|
return
|
||
|
|
||
8 years ago
|
export: ->
|
||
|
data = new Blob([JSON.stringify(app.settings.export())], type: 'application/json')
|
||
|
link = document.createElement('a')
|
||
|
link.href = URL.createObjectURL(data)
|
||
|
link.download = 'devdocs.json'
|
||
|
link.style.display = 'none'
|
||
|
document.body.appendChild(link)
|
||
|
link.click()
|
||
|
document.body.removeChild(link)
|
||
|
return
|
||
|
|
||
|
import: (file, input) ->
|
||
|
unless file and file.type is 'application/json'
|
||
|
new app.views.Notif 'ImportInvalid', autoHide: false
|
||
|
return
|
||
|
|
||
|
reader = new FileReader()
|
||
|
reader.onloadend = ->
|
||
|
data = try JSON.parse(reader.result)
|
||
|
unless data and data.constructor is Object
|
||
|
new app.views.Notif 'ImportInvalid', autoHide: false
|
||
|
return
|
||
|
app.settings.import(data)
|
||
|
$.trigger input.form, 'import'
|
||
|
return
|
||
|
reader.readAsText(file)
|
||
|
return
|
||
|
|
||
8 years ago
|
onChange: (event) =>
|
||
|
input = event.target
|
||
|
switch input.name
|
||
5 years ago
|
when 'theme'
|
||
|
@setTheme input.value
|
||
8 years ago
|
when 'layout'
|
||
|
@toggleLayout input.value, input.checked
|
||
8 years ago
|
when 'smoothScroll'
|
||
|
@toggleSmoothScroll input.checked
|
||
8 years ago
|
when 'import'
|
||
|
@import input.files[0], input
|
||
6 years ago
|
when 'analyticsConsent'
|
||
|
@toggleAnalyticsConsent input.checked
|
||
4 years ago
|
when 'spaceScroll'
|
||
|
@toggleSpaceScroll input.checked
|
||
4 years ago
|
when 'spaceTimeout'
|
||
|
@setScrollTimeout input.value
|
||
8 years ago
|
else
|
||
|
@toggle input.name, input.checked
|
||
8 years ago
|
return
|
||
|
|
||
8 years ago
|
onClick: (event) =>
|
||
|
target = $.eventTarget(event)
|
||
|
switch target.getAttribute('data-action')
|
||
|
when 'export'
|
||
|
$.stopEvent(event)
|
||
|
@export()
|
||
|
return
|
||
|
|
||
8 years ago
|
onRoute: (context) ->
|
||
|
@render()
|
||
8 years ago
|
return
|