From d9cab09436ba187bd8be17e100fab9b0a99c2976 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Thu, 2 Jan 2014 02:07:29 -0700 Subject: [PATCH] God, what was I doing? --- builds/appchan-x.user.js | 80 +++++++++++++++++++------------------- builds/crx/script.js | 80 +++++++++++++++++++------------------- src/Theming/Mascots.coffee | 67 +++++++++++++++++-------------- 3 files changed, 117 insertions(+), 110 deletions(-) diff --git a/builds/appchan-x.user.js b/builds/appchan-x.user.js index bf9586f63..6e45e46e3 100644 --- a/builds/appchan-x.user.js +++ b/builds/appchan-x.user.js @@ -12717,7 +12717,7 @@ }, categories: ['Anime', 'Ponies', 'Questionable', 'Silhouette', 'Western'], dialog: function(key) { - var container, dialog, div, fileInput, input, item, layout, name, option, optionHTML, setting, value, _i, _len, _ref; + var container, dialog, div, fileInput, fileRice, imageFn, input, item, layout, name, nameFn, option, optionHTML, saveCheck, saveVal, setting, updateMascot, value, _i, _len, _ref; Conf['editMode'] = 'mascot'; if (Mascots[key]) { editMascot = JSON.parse(JSON.stringify(Mascots[key])); @@ -12743,6 +12743,38 @@ innerHTML: "
\nPROTIP: Shift-Click the Mascot Image field to upload your own images!\n
This may have some caveats.
Save Mascot
Close
" }); container = $("#mascotcontent", dialog); + fileRice = function(e) { + if (e.shiftKey) { + return this.nextSibling.click(); + } + }; + updateMascot = function() { + return MascotTools.change(editMascot); + }; + saveVal = function() { + editMascot[this.name] = this.value; + return updateMascot(); + }; + imageFn = function() { + if (MascotTools.URL === this.value) { + return MascotTools.change(editMascot); + } else if (MascotTools.URL) { + URL.revokeObjectURL(MascotTools.URL); + delete MascotTools.URL; + } + return saveVal.call(this); + }; + nameFn = function() { + this.value = this.value.replace(/[^a-z-_0-9]/ig, "_"); + if ((this.value !== "") && !/^[a-z]/i.test(this.value)) { + return alert("Mascot names must start with a letter."); + } + return saveVal.call(this); + }; + saveCheck = function() { + editMascot[this.name] = this.checked ? true : false; + return updateMascot(); + }; for (name in layout) { item = layout[name]; value = editMascot[name] || (editMascot[name] = item[1]); @@ -12752,53 +12784,27 @@ input = $('input', div); switch (name) { case 'image': - $.on(input, 'blur', function() { - if (MascotTools.URL === this.value) { - return MascotTools.change(editMascot); - } else if (MascotTools.URL) { - URL.revokeObjectURL(MascotTools.URL); - delete MascotTools.URL; - } - editMascot[this.name] = this.value; - return MascotTools.change(editMascot); - }); + $.on(input, 'blur', imageFn); fileInput = $.el('input', { type: "file", accept: "image/*", title: "imagefile", hidden: "hidden" }); - $.on(input, 'click', function(e) { - if (e.shiftKey) { - return this.nextSibling.click(); - } - }); + $.on(input, 'click', FileRice); $.on(fileInput, 'change', MascotTools.uploadImage); $.after(input, fileInput); break; case 'name': - $.on(input, 'blur', function() { - this.value = this.value.replace(/[^a-z-_0-9]/ig, "_"); - if ((this.value !== "") && !/^[a-z]/i.test(this.value)) { - return alert("Mascot names must start with a letter."); - } - editMascot[this.name] = this.value; - return MascotTools.change(editMascot); - }); + $.on(input, 'blur', nameFn); break; default: - $.on(input, 'blur', function() { - editMascot[this.name] = this.value; - return MascotTools.change(editMascot); - }); + $.on(input, 'blur', saveVal); } break; case "number": div = this.input(item, name); - $.on($('input', div), 'blur', function() { - editMascot[this.name] = parseInt(this.value); - return MascotTools.change(editMascot); - }); + $.on($('input', div), 'blur', saveVal); break; case "select": optionHTML = "
" + item[0] + "
" + item[0] + "" }); - $.on($('input', div), 'click', function() { - editMascot[this.name] = this.checked ? true : false; - return MascotTools.change(editMascot); - }); + $.on($('input', div), 'click', saveCheck); } $.add(container, div); } diff --git a/builds/crx/script.js b/builds/crx/script.js index 564a4a1b7..1bc179ba7 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -12722,7 +12722,7 @@ }, categories: ['Anime', 'Ponies', 'Questionable', 'Silhouette', 'Western'], dialog: function(key) { - var container, dialog, div, fileInput, input, item, layout, name, option, optionHTML, setting, value, _i, _len, _ref; + var container, dialog, div, fileInput, fileRice, imageFn, input, item, layout, name, nameFn, option, optionHTML, saveCheck, saveVal, setting, updateMascot, value, _i, _len, _ref; Conf['editMode'] = 'mascot'; if (Mascots[key]) { editMascot = JSON.parse(JSON.stringify(Mascots[key])); @@ -12748,6 +12748,38 @@ innerHTML: "
\nPROTIP: Shift-Click the Mascot Image field to upload your own images!\n
This may have some caveats.
" }); container = $("#mascotcontent", dialog); + fileRice = function(e) { + if (e.shiftKey) { + return this.nextSibling.click(); + } + }; + updateMascot = function() { + return MascotTools.change(editMascot); + }; + saveVal = function() { + editMascot[this.name] = this.value; + return updateMascot(); + }; + imageFn = function() { + if (MascotTools.URL === this.value) { + return MascotTools.change(editMascot); + } else if (MascotTools.URL) { + URL.revokeObjectURL(MascotTools.URL); + delete MascotTools.URL; + } + return saveVal.call(this); + }; + nameFn = function() { + this.value = this.value.replace(/[^a-z-_0-9]/ig, "_"); + if ((this.value !== "") && !/^[a-z]/i.test(this.value)) { + return alert("Mascot names must start with a letter."); + } + return saveVal.call(this); + }; + saveCheck = function() { + editMascot[this.name] = this.checked ? true : false; + return updateMascot(); + }; for (name in layout) { item = layout[name]; value = editMascot[name] || (editMascot[name] = item[1]); @@ -12757,53 +12789,27 @@ input = $('input', div); switch (name) { case 'image': - $.on(input, 'blur', function() { - if (MascotTools.URL === this.value) { - return MascotTools.change(editMascot); - } else if (MascotTools.URL) { - URL.revokeObjectURL(MascotTools.URL); - delete MascotTools.URL; - } - editMascot[this.name] = this.value; - return MascotTools.change(editMascot); - }); + $.on(input, 'blur', imageFn); fileInput = $.el('input', { type: "file", accept: "image/*", title: "imagefile", hidden: "hidden" }); - $.on(input, 'click', function(e) { - if (e.shiftKey) { - return this.nextSibling.click(); - } - }); + $.on(input, 'click', FileRice); $.on(fileInput, 'change', MascotTools.uploadImage); $.after(input, fileInput); break; case 'name': - $.on(input, 'blur', function() { - this.value = this.value.replace(/[^a-z-_0-9]/ig, "_"); - if ((this.value !== "") && !/^[a-z]/i.test(this.value)) { - return alert("Mascot names must start with a letter."); - } - editMascot[this.name] = this.value; - return MascotTools.change(editMascot); - }); + $.on(input, 'blur', nameFn); break; default: - $.on(input, 'blur', function() { - editMascot[this.name] = this.value; - return MascotTools.change(editMascot); - }); + $.on(input, 'blur', saveVal); } break; case "number": div = this.input(item, name); - $.on($('input', div), 'blur', function() { - editMascot[this.name] = parseInt(this.value); - return MascotTools.change(editMascot); - }); + $.on($('input', div), 'blur', saveVal); break; case "select": optionHTML = "
" + item[0] + "
" + item[0] + "" }); - $.on($('input', div), 'click', function() { - editMascot[this.name] = this.checked ? true : false; - return MascotTools.change(editMascot); - }); + $.on($('input', div), 'click', saveCheck); } $.add(container, div); } diff --git a/src/Theming/Mascots.coffee b/src/Theming/Mascots.coffee index 6b0cc0648..caedc98de 100644 --- a/src/Theming/Mascots.coffee +++ b/src/Theming/Mascots.coffee @@ -83,7 +83,7 @@ MascotTools = dialog: (key) -> Conf['editMode'] = 'mascot' if Mascots[key] - editMascot = JSON.parse(JSON.stringify(Mascots[key])) + editMascot = JSON.parse JSON.stringify Mascots[key] else editMascot = {} editMascot.name = key or '' @@ -147,6 +147,35 @@ MascotTools = innerHTML: """<%= grunt.file.read('src/General/html/Features/MascotDialog.html').replace(/>\s+<').trim() %>""" container = $ "#mascotcontent", dialog + + fileRice = (e) -> + if e.shiftKey + @nextSibling.click() + + updateMascot = -> + MascotTools.change editMascot + + saveVal = -> + editMascot[@name] = @value + updateMascot() + + imageFn = -> + if MascotTools.URL is @value + return MascotTools.change editMascot + else if MascotTools.URL + URL.revokeObjectURL MascotTools.URL + delete MascotTools.URL + saveVal.call @ + + nameFn = -> + @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." + saveVal.call @ + + saveCheck = -> + editMascot[@name] = if @checked then true else false + updateMascot() for name, item of layout value = editMascot[name] or= item[1] @@ -159,14 +188,7 @@ MascotTools = switch name when 'image' - $.on input, 'blur', -> - if MascotTools.URL is @value - return MascotTools.change editMascot - else if MascotTools.URL - URL.revokeObjectURL MascotTools.URL - delete MascotTools.URL - editMascot[@name] = @value - MascotTools.change editMascot + $.on input, 'blur', imageFn fileInput = $.el 'input', type: "file" @@ -174,32 +196,21 @@ MascotTools = title: "imagefile" hidden: "hidden" - $.on input, 'click', (e) -> - if e.shiftKey - @nextSibling.click() + $.on input, 'click', FileRice $.on fileInput, 'change', MascotTools.uploadImage $.after input, fileInput when '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.change editMascot + $.on input, 'blur', nameFn else - $.on input, 'blur', -> - editMascot[@name] = @value - MascotTools.change editMascot + $.on input, 'blur', saveVal when "number" div = @input item, name - $.on $('input', div), 'blur', -> - editMascot[@name] = parseInt @value - MascotTools.change editMascot + $.on $('input', div), 'blur', saveVal when "select" optionHTML = "
#{item[0]}
#{item[0]}" - $.on $('input', div), 'click', -> - editMascot[@name] = if @checked then true else false - MascotTools.change editMascot + $.on $('input', div), 'click', saveCheck $.add container, div