Simplify Advanced Settings code.

This commit is contained in:
ccd0 2016-05-14 19:41:31 -07:00
parent 692114c099
commit 5a9eac7cc6

View File

@ -425,39 +425,29 @@ Settings =
$.extend section, <%= readHTML('Advanced.html') %> $.extend section, <%= readHTML('Advanced.html') %>
warning.hidden = Conf[warning.dataset.feature] for warning in $$ '.warning', section warning.hidden = Conf[warning.dataset.feature] for warning in $$ '.warning', section
items = {}
inputs = {} inputs = {}
for name in ['captchaLanguage', 'boardnav', 'time', 'backlink', 'fileInfo', 'favicon', 'usercss', 'customCooldown'] for input in $$ '[name]', section
input = $ "[name='#{name}']", section inputs[input.name] = input
items[name] = Conf[name]
inputs[name] = input
if name is 'usercss'
$.on input, 'change', $.cb.value
else if name is 'favicon'
$.on input, 'change', $.cb.value
$.on input, 'change', Settings[name]
else
$.on input, 'input', $.cb.value
$.on input, 'input', Settings[name] if name of Settings
# Quick Reply Personas items = {}
ta = $ '.personafield', section for name in ['captchaLanguage', 'boardnav', 'time', 'backlink', 'fileInfo', 'QR.personas', 'favicon', 'usercss', 'customCooldown']
items[name] = Conf[name]
$.get 'QR.personas', Conf['QR.personas'], (item) -> input = inputs[name]
ta.value = item['QR.personas'] event = if name in ['QR.personas', 'favicon', 'usercss'] then 'change' else 'input'
$.on ta, 'change', $.cb.value $.on input, event, $.cb.value
$.on input, event, Settings[name] if name of Settings
$.get items, (items) -> $.get items, (items) ->
for key, val of items for key, val of items
input = inputs[key] input = inputs[key]
input.value = val input.value = val
if key of Settings and key isnt 'usercss' if key of Settings
Settings[key].call input Settings[key].call input
return return
interval = $ 'input[name="Interval"]', section interval = inputs['Interval']
customCSS = $ 'input[name="Custom CSS"]', section customCSS = inputs['Custom CSS']
applyCSS = $ '#apply-css', section applyCSS = $ '#apply-css', section
interval.value = Conf['Interval'] interval.value = Conf['Interval']
customCSS.checked = Conf['Custom CSS'] customCSS.checked = Conf['Custom CSS']
@ -466,7 +456,7 @@ Settings =
$.on interval, 'change', ThreadUpdater.cb.interval $.on interval, 'change', ThreadUpdater.cb.interval
$.on customCSS, 'change', Settings.togglecss $.on customCSS, 'change', Settings.togglecss
$.on applyCSS, 'click', Settings.usercss $.on applyCSS, 'click', -> CustomCSS.update()
archBoards = {} archBoards = {}
for {uid, name, boards, files, software, withCredentials} in Redirect.archives for {uid, name, boards, files, software, withCredentials} in Redirect.archives
@ -595,9 +585,6 @@ Settings =
CustomCSS.addStyle() CustomCSS.addStyle()
$.cb.checked.call @ $.cb.checked.call @
usercss: ->
CustomCSS.update()
keybinds: (section) -> keybinds: (section) ->
$.extend section, <%= readHTML('Keybinds.html') %> $.extend section, <%= readHTML('Keybinds.html') %>
$('.warning', section).hidden = Conf['Keybinds'] $('.warning', section).hidden = Conf['Keybinds']