|
|
@@ -5,6 +5,7 @@ class app.views.SettingsPage extends app.View
|
|
|
@className: '_static'
|
|
|
|
|
|
@events:
|
|
|
+ click: 'onClick'
|
|
|
change: 'onChange'
|
|
|
|
|
|
render: ->
|
|
|
@@ -46,6 +47,34 @@ class app.views.SettingsPage extends app.View
|
|
|
app.settings.set(name, enable)
|
|
|
return
|
|
|
|
|
|
+ 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
|
|
|
+
|
|
|
onChange: (event) =>
|
|
|
input = event.target
|
|
|
switch input.name
|
|
|
@@ -55,10 +84,20 @@ class app.views.SettingsPage extends app.View
|
|
|
@toggleLayout input.value, input.checked
|
|
|
when 'smoothScroll'
|
|
|
@toggleSmoothScroll input.checked
|
|
|
+ when 'import'
|
|
|
+ @import input.files[0], input
|
|
|
else
|
|
|
@toggle input.name, input.checked
|
|
|
return
|
|
|
|
|
|
+ onClick: (event) =>
|
|
|
+ target = $.eventTarget(event)
|
|
|
+ switch target.getAttribute('data-action')
|
|
|
+ when 'export'
|
|
|
+ $.stopEvent(event)
|
|
|
+ @export()
|
|
|
+ return
|
|
|
+
|
|
|
onRoute: (context) ->
|
|
|
@render()
|
|
|
return
|