Finish fixing up settings dialogs for mascots and themes.

This commit is contained in:
Zixaphir 2013-04-13 22:35:08 -07:00
parent cbc0092e48
commit 19178d86df
8 changed files with 460 additions and 350 deletions

File diff suppressed because one or more lines are too long

View File

@ -1193,6 +1193,7 @@ input.field.tripped:not(:hover):not(:focus) {
.captcha-img { .captcha-img {
margin: 1px 0 0; margin: 1px 0 0;
text-align: center; text-align: center;
line-height: 0;
} }
.captcha-img img { .captcha-img img {
width: 100%; width: 100%;
@ -1681,12 +1682,12 @@ opacity: 0;
#themebar input { #themebar input {
width: 30%; width: 30%;
} }
.color { .option .color {
width: 10%; width: 10%;
border-left: none !important; border-left: none !important;
color: transparent !important; color: transparent !important;
} }
.colorfield { .option .colorfield {
width: 90%; width: 90%;
} }
.themevar textarea { .themevar textarea {

View File

@ -9,6 +9,7 @@ $$ = (selector, root=d.body) ->
$.extend = (object, properties) -> $.extend = (object, properties) ->
for key, val of properties for key, val of properties
continue unless properties.hasOwnProperty key
object[key] = val object[key] = val
return return

View File

@ -1292,7 +1292,7 @@ MascotTools =
MascotTools.save editMascot MascotTools.save editMascot
$.on $('#close > a', dialog), 'click', MascotTools.close $.on $('#close > a', dialog), 'click', MascotTools.close
Style.rice(dialog) Rice.nodes(dialog)
$.add d.body, dialog $.add d.body, dialog
input: (item, name) -> input: (item, name) ->
@ -1376,7 +1376,7 @@ MascotTools =
close: -> close: ->
Conf['editMode'] = false Conf['editMode'] = false
editMascot = {} editMascot = {}
$.rm $.id mascotConf $.rm $.id 'mascotConf'
Style.addStyle() Style.addStyle()
Settings.open "mascots" Settings.open "mascots"

View File

@ -229,6 +229,10 @@ Config =
false false
'Remember the spoiler state, instead of resetting after posting.' 'Remember the spoiler state, instead of resetting after posting.'
] ]
'Remember QR Size': [
false
'Remember the size of the quick reply\'s comment field.'
]
'Hide Original Post Form': [ 'Hide Original Post Form': [
true true
'Hide the normal post form.' 'Hide the normal post form.'

View File

@ -1306,9 +1306,6 @@ a.forwardlink{
border-radius: 0 !important; border-radius: 0 !important;
margin-bottom: 0; margin-bottom: 0;
} }
.thread .op {
padding: 0 3px;
}
#themes { #themes {
text-shadow: none; text-shadow: none;
} }

View File

@ -802,6 +802,12 @@ QR =
status: $ '[type=submit]', dialog status: $ '[type=submit]', dialog
fileInput: $ '[type=file]', dialog fileInput: $ '[type=file]', dialog
if Conf['Remember QR Size']
$.get 'QR.size', '', (item) ->
nodes.com.style.cssText = item['QR.size']
$.on nodes.com, 'mouseup', ->
$.set 'QR.size', @style.cssText
# Allow only this board's supported files. # Allow only this board's supported files.
mimeTypes = $('ul.rules > li').textContent.trim().match(/: (.+)/)[1].toLowerCase().replace /\w+/g, (type) -> mimeTypes = $('ul.rules > li').textContent.trim().match(/: (.+)/)[1].toLowerCase().replace /\w+/g, (type) ->
switch type switch type

View File

