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.
devdocs/assets/javascripts/app/settings.coffee

95 lines
1.9 KiB

11 years ago
class app.Settings
10 years ago
SETTINGS_KEY = 'settings'
DOCS_KEY = 'docs'
DARK_KEY = 'dark'
LAYOUT_KEY = 'layout'
SIZE_KEY = 'size'
10 years ago
@defaults:
10 years ago
count: 0
hideDisabled: false
hideIntro: false
news: 0
autoUpdate: true
schema: 0
10 years ago
constructor: (@store) ->
@create() unless @settings = @store.get(SETTINGS_KEY)
create: ->
@settings = $.extend({}, @constructor.defaults)
10 years ago
@applyLegacyValues @settings
@save()
return
applyLegacyValues: (settings) ->
for key, v of settings when (value = @store.get(key))?
10 years ago
settings[key] = value
@store.del(key)
return
save: ->
@store.set SETTINGS_KEY, @settings
set: (key, value) ->
@settings[key] = value
@save()
get: (key) ->
@settings[key] ? @constructor.defaults[key]
10 years ago
11 years ago
hasDocs: ->
10 years ago
try !!Cookies.get DOCS_KEY
11 years ago
getDocs: ->
try
10 years ago
Cookies.get(DOCS_KEY)?.split('/') or app.config.default_docs
11 years ago
catch
app.config.default_docs
setDocs: (docs) ->
try
Cookies.set DOCS_KEY, docs.join('/'), path: '/', expires: 1e8
catch
return
setDark: (value) ->
try
if value
Cookies.set DARK_KEY, '1', path: '/', expires: 1e8
else
Cookies.expire DARK_KEY
11 years ago
catch
return
setLayout: (name, enable) ->
try
layout = (Cookies.get(LAYOUT_KEY) || '').split(' ')
$.arrayDelete(layout, '')
if enable
layout.push(name) if layout.indexOf(name) is -1
else
$.arrayDelete(layout, name)
if layout.length > 0
Cookies.set LAYOUT_KEY, layout.join(' '), path: '/', expires: 1e8
else
Cookies.expire LAYOUT_KEY
catch
return
setSize: (value) ->
try
Cookies.set SIZE_KEY, value, path: '/', expires: 1e8
catch
return
11 years ago
reset: ->
10 years ago
try Cookies.expire DOCS_KEY
try Cookies.expire DARK_KEY
try Cookies.expire LAYOUT_KEY
try Cookies.expire SIZE_KEY
10 years ago
try @store.del(SETTINGS_KEY)
11 years ago
return