Merge from Appchan X: src/General/Settings.coffee
This commit is contained in:
parent
1a3b3012db
commit
ce1b7301e8
@ -10,14 +10,16 @@ Settings =
|
|||||||
|
|
||||||
Header.addShortcut link
|
Header.addShortcut link
|
||||||
|
|
||||||
Settings.addSection 'Main', Settings.main
|
add = @addSection
|
||||||
Settings.addSection 'Filter', Settings.filter
|
|
||||||
Settings.addSection 'Sauce', Settings.sauce
|
add 'Main', @main
|
||||||
Settings.addSection 'Advanced', Settings.advanced
|
add 'Filter', @filter
|
||||||
Settings.addSection 'Keybinds', Settings.keybinds
|
add 'Sauce', @sauce
|
||||||
|
add 'Advanced', @advanced
|
||||||
|
add 'Keybinds', @keybinds
|
||||||
|
|
||||||
$.on d, 'AddSettingsSection', Settings.addSection
|
$.on d, 'AddSettingsSection', Settings.addSection
|
||||||
$.on d, 'OpenSettings', (e) -> Settings.open e.detail
|
$.on d, 'OpenSettings', (e) -> Settings.open e.detail
|
||||||
|
|
||||||
if Conf['Disable Native Extension']
|
if Conf['Disable Native Extension']
|
||||||
settings = JSON.parse(localStorage.getItem '4chan-settings') or {}
|
settings = JSON.parse(localStorage.getItem '4chan-settings') or {}
|
||||||
@ -26,22 +28,22 @@ Settings =
|
|||||||
localStorage.setItem '4chan-settings', JSON.stringify settings
|
localStorage.setItem '4chan-settings', JSON.stringify settings
|
||||||
|
|
||||||
open: (openSection) ->
|
open: (openSection) ->
|
||||||
return if Settings.dialog
|
return if Settings.overlay
|
||||||
$.event 'CloseMenu'
|
$.event 'CloseMenu'
|
||||||
|
|
||||||
Settings.overlay = overlay = $.el 'div',
|
|
||||||
id: 'overlay'
|
|
||||||
|
|
||||||
Settings.dialog = dialog = $.el 'div',
|
Settings.dialog = dialog = $.el 'div',
|
||||||
id: 'fourchanx-settings'
|
id: 'fourchanx-settings'
|
||||||
className: 'dialog'
|
className: 'dialog'
|
||||||
$.extend dialog, <%= importHTML('Settings/Settings') %>
|
$.extend dialog, <%= importHTML('Settings/Settings') %>
|
||||||
$('a[href$="/CHANGELOG.md"]', dialog).textContent = g.VERSION
|
$('a[href$="/CHANGELOG.md"]', dialog).textContent = g.VERSION
|
||||||
|
|
||||||
$.on $('.export', Settings.dialog), 'click', Settings.export
|
Settings.overlay = overlay = $.el 'div',
|
||||||
$.on $('.import', Settings.dialog), 'click', Settings.import
|
id: 'overlay'
|
||||||
$.on $('.reset', Settings.dialog), 'click', Settings.reset
|
|
||||||
$.on $('input', Settings.dialog), 'change', Settings.onImport
|
$.on $('.export', dialog), 'click', Settings.export
|
||||||
|
$.on $('.import', dialog), 'click', Settings.import
|
||||||
|
$.on $('.reset', dialog), 'click', Settings.reset
|
||||||
|
$.on $('input', dialog), 'change', Settings.onImport
|
||||||
|
|
||||||
links = []
|
links = []
|
||||||
for section in Settings.sections
|
for section in Settings.sections
|
||||||
@ -54,7 +56,7 @@ Settings =
|
|||||||
sectionToOpen = link if section.title is openSection
|
sectionToOpen = link if section.title is openSection
|
||||||
links.pop()
|
links.pop()
|
||||||
$.add $('.sections-list', dialog), links
|
$.add $('.sections-list', dialog), links
|
||||||
(if sectionToOpen then sectionToOpen else links[0]).click()
|
(if sectionToOpen then sectionToOpen else links[0]).click() unless openSection is 'none'
|
||||||
|
|
||||||
$.on $('.close', dialog), 'click', Settings.close
|
$.on $('.close', dialog), 'click', Settings.close
|
||||||
$.on overlay, 'click', Settings.close
|
$.on overlay, 'click', Settings.close
|
||||||
@ -103,8 +105,9 @@ Settings =
|
|||||||
div = $.el 'div',
|
div = $.el 'div',
|
||||||
<%= html('<label><input type="checkbox" name="${key}">${key}</label><span class="description">: ${description}</span>') %>
|
<%= html('<label><input type="checkbox" name="${key}">${key}</label><span class="description">: ${description}</span>') %>
|
||||||
input = $ 'input', div
|
input = $ 'input', div
|
||||||
$.on input, 'change', $.cb.checked
|
$.on input, 'change', ->
|
||||||
$.on input, 'change', -> @parentNode.parentNode.dataset.checked = @checked
|
@parentNode.parentNode.dataset.checked = @checked
|
||||||
|
$.cb.checked.call @
|
||||||
items[key] = Conf[key]
|
items[key] = Conf[key]
|
||||||
inputs[key] = input
|
inputs[key] = input
|
||||||
level = arr[2] or 0
|
level = arr[2] or 0
|
||||||
@ -160,7 +163,7 @@ Settings =
|
|||||||
<% } %>
|
<% } %>
|
||||||
a.click()
|
a.click()
|
||||||
import: ->
|
import: ->
|
||||||
$('input', @parentNode).click()
|
$('input[type=file]', @parentNode).click()
|
||||||
|
|
||||||
onImport: ->
|
onImport: ->
|
||||||
return unless file = @files[0]
|
return unless file = @files[0]
|
||||||
@ -305,17 +308,21 @@ Settings =
|
|||||||
items = {}
|
items = {}
|
||||||
inputs = {}
|
inputs = {}
|
||||||
for name in ['boardnav', 'time', 'backlink', 'fileInfo', 'favicon', 'usercss']
|
for name in ['boardnav', 'time', 'backlink', 'fileInfo', 'favicon', 'usercss']
|
||||||
input = $ "[name=#{name}]", section
|
input = $ "[name='#{name}']", section
|
||||||
items[name] = Conf[name]
|
items[name] = Conf[name]
|
||||||
inputs[name] = input
|
inputs[name] = input
|
||||||
event = if name in ['favicon', 'usercss']
|
if name is 'usercss'
|
||||||
'change'
|
$.on input, 'change', $.cb.value
|
||||||
else
|
else if name is 'favicon'
|
||||||
'input'
|
$.on input, 'change', $.cb.value
|
||||||
$.on input, event, $.cb.value
|
$.on input, 'change', Settings[name]
|
||||||
|
else
|
||||||
|
$.on input, 'input', $.cb.value
|
||||||
|
$.on input, 'input', Settings[name]
|
||||||
|
|
||||||
# Quick Reply Personas
|
# Quick Reply Personas
|
||||||
ta = $ '.personafield', section
|
ta = $ '.personafield', section
|
||||||
|
|
||||||
$.get 'QR.personas', Conf['QR.personas'], (item) ->
|
$.get 'QR.personas', Conf['QR.personas'], (item) ->
|
||||||
ta.value = item['QR.personas']
|
ta.value = item['QR.personas']
|
||||||
$.on ta, 'change', $.cb.value
|
$.on ta, 'change', $.cb.value
|
||||||
@ -325,7 +332,6 @@ Settings =
|
|||||||
input = inputs[key]
|
input = inputs[key]
|
||||||
input.value = val
|
input.value = val
|
||||||
continue if key is 'usercss'
|
continue if key is 'usercss'
|
||||||
$.on input, event, Settings[key]
|
|
||||||
Settings[key].call input
|
Settings[key].call input
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -484,6 +490,7 @@ Settings =
|
|||||||
inputs[key] = input
|
inputs[key] = input
|
||||||
$.on input, 'keydown', Settings.keybind
|
$.on input, 'keydown', Settings.keybind
|
||||||
$.add tbody, tr
|
$.add tbody, tr
|
||||||
|
|
||||||
$.get items, (items) ->
|
$.get items, (items) ->
|
||||||
for key, val of items
|
for key, val of items
|
||||||
inputs[key].value = val
|
inputs[key].value = val
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user