@ -644,6 +644,8 @@ Settings =
keys = Object.keys(Themes) keys = Object.keys(Themes)
keys.sort() keys.sort()
cb = Settings.cb.theme
if mode is "default" if mode is "default"
for name in keys for name in keys
@ -700,46 +702,11 @@ Settings =
div.style.backgroundColor = theme['Background Color'] div.style.backgroundColor = theme['Background Color']
$.on $('a.edit', div), 'click', (e) -> $.on $('a.edit', div), 'click', cb.edit
e.preventDefault() $.on $('a.export', div), 'click', cb.export
e.stopPropagation() $.on $('a.delete', div), 'click', cb.delete
ThemeTools.init @name $.on div, 'click', cb.select
Settings.close()
$.on $('a.export', div), 'click', (e) ->
e.preventDefault()
e.stopPropagation()
exportTheme = Themes[@name]
exportTheme['Theme'] = @name
exportedTheme = "data:application/json," + encodeURIComponent(JSON.stringify(exportTheme))
if window.open exportedTheme, "_blank"
return
else if confirm "Your popup blocker is preventing Appchan X from exporting this theme. Would you like to open the exported theme in this window?"
window.location exportedTheme
$.on $('a.delete', div), 'click', (e) ->
e.preventDefault()
e.stopPropagation()
container = $.id @name
unless container.previousSibling or container.nextSibling
alert "Cannot delete theme (No other themes available)."
return
if confirm "Are you sure you want to delete \"#{@name}\"?"
if @name is Conf['theme']
if settheme = container.previousSibling or container.nextSibling
Conf['theme'] = settheme.id
$.addClass settheme, 'selectedtheme'
$.set 'theme', Conf['theme']
Themes[@name]["Deleted"] = true
userThemes = $.get "userThemes", {}
userThemes[@name] = Themes[@name]
$.set 'userThemes', userThemes
$.rm container
$.on div, 'click', Settings.selectTheme
$.add suboptions, div $.add suboptions, div
div = $.el 'div', div = $.el 'div',
@ -758,16 +725,17 @@ Settings =
$.on $("#import", div), 'click', -> $.on $("#import", div), 'click', ->
@nextSibling.click() @nextSibling.click()
$.on $("#importbutton", div), 'change', (evt) -> $.on $("#importbutton", div), 'change', (e) ->
ThemeTools.importtheme "appchan", evt ThemeTools.importtheme "appchan", e
$.on $("#OCimport", div), 'click', -> $.on $("#OCimport", div), 'click', ->
@nextSibling.click() @nextSibling.click()
$.on $("#OCimportbutton", div), 'change', (evt) -> $.on $("#OCimportbutton", div), 'change', (e) ->
ThemeTools.importtheme "oneechan", evt ThemeTools.importtheme "oneechan", e
$.on $("#SSimportbutton", div), 'change', (e) ->
ThemeTools.importtheme "SS", e
$.on $("#SSimportbutton", div), 'change', (evt) ->
ThemeTools.importtheme "SS", evt
$.on $("#SSimport", div), 'click', -> $.on $("#SSimport", div), 'click', ->
@nextSibling.click() @nextSibling.click()
@ -804,14 +772,7 @@ Settings =
</blockquote> </blockquote>
</div>" </div>"
$.on div, 'click', -> $.on div, 'click', cb.restore
if confirm "Are you sure you want to undelete \"#{@id}\"?"
Themes[@id]["Deleted"] = false
$.get "userThemes", {}, (item) ->
userThemes = item["userThemes"]
userThemes[@id] = Themes[@id]
$.set 'userThemes', userThemes
$.rm @
$.add suboptions, div $.add suboptions, div
@ -827,18 +788,6 @@ Settings =
$.add parentdiv, div $.add parentdiv, div
$.add section, parentdiv $.add section, parentdiv
selectTheme: ->
if currentTheme = $.id(Conf['theme'])
$.rmClass currentTheme, 'selectedtheme'
if Conf["NSFW/SFW Themes"]
$.set "theme_#{g.TYPE}", @id
else
$.set "theme", @id
Conf['theme'] = @id
$.addClass @, 'selectedtheme'
Style.addStyle()
mouseover: (e) -> mouseover: (e) ->
mouseover = $.el 'div', mouseover = $.el 'div',
id: 'mouseover' id: 'mouseover'
@ -858,10 +807,10 @@ Settings =
return return
mascots: (section, mode) -> mascots: (section, mode) ->
ul = {} categories = {}
categories = [] menu = []
cb = Settings.cb.mascot
if typeof mode isnt 'string' if typeof mode isnt 'string'
mode = 'default' mode = 'default'
@ -875,94 +824,60 @@ Settings =
mascotHide = $.el "div", mascotHide = $.el "div",
id: "mascot_hide" id: "mascot_hide"
className: "reply" className: "reply"
innerHTML: "Hide Categories <span></span><div></div>" innerHTML: "Hide Categories <span class=dropmarker></span><div></div>"
keys = Object.keys Mascots keys = Object.keys Mascots
keys.sort() keys.sort()
if mode is 'default' if mode is 'default'
# Create a keyed Unordered List Element and hide option for each mascot category. # Create a keyed Unordered List Element and hide option for each mascot category.
for category in MascotTools.categories for name in MascotTools.categories
ul[category] = $.el "ul", categories[name] = $.el "div",
className: "mascots" className: "mascots"
id: category id: name
if Conf["Hidden Categories"].contains category if Conf["Hidden Categories"].contains name
ul[category].hidden = true categories[name].hidden = true
header = $.el "h3", header = $.el "h3",
className: "mascotHeader" className: "mascotHeader"
textContent: category textContent: name
categories.push option = $.el "label", menu.push option = $.el "label",
name: category name: name
innerHTML: "<input name='#{category}' type=checkbox #{if Conf["Hidden Categories"].contains(category) then 'checked' else ''}>#{category}" innerHTML: "<input name='#{name}' type=checkbox #{if Conf["Hidden Categories"].contains(name) then 'checked' else ''}>#{name}"
$.on $('input', option), 'change', -> $.on $('input', option), 'change', Settings.cb.mascotCategory
Settings.mascotTab.toggle.call @
$.add ul[category], header $.add categories[name], header
$.add suboptions, ul[category] $.add suboptions, categories[name]
for name in keys for name in keys
unless Conf["Deleted Mascots"].contains name
mascot = Mascots[name] continue if Conf["Deleted Mascots"].contains name
li = $.el 'li', mascot = Mascots[name]
className: 'mascot' mascotEl = $.el 'div',
id: name className: 'mascot'
innerHTML: " id: name
innerHTML: "
<div class='mascotname'>#{name.replace /_/g, " "}</div> <div class='mascotname'>#{name.replace /_/g, " "}</div>
<div class='mascotcontainer'><div class='mAlign #{mascot.category}'><img class=mascotimg src='#{if Array.isArray(mascot.image) then (if Style.lightTheme then mascot.image[1] else mascot.image[0]) else mascot.image}'></div></div> <div class='mascotcontainer'><div class='mAlign #{mascot.category}'><img class=mascotimg src='#{if Array.isArray(mascot.image) then (if Style.lightTheme then mascot.image[1] else mascot.image[0]) else mascot.image}'></div></div>
<div class='mascotoptions'><a class=edit name='#{name}' href='javascript:;'>Edit</a><a class=delete name='#{name}' href='javascript:;'>Delete</a><a class=export name='#{name}' href='javascript:;'>Export</a></div>" <div class='mascotoptions'><a class=edit name='#{name}' href='javascript:;'>Edit</a><a class=delete name='#{name}' href='javascript:;'>Delete</a><a class=export name='#{name}' href='javascript:;'>Export</a></div>"
if Conf[g.MASCOTSTRING].contains name if Conf[g.MASCOTSTRING].contains name
$.addClass li, 'enabled' $.addClass mascotEl, 'enabled'
$.on $('a.edit', li), 'click', (e) -> $.on $('.edit', mascotEl), 'click', cb.edit
e.stopPropagation() $.on $('.delete', mascotEl), 'click', cb.delete
MascotTools.dialog @name $.on $('.export', mascotEl), 'click', cb.export
Settings.close() $.on mascotEl, 'click', cb.select
$.on $('a.delete', li), 'click', (e) -> if MascotTools.categories.contains mascot.category
e.stopPropagation() $.add categories[mascot.category], mascotEl
if confirm "Are you sure you want to delete \"#{@name}\"?" else
if Conf['mascot'] is @name $.add categories[MascotTools.categories[0]], mascotEl
MascotTools.init()
for type in ["Enabled Mascots", "Enabled Mascots sfw", "Enabled Mascots nsfw"]
Conf[type].remove @name
$.set type, Conf[type]
Conf["Deleted Mascots"].push @name
$.set "Deleted Mascots", Conf["Deleted Mascots"]
$.rm $.id @name
# Mascot Exporting $.add $('div', mascotHide), menu
$.on $('a.export', li), 'click', (e) ->
e.stopPropagation()
exportMascot = Mascots[@name]
exportMascot['Mascot'] = @name
exportedMascot = "data:application/json," + encodeURIComponent(JSON.stringify(exportMascot))
if window.open exportedMascot, "_blank"
return
else if confirm "Your popup blocker is preventing Appchan X from exporting this theme. Would you like to open the exported theme in this window?"
window.location exportedMascot
$.on li, 'click', ->
if Conf[g.MASCOTSTRING].remove @id
if Conf['mascot'] is @id
MascotTools.init()
else
Conf[g.MASCOTSTRING].push @id
MascotTools.init @id
$.toggleClass @, 'enabled'
$.set g.MASCOTSTRING, Conf[g.MASCOTSTRING]
if MascotTools.categories.contains mascot.category
$.add ul[mascot.category], li
else
$.add ul[MascotTools.categories[0]], li
$.add $('div', mascotHide), categories
batchmascots = $.el 'div', batchmascots = $.el 'div',
id: "mascots_batch" id: "mascots_batch"
@ -995,8 +910,8 @@ Settings =
$.on $("#importMascot", batchmascots), 'click', -> $.on $("#importMascot", batchmascots), 'click', ->
@nextSibling.click() @nextSibling.click()
$.on $("#importMascotButton", batchmascots), 'change', (evt) -> $.on $("#importMascotButton", batchmascots), 'change', (e) ->
MascotTools.importMascot evt MascotTools.importMascot e
$.on $('#undelete', batchmascots), 'click', -> $.on $('#undelete', batchmascots), 'click', ->
unless Conf["Deleted Mascots"].length > 0 unless Conf["Deleted Mascots"].length > 0
@ -1006,30 +921,26 @@ Settings =
Settings.mascotTab.dialog Settings.el, 'undelete' Settings.mascotTab.dialog Settings.el, 'undelete'
else else
ul = $.el "ul", categories = $.el "div",
className: "mascots" className: "mascots"
id: category id: name
for name in keys for name in keys
if Conf["Deleted Mascots"].contains name continue unless Conf["Deleted Mascots"].contains name
mascot = Mascots[name] mascot = Mascots[name]
li = $.el 'li', mascotEl = $.el 'div',
className: 'mascot' className: 'mascot'
id: name id: name
innerHTML: " innerHTML: "
<div class='mascotname'>#{name.replace /_/g, " "}</span> <div class='mascotname'>#{name.replace /_/g, " "}</span>
<div class='container #{mascot.category}'><img class=mascotimg src='#{if Array.isArray(mascot.image) then (if Style.lightTheme then mascot.image[1] else mascot.image[0]) else mascot.image}'></div> <div class='container #{mascot.category}'><img class=mascotimg src='#{if Array.isArray(mascot.image) then (if Style.lightTheme then mascot.image[1] else mascot.image[0]) else mascot.image}'></div>
" "
$.on li, 'click', -> $.on mascotEl, 'click', Settings.cb.mascot.restore
if confirm "Are you sure you want to undelete \"#{@id}\"?"
Conf["Deleted Mascots"].remove @id
$.set "Deleted Mascots", Conf["Deleted Mascots"]
$.rm @
$.add ul, li $.add categories, mascotEl
$.add suboptions, ul $.add suboptions, categories
batchmascots = $.el 'div', batchmascots = $.el 'div',
id: "mascots_batch" id: "mascots_batch"
@ -1043,4 +954,136 @@ Settings =
Rice.nodes parentdiv Rice.nodes parentdiv
$.add section, parentdiv $.add section, parentdiv
cb:
mascot:
category: ->
if $.id(@name).hidden = @checked
Conf["Hidden Categories"].push @name
# Gather all names of enabled mascots in the hidden category in every context it could be enabled.
for type in ["Enabled Mascots", "Enabled Mascots sfw", "Enabled Mascots nsfw"]
setting = Conf[type]
i = setting.length
test = type is g.MASCOTSTRING
while i--
name = setting[i]
continue unless Mascots[name].category is @name
setting.remove name
continue unless test
$.rmClass $.id(name), 'enabled'
$.set type, setting
else
Conf["Hidden Categories"].remove @name
$.set "Hidden Categories", Conf["Hidden Categories"]
edit: (e) ->
e.stopPropagation()
MascotTools.dialog @name
Settings.close()
delete: (e) ->
e.stopPropagation()
if confirm "Are you sure you want to delete \"#{@name}\"?"
if Conf['mascot'] is @name
MascotTools.init()
for type in ["Enabled Mascots", "Enabled Mascots sfw", "Enabled Mascots nsfw"]
Conf[type].remove @name
$.set type, Conf[type]
Conf["Deleted Mascots"].push @name
$.set "Deleted Mascots", Conf["Deleted Mascots"]
$.rm $.id @name
export: (e) ->
e.stopPropagation()
exportMascot = Mascots[@name]
exportMascot['Mascot'] = @name
exportedMascot = "data:application/json," + encodeURIComponent(JSON.stringify(exportMascot))
if window.open exportedMascot, "_blank"
return
else if confirm "Your popup blocker is preventing Appchan X from exporting this theme. Would you like to open the exported theme in this window?"
window.location exportedMascot
restore: ->
if confirm "Are you sure you want to restore \"#{@id}\"?"
Conf["Deleted Mascots"].remove @id
$.set "Deleted Mascots", Conf["Deleted Mascots"]
$.rm @
select: ->
if Conf[g.MASCOTSTRING].remove @id
if Conf['mascot'] is @id
MascotTools.init()
else
Conf[g.MASCOTSTRING].push @id
MascotTools.init @id
$.toggleClass @, 'enabled'
$.set g.MASCOTSTRING, Conf[g.MASCOTSTRING]
theme:
select: ->
if currentTheme = $.id(Conf['theme'])
$.rmClass currentTheme, 'selectedtheme'
if Conf["NSFW/SFW Themes"]
$.set "theme_#{g.TYPE}", @id
else
$.set "theme", @id
Conf['theme'] = @id
$.addClass @, 'selectedtheme'
Style.addStyle()
edit: (e) ->
e.preventDefault()
e.stopPropagation()
ThemeTools.init @name
Settings.close()
export: (e) ->
e.preventDefault()
e.stopPropagation()
exportTheme = Themes[@name]
exportTheme['Theme'] = @name
exportedTheme = "data:application/json," + encodeURIComponent(JSON.stringify(exportTheme))
if window.open exportedTheme, "_blank"
return
else if confirm "Your popup blocker is preventing Appchan X from exporting this theme. Would you like to open the exported theme in this window?"
window.location exportedTheme
delete: (e) ->
e.preventDefault()
e.stopPropagation()
container = $.id @name
unless container.previousSibling or container.nextSibling
alert "Cannot delete theme (No other themes available)."
return
if confirm "Are you sure you want to delete \"#{@name}\"?"
if @name is Conf['theme']
if settheme = container.previousSibling or container.nextSibling
Conf['theme'] = settheme.id
$.addClass settheme, 'selectedtheme'
$.set 'theme', Conf['theme']
Themes[@name]["Deleted"] = true
userThemes = $.get "userThemes", {}
userThemes[@name] = Themes[@name]
$.set 'userThemes', userThemes
$.rm container
restore: ->
if confirm "Are you sure you want to restore \"#{@id}\"?"
Themes[@id]["Deleted"] = false
$.get "userThemes", {}, (item) ->
userThemes = item["userThemes"]
userThemes[@id] = Themes[@id]
$.set 'userThemes', userThemes
$.rm @