MascotTools =
init: (mascot) ->
unless mascot and mascot.image
return unless Conf[g.MASCOTSTRING].length
name = Conf[g.MASCOTSTRING][Math.floor(Math.random() * Conf[g.MASCOTSTRING].length)]
mascot = Mascots[name]
Conf['mascot'] = name
unless @el
@el = $.el 'div',
id: "mascot"
innerHTML: ""
if Conf['Click to Toggle']
$.on @el, 'mousedown', MascotTools.click
$.on doc, 'QRDialogCreation', MascotTools.reposition
$.asap (-> d.body), =>
$.add d.body, @el
el = @el.firstElementChild
if !Conf['Mascots'] or (Conf['Hide Mascots on Catalog'] and g.VIEW is 'catalog')
if el then el.src = ""
return
if Conf['Mascot Position'] is 'default'
$.rmClass doc, 'mascot-position-above-post-form'
$.rmClass doc, 'mascot-position-bottom'
$.rmClass doc, 'mascot-position-default'
if mascot.position is 'bottom'
$.addClass doc, 'mascot-position-bottom'
else
$.addClass doc, 'mascot-position-above-post-form'
if mascot.silhouette and not Conf['Silhouette Filter']
$.addClass doc, 'silhouette-filter'
else unless Conf['Silhouette Filter']
$.rmClass doc, 'silhouette-filter'
unless mascot
if name and not mascot = Mascots[name]
if el then el.src = "" else null
Conf[g.MASCOTSTRING].remove name
return MascotTools.init()
image =
if Array.isArray mascot.image
if Style.lightTheme
mascot.image[1]
else
mascot.image[0]
else mascot.image
el.src = image
Style.mascot.textContent = """<%= grunt.file.read('src/General/css/mascot.css') %>"""
categories: [
'Anime'
'Ponies'
'Questionable'
'Silhouette'
'Western'
]
dialog: (key) ->
Conf['editMode'] = 'mascot'
if Mascots[key]
editMascot = JSON.parse(JSON.stringify(Mascots[key]))
else
editMascot = {}
editMascot.name = key or ''
layout =
name: [
"Mascot Name"
""
"text"
]
image: [
"Image"
""
"text"
]
category: [
"Category"
MascotTools.categories[0]
"select"
MascotTools.categories
]
position: [
"Position"
"default"
"select"
["default", "top", "bottom"]
]
height: [
"Height"
"auto"
"text"
]
width: [
"Width"
"auto"
"text"
]
vOffset: [
"Vertical Offset"
"0"
"number"
]
hOffset: [
"Horizontal Offset"
"0"
"number"
]
center: [
"Center Mascot"
false
"checkbox"
]
dialog = $.el "div",
id: "mascotConf"
className: "reply dialog"
innerHTML: """<%= grunt.file.read('src/General/html/Features/MascotDialog.html').replace(/>\s+<').trim() %>"""
container = $ "#mascotcontent", dialog
for name, item of layout
value = editMascot[name] or= item[1]
switch item[2]
when "text"
div = @input item, name
input = $ 'input', div
if name is 'image'
$.on input, 'blur', ->
editMascot[@name] = @value
MascotTools.init editMascot
fileInput = $.el 'input',
type: "file"
accept: "image/*"
title: "imagefile"
hidden: "hidden"
$.on input, 'click', (evt) ->
if evt.shiftKey
@.nextSibling.click()
$.on fileInput, 'change', (evt) ->
MascotTools.uploadImage evt, @
$.after input, fileInput
if name is 'name'
$.on input, 'blur', ->
@value = @value.replace /[^a-z-_0-9]/ig, "_"
if (@value isnt "") and !/^[a-z]/i.test @value
return alert "Mascot names must start with a letter."
editMascot[@name] = @value
MascotTools.init editMascot
else
$.on input, 'blur', ->
editMascot[@name] = @value
MascotTools.init editMascot
when "number"
div = @input item, name
$.on $('input', div), 'blur', ->
editMascot[@name] = parseInt @value
MascotTools.init editMascot
when "select"
optionHTML = "