Use better practices in my own code.
This commit is contained in:
parent
4410a8f118
commit
7a093b26ee
@ -11063,38 +11063,33 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
MascotTools = {
|
MascotTools = {
|
||||||
init: function(mascot) {
|
init: function() {
|
||||||
var el, image, name,
|
var _this = this;
|
||||||
_this = this;
|
|
||||||
|
|
||||||
if (!(mascot && mascot.image)) {
|
if (!Conf['Mascots'] || (g.VIEW === 'catalog' && Conf['Hide Mascots on Catalog'])) {
|
||||||
if (!Conf[g.MASCOTSTRING].length) {
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
name = Conf[g.MASCOTSTRING][Math.floor(Math.random() * Conf[g.MASCOTSTRING].length)];
|
|
||||||
mascot = Mascots[name];
|
|
||||||
Conf['mascot'] = name;
|
|
||||||
}
|
}
|
||||||
if (!this.el) {
|
if (Conf['Click to Toggle']) {
|
||||||
this.el = $.el('div', {
|
$.on(this.el, 'mousedown', MascotTools.click);
|
||||||
id: "mascot",
|
|
||||||
innerHTML: "<img>"
|
|
||||||
});
|
|
||||||
if (Conf['Click to Toggle']) {
|
|
||||||
$.on(this.el, 'mousedown', MascotTools.click);
|
|
||||||
}
|
|
||||||
$.on(doc, 'QRDialogCreation', MascotTools.reposition);
|
|
||||||
$.asap((function() {
|
|
||||||
return d.body;
|
|
||||||
}), function() {
|
|
||||||
return $.add(d.body, _this.el);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
$.on(doc, 'QRDialogCreation', MascotTools.reposition);
|
||||||
|
$.asap((function() {
|
||||||
|
return d.body;
|
||||||
|
}), function() {
|
||||||
|
return $.add(d.body, _this.el);
|
||||||
|
});
|
||||||
|
return MascotTools.toggle();
|
||||||
|
},
|
||||||
|
el: $.el('div', {
|
||||||
|
id: "mascot",
|
||||||
|
innerHTML: "<img>"
|
||||||
|
}),
|
||||||
|
change: function(mascot) {
|
||||||
|
var el, image;
|
||||||
|
|
||||||
el = this.el.firstElementChild;
|
el = this.el.firstElementChild;
|
||||||
if (!Conf['Mascots'] || (Conf['Hide Mascots on Catalog'] && g.VIEW === 'catalog')) {
|
if (!Conf['Mascots']) {
|
||||||
if (el) {
|
el.src = "";
|
||||||
el.src = "";
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Conf['Mascot Position'] === 'default') {
|
if (Conf['Mascot Position'] === 'default') {
|
||||||
@ -11112,21 +11107,29 @@
|
|||||||
} else if (!Conf['Silhouettize Mascots']) {
|
} else if (!Conf['Silhouettize Mascots']) {
|
||||||
$.rmClass(doc, 'silhouettize-mascots');
|
$.rmClass(doc, 'silhouettize-mascots');
|
||||||
}
|
}
|
||||||
if (!mascot) {
|
|
||||||
if (name && !(mascot = Mascots[name])) {
|
|
||||||
if (el) {
|
|
||||||
el.src = "";
|
|
||||||
} else {
|
|
||||||
null;
|
|
||||||
}
|
|
||||||
Conf[g.MASCOTSTRING].remove(name);
|
|
||||||
return MascotTools.init();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
image = Array.isArray(mascot.image) ? Style.lightTheme ? mascot.image[1] : mascot.image[0] : mascot.image;
|
image = Array.isArray(mascot.image) ? Style.lightTheme ? mascot.image[1] : mascot.image[0] : mascot.image;
|
||||||
el.src = image;
|
el.src = image;
|
||||||
return Style.mascot.textContent = "#mascot img {\nheight: " + (mascot.height && isNaN(parseFloat(mascot.height)) ? mascot.height : mascot.height ? parseInt(mascot.height, 10) + 'px' : 'auto') + ";\nwidth: " + (mascot.width && isNaN(parseFloat(mascot.width)) ? mascot.width : mascot.width ? parseInt(mascot.width, 10) + 'px' : 'auto') + ";\n}\n#mascot {\nmargin: " + (mascot.vOffset || 0) + "px " + (mascot.hOffset || 0) + "px;\n}\n.sidebar-large #mascot {\nleft: " + (mascot.center ? 25 : 0) + "px;\nright: " + (mascot.center ? 25 : 0) + "px;\n}\n.mascot-position-above-post-form.post-form-style-fixed #mascot {\ntransform: translateY(-" + (QR.nodes ? QR.nodes.el.getBoundingClientRect().height : 0) + "px);\n}";
|
return Style.mascot.textContent = "#mascot img {\nheight: " + (mascot.height && isNaN(parseFloat(mascot.height)) ? mascot.height : mascot.height ? parseInt(mascot.height, 10) + 'px' : 'auto') + ";\nwidth: " + (mascot.width && isNaN(parseFloat(mascot.width)) ? mascot.width : mascot.width ? parseInt(mascot.width, 10) + 'px' : 'auto') + ";\n}\n#mascot {\nmargin: " + (mascot.vOffset || 0) + "px " + (mascot.hOffset || 0) + "px;\n}\n.sidebar-large #mascot {\nleft: " + (mascot.center ? 25 : 0) + "px;\nright: " + (mascot.center ? 25 : 0) + "px;\n}\n.mascot-position-above-post-form.post-form-style-fixed #mascot {\ntransform: translateY(-" + (QR.nodes ? QR.nodes.el.getBoundingClientRect().height : 0) + "px);\n}";
|
||||||
},
|
},
|
||||||
|
toggle: function() {
|
||||||
|
var enabled, len, mascot, name, string;
|
||||||
|
|
||||||
|
string = g.MASCOTSTRING;
|
||||||
|
enabled = Conf[string];
|
||||||
|
if (!(len = enabled.length)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
name = enabled[Math.floor(Math.random() * len)];
|
||||||
|
if (!(mascot = Mascots[name])) {
|
||||||
|
enabled.remove(name);
|
||||||
|
if (el) {
|
||||||
|
el.src = "";
|
||||||
|
}
|
||||||
|
$.set(string, Conf[string] = enabled);
|
||||||
|
return MascotTools.toggle();
|
||||||
|
}
|
||||||
|
return MascotTools.change(mascot);
|
||||||
|
},
|
||||||
categories: ['Anime', 'Ponies', 'Questionable', 'Silhouette', 'Western'],
|
categories: ['Anime', 'Ponies', 'Questionable', 'Silhouette', 'Western'],
|
||||||
dialog: function(key) {
|
dialog: function(key) {
|
||||||
var container, dialog, div, fileInput, input, item, layout, name, option, optionHTML, setting, value, _i, _len, _ref;
|
var container, dialog, div, fileInput, input, item, layout, name, option, optionHTML, setting, value, _i, _len, _ref;
|
||||||
@ -11165,7 +11168,7 @@
|
|||||||
if (name === 'image') {
|
if (name === 'image') {
|
||||||
$.on(input, 'blur', function() {
|
$.on(input, 'blur', function() {
|
||||||
editMascot[this.name] = this.value;
|
editMascot[this.name] = this.value;
|
||||||
return MascotTools.init(editMascot);
|
return MascotTools.change(editMascot);
|
||||||
});
|
});
|
||||||
fileInput = $.el('input', {
|
fileInput = $.el('input', {
|
||||||
type: "file",
|
type: "file",
|
||||||
@ -11190,12 +11193,12 @@
|
|||||||
return alert("Mascot names must start with a letter.");
|
return alert("Mascot names must start with a letter.");
|
||||||
}
|
}
|
||||||
editMascot[this.name] = this.value;
|
editMascot[this.name] = this.value;
|
||||||
return MascotTools.init(editMascot);
|
return MascotTools.change(editMascot);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
$.on(input, 'blur', function() {
|
$.on(input, 'blur', function() {
|
||||||
editMascot[this.name] = this.value;
|
editMascot[this.name] = this.value;
|
||||||
return MascotTools.init(editMascot);
|
return MascotTools.change(editMascot);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -11203,7 +11206,7 @@
|
|||||||
div = this.input(item, name);
|
div = this.input(item, name);
|
||||||
$.on($('input', div), 'blur', function() {
|
$.on($('input', div), 'blur', function() {
|
||||||
editMascot[this.name] = parseInt(this.value);
|
editMascot[this.name] = parseInt(this.value);
|
||||||
return MascotTools.init(editMascot);
|
return MascotTools.change(editMascot);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "select":
|
case "select":
|
||||||
@ -11222,7 +11225,7 @@
|
|||||||
setting.value = value;
|
setting.value = value;
|
||||||
$.on($('select', div), 'change', function() {
|
$.on($('select', div), 'change', function() {
|
||||||
editMascot[this.name] = this.value;
|
editMascot[this.name] = this.value;
|
||||||
return MascotTools.init(editMascot);
|
return MascotTools.change(editMascot);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "checkbox":
|
case "checkbox":
|
||||||
@ -11232,12 +11235,12 @@
|
|||||||
});
|
});
|
||||||
$.on($('input', div), 'click', function() {
|
$.on($('input', div), 'click', function() {
|
||||||
editMascot[this.name] = this.checked ? true : false;
|
editMascot[this.name] = this.checked ? true : false;
|
||||||
return MascotTools.init(editMascot);
|
return MascotTools.change(editMascot);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
$.add(container, div);
|
$.add(container, div);
|
||||||
}
|
}
|
||||||
MascotTools.init(editMascot);
|
MascotTools.change(editMascot);
|
||||||
$.on($('#save > a', dialog), 'click', function() {
|
$.on($('#save > a', dialog), 'click', function() {
|
||||||
return MascotTools.save(editMascot);
|
return MascotTools.save(editMascot);
|
||||||
});
|
});
|
||||||
@ -11279,7 +11282,7 @@
|
|||||||
return reader.readAsDataURL(file);
|
return reader.readAsDataURL(file);
|
||||||
},
|
},
|
||||||
save: function(mascot) {
|
save: function(mascot) {
|
||||||
var image, name, type, _i, _len, _ref;
|
var image, name;
|
||||||
|
|
||||||
name = mascot.name, image = mascot.image;
|
name = mascot.name, image = mascot.image;
|
||||||
if ((name == null) || name === "") {
|
if ((name == null) || name === "") {
|
||||||
@ -11305,23 +11308,23 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ref = ["Enabled Mascots", "Enabled Mascots sfw", "Enabled Mascots nsfw"];
|
|
||||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
||||||
type = _ref[_i];
|
|
||||||
if (!Conf[type].contains(name)) {
|
|
||||||
Conf[type].push(name);
|
|
||||||
$.set(type, Conf[type]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Mascots[name] = JSON.parse(JSON.stringify(mascot));
|
Mascots[name] = JSON.parse(JSON.stringify(mascot));
|
||||||
Conf["mascot"] = name;
|
|
||||||
delete Mascots[name].name;
|
delete Mascots[name].name;
|
||||||
return $.get("userMascots", {}, function(item) {
|
return $.get("userMascots", {}, function(_arg) {
|
||||||
var userMascots;
|
var type, userMascots, _i, _len, _ref;
|
||||||
|
|
||||||
userMascots = item['userMascots'];
|
userMascots = _arg.userMascots;
|
||||||
userMascots[name] = Mascots[name];
|
userMascots[name] = Mascots[name];
|
||||||
$.set('userMascots', userMascots);
|
$.set('userMascots', userMascots);
|
||||||
|
Conf["mascot"] = name;
|
||||||
|
_ref = ["Enabled Mascots", "Enabled Mascots sfw", "Enabled Mascots nsfw"];
|
||||||
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||||
|
type = _ref[_i];
|
||||||
|
if (!Conf[type].contains(name)) {
|
||||||
|
Conf[type].push(name);
|
||||||
|
$.set(type, Conf[type]);
|
||||||
|
}
|
||||||
|
}
|
||||||
return alert("Mascot \"" + name + "\" saved.");
|
return alert("Mascot \"" + name + "\" saved.");
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -11330,7 +11333,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
return MascotTools.init();
|
return MascotTools.toggle();
|
||||||
},
|
},
|
||||||
close: function() {
|
close: function() {
|
||||||
Conf['editMode'] = false;
|
Conf['editMode'] = false;
|
||||||
@ -11537,7 +11540,6 @@
|
|||||||
$.addClass(doc, hyphenated);
|
$.addClass(doc, hyphenated);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MascotTools.init();
|
|
||||||
if (g.VIEW === 'index') {
|
if (g.VIEW === 'index') {
|
||||||
return $.asap((function() {
|
return $.asap((function() {
|
||||||
return $('.mPagelist');
|
return $('.mPagelist');
|
||||||
@ -14447,7 +14449,7 @@
|
|||||||
name = this.parentElement.parentElement.id;
|
name = this.parentElement.parentElement.id;
|
||||||
if (confirm("Are you sure you want to delete \"" + name + "\"?")) {
|
if (confirm("Are you sure you want to delete \"" + name + "\"?")) {
|
||||||
if (Conf['mascot'] === name) {
|
if (Conf['mascot'] === name) {
|
||||||
MascotTools.init();
|
MascotTools.toggle();
|
||||||
}
|
}
|
||||||
_ref = ["Enabled Mascots", "Enabled Mascots sfw", "Enabled Mascots nsfw"];
|
_ref = ["Enabled Mascots", "Enabled Mascots sfw", "Enabled Mascots nsfw"];
|
||||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||||
@ -14489,12 +14491,12 @@
|
|||||||
select: function() {
|
select: function() {
|
||||||
if (Conf[g.MASCOTSTRING].remove(this.id)) {
|
if (Conf[g.MASCOTSTRING].remove(this.id)) {
|
||||||
if (Conf['mascot'] === this.id) {
|
if (Conf['mascot'] === this.id) {
|
||||||
MascotTools.init();
|
MascotTools.toggle();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Conf['mascot'] = this.id;
|
Conf['mascot'] = this.id;
|
||||||
Conf[g.MASCOTSTRING].push(this.id);
|
Conf[g.MASCOTSTRING].push(this.id);
|
||||||
MascotTools.init(Mascots[this.id]);
|
MascotTools.change(Mascots[this.id]);
|
||||||
}
|
}
|
||||||
$.toggleClass(this, 'enabled');
|
$.toggleClass(this, 'enabled');
|
||||||
return $.set(g.MASCOTSTRING, Conf[g.MASCOTSTRING]);
|
return $.set(g.MASCOTSTRING, Conf[g.MASCOTSTRING]);
|
||||||
@ -14714,6 +14716,7 @@
|
|||||||
'Polyfill': Polyfill,
|
'Polyfill': Polyfill,
|
||||||
'Emoji': Emoji,
|
'Emoji': Emoji,
|
||||||
'Style': Style,
|
'Style': Style,
|
||||||
|
'Mascots': MascotTools,
|
||||||
'Rice': Rice,
|
'Rice': Rice,
|
||||||
'Banner': Banner,
|
'Banner': Banner,
|
||||||
'Announcements': GlobalMessage,
|
'Announcements': GlobalMessage,
|
||||||
|
|||||||
@ -11050,38 +11050,33 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
MascotTools = {
|
MascotTools = {
|
||||||
init: function(mascot) {
|
init: function() {
|
||||||
var el, image, name,
|
var _this = this;
|
||||||
_this = this;
|
|
||||||
|
|
||||||
if (!(mascot && mascot.image)) {
|
if (!Conf['Mascots'] || (g.VIEW === 'catalog' && Conf['Hide Mascots on Catalog'])) {
|
||||||
if (!Conf[g.MASCOTSTRING].length) {
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
name = Conf[g.MASCOTSTRING][Math.floor(Math.random() * Conf[g.MASCOTSTRING].length)];
|
|
||||||
mascot = Mascots[name];
|
|
||||||
Conf['mascot'] = name;
|
|
||||||
}
|
}
|
||||||
if (!this.el) {
|
if (Conf['Click to Toggle']) {
|
||||||
this.el = $.el('div', {
|
$.on(this.el, 'mousedown', MascotTools.click);
|
||||||
id: "mascot",
|
|
||||||
innerHTML: "<img>"
|
|
||||||
});
|
|
||||||
if (Conf['Click to Toggle']) {
|
|
||||||
$.on(this.el, 'mousedown', MascotTools.click);
|
|
||||||
}
|
|
||||||
$.on(doc, 'QRDialogCreation', MascotTools.reposition);
|
|
||||||
$.asap((function() {
|
|
||||||
return d.body;
|
|
||||||
}), function() {
|
|
||||||
return $.add(d.body, _this.el);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
$.on(doc, 'QRDialogCreation', MascotTools.reposition);
|
||||||
|
$.asap((function() {
|
||||||
|
return d.body;
|
||||||
|
}), function() {
|
||||||
|
return $.add(d.body, _this.el);
|
||||||
|
});
|
||||||
|
return MascotTools.toggle();
|
||||||
|
},
|
||||||
|
el: $.el('div', {
|
||||||
|
id: "mascot",
|
||||||
|
innerHTML: "<img>"
|
||||||
|
}),
|
||||||
|
change: function(mascot) {
|
||||||
|
var el, image;
|
||||||
|
|
||||||
el = this.el.firstElementChild;
|
el = this.el.firstElementChild;
|
||||||
if (!Conf['Mascots'] || (Conf['Hide Mascots on Catalog'] && g.VIEW === 'catalog')) {
|
if (!Conf['Mascots']) {
|
||||||
if (el) {
|
el.src = "";
|
||||||
el.src = "";
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Conf['Mascot Position'] === 'default') {
|
if (Conf['Mascot Position'] === 'default') {
|
||||||
@ -11099,21 +11094,29 @@
|
|||||||
} else if (!Conf['Silhouettize Mascots']) {
|
} else if (!Conf['Silhouettize Mascots']) {
|
||||||
$.rmClass(doc, 'silhouettize-mascots');
|
$.rmClass(doc, 'silhouettize-mascots');
|
||||||
}
|
}
|
||||||
if (!mascot) {
|
|
||||||
if (name && !(mascot = Mascots[name])) {
|
|
||||||
if (el) {
|
|
||||||
el.src = "";
|
|
||||||
} else {
|
|
||||||
null;
|
|
||||||
}
|
|
||||||
Conf[g.MASCOTSTRING].remove(name);
|
|
||||||
return MascotTools.init();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
image = Array.isArray(mascot.image) ? Style.lightTheme ? mascot.image[1] : mascot.image[0] : mascot.image;
|
image = Array.isArray(mascot.image) ? Style.lightTheme ? mascot.image[1] : mascot.image[0] : mascot.image;
|
||||||
el.src = image;
|
el.src = image;
|
||||||
return Style.mascot.textContent = "#mascot img {\nheight: " + (mascot.height && isNaN(parseFloat(mascot.height)) ? mascot.height : mascot.height ? parseInt(mascot.height, 10) + 'px' : 'auto') + ";\nwidth: " + (mascot.width && isNaN(parseFloat(mascot.width)) ? mascot.width : mascot.width ? parseInt(mascot.width, 10) + 'px' : 'auto') + ";\n}\n#mascot {\nmargin: " + (mascot.vOffset || 0) + "px " + (mascot.hOffset || 0) + "px;\n}\n.sidebar-large #mascot {\nleft: " + (mascot.center ? 25 : 0) + "px;\nright: " + (mascot.center ? 25 : 0) + "px;\n}\n.mascot-position-above-post-form.post-form-style-fixed #mascot {\n-webkit-transform: translateY(-" + (QR.nodes ? QR.nodes.el.getBoundingClientRect().height : 0) + "px);\n}";
|
return Style.mascot.textContent = "#mascot img {\nheight: " + (mascot.height && isNaN(parseFloat(mascot.height)) ? mascot.height : mascot.height ? parseInt(mascot.height, 10) + 'px' : 'auto') + ";\nwidth: " + (mascot.width && isNaN(parseFloat(mascot.width)) ? mascot.width : mascot.width ? parseInt(mascot.width, 10) + 'px' : 'auto') + ";\n}\n#mascot {\nmargin: " + (mascot.vOffset || 0) + "px " + (mascot.hOffset || 0) + "px;\n}\n.sidebar-large #mascot {\nleft: " + (mascot.center ? 25 : 0) + "px;\nright: " + (mascot.center ? 25 : 0) + "px;\n}\n.mascot-position-above-post-form.post-form-style-fixed #mascot {\n-webkit-transform: translateY(-" + (QR.nodes ? QR.nodes.el.getBoundingClientRect().height : 0) + "px);\n}";
|
||||||
},
|
},
|
||||||
|
toggle: function() {
|
||||||
|
var enabled, len, mascot, name, string;
|
||||||
|
|
||||||
|
string = g.MASCOTSTRING;
|
||||||
|
enabled = Conf[string];
|
||||||
|
if (!(len = enabled.length)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
name = enabled[Math.floor(Math.random() * len)];
|
||||||
|
if (!(mascot = Mascots[name])) {
|
||||||
|
enabled.remove(name);
|
||||||
|
if (el) {
|
||||||
|
el.src = "";
|
||||||
|
}
|
||||||
|
$.set(string, Conf[string] = enabled);
|
||||||
|
return MascotTools.toggle();
|
||||||
|
}
|
||||||
|
return MascotTools.change(mascot);
|
||||||
|
},
|
||||||
categories: ['Anime', 'Ponies', 'Questionable', 'Silhouette', 'Western'],
|
categories: ['Anime', 'Ponies', 'Questionable', 'Silhouette', 'Western'],
|
||||||
dialog: function(key) {
|
dialog: function(key) {
|
||||||
var container, dialog, div, fileInput, input, item, layout, name, option, optionHTML, setting, value, _i, _len, _ref;
|
var container, dialog, div, fileInput, input, item, layout, name, option, optionHTML, setting, value, _i, _len, _ref;
|
||||||
@ -11152,7 +11155,7 @@
|
|||||||
if (name === 'image') {
|
if (name === 'image') {
|
||||||
$.on(input, 'blur', function() {
|
$.on(input, 'blur', function() {
|
||||||
editMascot[this.name] = this.value;
|
editMascot[this.name] = this.value;
|
||||||
return MascotTools.init(editMascot);
|
return MascotTools.change(editMascot);
|
||||||
});
|
});
|
||||||
fileInput = $.el('input', {
|
fileInput = $.el('input', {
|
||||||
type: "file",
|
type: "file",
|
||||||
@ -11177,12 +11180,12 @@
|
|||||||
return alert("Mascot names must start with a letter.");
|
return alert("Mascot names must start with a letter.");
|
||||||
}
|
}
|
||||||
editMascot[this.name] = this.value;
|
editMascot[this.name] = this.value;
|
||||||
return MascotTools.init(editMascot);
|
return MascotTools.change(editMascot);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
$.on(input, 'blur', function() {
|
$.on(input, 'blur', function() {
|
||||||
editMascot[this.name] = this.value;
|
editMascot[this.name] = this.value;
|
||||||
return MascotTools.init(editMascot);
|
return MascotTools.change(editMascot);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -11190,7 +11193,7 @@
|
|||||||
div = this.input(item, name);
|
div = this.input(item, name);
|
||||||
$.on($('input', div), 'blur', function() {
|
$.on($('input', div), 'blur', function() {
|
||||||
editMascot[this.name] = parseInt(this.value);
|
editMascot[this.name] = parseInt(this.value);
|
||||||
return MascotTools.init(editMascot);
|
return MascotTools.change(editMascot);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "select":
|
case "select":
|
||||||
@ -11209,7 +11212,7 @@
|
|||||||
setting.value = value;
|
setting.value = value;
|
||||||
$.on($('select', div), 'change', function() {
|
$.on($('select', div), 'change', function() {
|
||||||
editMascot[this.name] = this.value;
|
editMascot[this.name] = this.value;
|
||||||
return MascotTools.init(editMascot);
|
return MascotTools.change(editMascot);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "checkbox":
|
case "checkbox":
|
||||||
@ -11219,12 +11222,12 @@
|
|||||||
});
|
});
|
||||||
$.on($('input', div), 'click', function() {
|
$.on($('input', div), 'click', function() {
|
||||||
editMascot[this.name] = this.checked ? true : false;
|
editMascot[this.name] = this.checked ? true : false;
|
||||||
return MascotTools.init(editMascot);
|
return MascotTools.change(editMascot);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
$.add(container, div);
|
$.add(container, div);
|
||||||
}
|
}
|
||||||
MascotTools.init(editMascot);
|
MascotTools.change(editMascot);
|
||||||
$.on($('#save > a', dialog), 'click', function() {
|
$.on($('#save > a', dialog), 'click', function() {
|
||||||
return MascotTools.save(editMascot);
|
return MascotTools.save(editMascot);
|
||||||
});
|
});
|
||||||
@ -11266,7 +11269,7 @@
|
|||||||
return reader.readAsDataURL(file);
|
return reader.readAsDataURL(file);
|
||||||
},
|
},
|
||||||
save: function(mascot) {
|
save: function(mascot) {
|
||||||
var image, name, type, _i, _len, _ref;
|
var image, name;
|
||||||
|
|
||||||
name = mascot.name, image = mascot.image;
|
name = mascot.name, image = mascot.image;
|
||||||
if ((name == null) || name === "") {
|
if ((name == null) || name === "") {
|
||||||
@ -11292,23 +11295,23 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ref = ["Enabled Mascots", "Enabled Mascots sfw", "Enabled Mascots nsfw"];
|
|
||||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
||||||
type = _ref[_i];
|
|
||||||
if (!Conf[type].contains(name)) {
|
|
||||||
Conf[type].push(name);
|
|
||||||
$.set(type, Conf[type]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Mascots[name] = JSON.parse(JSON.stringify(mascot));
|
Mascots[name] = JSON.parse(JSON.stringify(mascot));
|
||||||
Conf["mascot"] = name;
|
|
||||||
delete Mascots[name].name;
|
delete Mascots[name].name;
|
||||||
return $.get("userMascots", {}, function(item) {
|
return $.get("userMascots", {}, function(_arg) {
|
||||||
var userMascots;
|
var type, userMascots, _i, _len, _ref;
|
||||||
|
|
||||||
userMascots = item['userMascots'];
|
userMascots = _arg.userMascots;
|
||||||
userMascots[name] = Mascots[name];
|
userMascots[name] = Mascots[name];
|
||||||
$.set('userMascots', userMascots);
|
$.set('userMascots', userMascots);
|
||||||
|
Conf["mascot"] = name;
|
||||||
|
_ref = ["Enabled Mascots", "Enabled Mascots sfw", "Enabled Mascots nsfw"];
|
||||||
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||||
|
type = _ref[_i];
|
||||||
|
if (!Conf[type].contains(name)) {
|
||||||
|
Conf[type].push(name);
|
||||||
|
$.set(type, Conf[type]);
|
||||||
|
}
|
||||||
|
}
|
||||||
return alert("Mascot \"" + name + "\" saved.");
|
return alert("Mascot \"" + name + "\" saved.");
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -11317,7 +11320,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
return MascotTools.init();
|
return MascotTools.toggle();
|
||||||
},
|
},
|
||||||
close: function() {
|
close: function() {
|
||||||
Conf['editMode'] = false;
|
Conf['editMode'] = false;
|
||||||
@ -11524,7 +11527,6 @@
|
|||||||
$.addClass(doc, hyphenated);
|
$.addClass(doc, hyphenated);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MascotTools.init();
|
|
||||||
if (g.VIEW === 'index') {
|
if (g.VIEW === 'index') {
|
||||||
return $.asap((function() {
|
return $.asap((function() {
|
||||||
return $('.mPagelist');
|
return $('.mPagelist');
|
||||||
@ -14432,7 +14434,7 @@
|
|||||||
name = this.parentElement.parentElement.id;
|
name = this.parentElement.parentElement.id;
|
||||||
if (confirm("Are you sure you want to delete \"" + name + "\"?")) {
|
if (confirm("Are you sure you want to delete \"" + name + "\"?")) {
|
||||||
if (Conf['mascot'] === name) {
|
if (Conf['mascot'] === name) {
|
||||||
MascotTools.init();
|
MascotTools.toggle();
|
||||||
}
|
}
|
||||||
_ref = ["Enabled Mascots", "Enabled Mascots sfw", "Enabled Mascots nsfw"];
|
_ref = ["Enabled Mascots", "Enabled Mascots sfw", "Enabled Mascots nsfw"];
|
||||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||||
@ -14471,12 +14473,12 @@
|
|||||||
select: function() {
|
select: function() {
|
||||||
if (Conf[g.MASCOTSTRING].remove(this.id)) {
|
if (Conf[g.MASCOTSTRING].remove(this.id)) {
|
||||||
if (Conf['mascot'] === this.id) {
|
if (Conf['mascot'] === this.id) {
|
||||||
MascotTools.init();
|
MascotTools.toggle();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Conf['mascot'] = this.id;
|
Conf['mascot'] = this.id;
|
||||||
Conf[g.MASCOTSTRING].push(this.id);
|
Conf[g.MASCOTSTRING].push(this.id);
|
||||||
MascotTools.init(Mascots[this.id]);
|
MascotTools.change(Mascots[this.id]);
|
||||||
}
|
}
|
||||||
$.toggleClass(this, 'enabled');
|
$.toggleClass(this, 'enabled');
|
||||||
return $.set(g.MASCOTSTRING, Conf[g.MASCOTSTRING]);
|
return $.set(g.MASCOTSTRING, Conf[g.MASCOTSTRING]);
|
||||||
@ -14693,6 +14695,7 @@
|
|||||||
'Polyfill': Polyfill,
|
'Polyfill': Polyfill,
|
||||||
'Emoji': Emoji,
|
'Emoji': Emoji,
|
||||||
'Style': Style,
|
'Style': Style,
|
||||||
|
'Mascots': MascotTools,
|
||||||
'Rice': Rice,
|
'Rice': Rice,
|
||||||
'Banner': Banner,
|
'Banner': Banner,
|
||||||
'Announcements': GlobalMessage,
|
'Announcements': GlobalMessage,
|
||||||
|
|||||||
@ -108,6 +108,7 @@ Main =
|
|||||||
'Polyfill': Polyfill
|
'Polyfill': Polyfill
|
||||||
'Emoji': Emoji
|
'Emoji': Emoji
|
||||||
'Style': Style
|
'Style': Style
|
||||||
|
'Mascots': MascotTools
|
||||||
'Rice': Rice
|
'Rice': Rice
|
||||||
'Banner': Banner
|
'Banner': Banner
|
||||||
'Announcements': GlobalMessage
|
'Announcements': GlobalMessage
|
||||||
|
|||||||
@ -830,7 +830,7 @@ Settings =
|
|||||||
name = @parentElement.parentElement.id
|
name = @parentElement.parentElement.id
|
||||||
if confirm "Are you sure you want to delete \"#{name}\"?"
|
if confirm "Are you sure you want to delete \"#{name}\"?"
|
||||||
if Conf['mascot'] is name
|
if Conf['mascot'] is name
|
||||||
MascotTools.init()
|
MascotTools.toggle()
|
||||||
for type in ["Enabled Mascots", "Enabled Mascots sfw", "Enabled Mascots nsfw"]
|
for type in ["Enabled Mascots", "Enabled Mascots sfw", "Enabled Mascots nsfw"]
|
||||||
Conf[type].remove name
|
Conf[type].remove name
|
||||||
$.set type, Conf[type]
|
$.set type, Conf[type]
|
||||||
@ -868,11 +868,11 @@ Settings =
|
|||||||
select: ->
|
select: ->
|
||||||
if Conf[g.MASCOTSTRING].remove @id
|
if Conf[g.MASCOTSTRING].remove @id
|
||||||
if Conf['mascot'] is @id
|
if Conf['mascot'] is @id
|
||||||
MascotTools.init()
|
MascotTools.toggle()
|
||||||
else
|
else
|
||||||
Conf['mascot'] = @id
|
Conf['mascot'] = @id
|
||||||
Conf[g.MASCOTSTRING].push @id
|
Conf[g.MASCOTSTRING].push @id
|
||||||
MascotTools.init Mascots[@id]
|
MascotTools.change Mascots[@id]
|
||||||
$.toggleClass @, 'enabled'
|
$.toggleClass @, 'enabled'
|
||||||
$.set g.MASCOTSTRING, Conf[g.MASCOTSTRING]
|
$.set g.MASCOTSTRING, Conf[g.MASCOTSTRING]
|
||||||
|
|
||||||
|
|||||||
@ -1,28 +1,26 @@
|
|||||||
MascotTools =
|
MascotTools =
|
||||||
init: (mascot) ->
|
init: ->
|
||||||
unless mascot and mascot.image
|
return if !Conf['Mascots'] or (g.VIEW is 'catalog' and Conf['Hide Mascots on Catalog'])
|
||||||
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
|
if Conf['Click to Toggle']
|
||||||
@el = $.el 'div',
|
$.on @el, 'mousedown', MascotTools.click
|
||||||
id: "mascot"
|
|
||||||
innerHTML: "<img>"
|
|
||||||
|
|
||||||
if Conf['Click to Toggle']
|
$.on doc, 'QRDialogCreation', MascotTools.reposition
|
||||||
$.on @el, 'mousedown', MascotTools.click
|
|
||||||
|
|
||||||
$.on doc, 'QRDialogCreation', MascotTools.reposition
|
$.asap (-> d.body), =>
|
||||||
|
$.add d.body, @el
|
||||||
|
|
||||||
$.asap (-> d.body), =>
|
MascotTools.toggle()
|
||||||
$.add d.body, @el
|
|
||||||
|
|
||||||
|
el: $.el 'div',
|
||||||
|
id: "mascot"
|
||||||
|
innerHTML: "<img>"
|
||||||
|
|
||||||
|
change: (mascot) ->
|
||||||
el = @el.firstElementChild
|
el = @el.firstElementChild
|
||||||
|
|
||||||
if !Conf['Mascots'] or (Conf['Hide Mascots on Catalog'] and g.VIEW is 'catalog')
|
if !Conf['Mascots']
|
||||||
if el then el.src = ""
|
el.src = ""
|
||||||
return
|
return
|
||||||
|
|
||||||
if Conf['Mascot Position'] is 'default'
|
if Conf['Mascot Position'] is 'default'
|
||||||
@ -39,24 +37,34 @@ MascotTools =
|
|||||||
else unless Conf['Silhouettize Mascots']
|
else unless Conf['Silhouettize Mascots']
|
||||||
$.rmClass doc, 'silhouettize-mascots'
|
$.rmClass doc, 'silhouettize-mascots'
|
||||||
|
|
||||||
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 =
|
image =
|
||||||
if Array.isArray mascot.image
|
if Array.isArray mascot.image
|
||||||
if Style.lightTheme
|
if Style.lightTheme
|
||||||
mascot.image[1]
|
mascot.image[1]
|
||||||
else
|
else
|
||||||
mascot.image[0]
|
mascot.image[0]
|
||||||
else mascot.image
|
else
|
||||||
|
mascot.image
|
||||||
|
|
||||||
el.src = image
|
el.src = image
|
||||||
|
|
||||||
Style.mascot.textContent = """<%= grunt.file.read('src/General/css/mascot.css') %>"""
|
Style.mascot.textContent = """<%= grunt.file.read('src/General/css/mascot.css') %>"""
|
||||||
|
|
||||||
|
toggle: ->
|
||||||
|
string = g.MASCOTSTRING
|
||||||
|
enabled = Conf[string]
|
||||||
|
return unless len = enabled.length
|
||||||
|
|
||||||
|
name = enabled[Math.floor(Math.random() * len)]
|
||||||
|
|
||||||
|
unless mascot = Mascots[name]
|
||||||
|
enabled.remove name
|
||||||
|
el.src = "" if el
|
||||||
|
$.set string, Conf[string] = enabled
|
||||||
|
return MascotTools.toggle()
|
||||||
|
|
||||||
|
MascotTools.change mascot
|
||||||
|
|
||||||
categories: [
|
categories: [
|
||||||
'Anime'
|
'Anime'
|
||||||
'Ponies'
|
'Ponies'
|
||||||
@ -140,7 +148,7 @@ MascotTools =
|
|||||||
if name is 'image'
|
if name is 'image'
|
||||||
$.on input, 'blur', ->
|
$.on input, 'blur', ->
|
||||||
editMascot[@name] = @value
|
editMascot[@name] = @value
|
||||||
MascotTools.init editMascot
|
MascotTools.change editMascot
|
||||||
|
|
||||||
fileInput = $.el 'input',
|
fileInput = $.el 'input',
|
||||||
type: "file"
|
type: "file"
|
||||||
@ -164,19 +172,19 @@ MascotTools =
|
|||||||
if (@value isnt "") and !/^[a-z]/i.test @value
|
if (@value isnt "") and !/^[a-z]/i.test @value
|
||||||
return alert "Mascot names must start with a letter."
|
return alert "Mascot names must start with a letter."
|
||||||
editMascot[@name] = @value
|
editMascot[@name] = @value
|
||||||
MascotTools.init editMascot
|
MascotTools.change editMascot
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
$.on input, 'blur', ->
|
$.on input, 'blur', ->
|
||||||
editMascot[@name] = @value
|
editMascot[@name] = @value
|
||||||
MascotTools.init editMascot
|
MascotTools.change editMascot
|
||||||
|
|
||||||
when "number"
|
when "number"
|
||||||
div = @input item, name
|
div = @input item, name
|
||||||
$.on $('input', div), 'blur', ->
|
$.on $('input', div), 'blur', ->
|
||||||
editMascot[@name] = parseInt @value
|
editMascot[@name] = parseInt @value
|
||||||
MascotTools.init editMascot
|
MascotTools.change editMascot
|
||||||
|
|
||||||
when "select"
|
when "select"
|
||||||
optionHTML = "<div class=optionlabel>#{item[0]}</div><div class=option><select name='#{name}' value='#{value}'><br>"
|
optionHTML = "<div class=optionlabel>#{item[0]}</div><div class=option><select name='#{name}' value='#{value}'><br>"
|
||||||
@ -191,7 +199,7 @@ MascotTools =
|
|||||||
|
|
||||||
$.on $('select', div), 'change', ->
|
$.on $('select', div), 'change', ->
|
||||||
editMascot[@name] = @value
|
editMascot[@name] = @value
|
||||||
MascotTools.init editMascot
|
MascotTools.change editMascot
|
||||||
|
|
||||||
when "checkbox"
|
when "checkbox"
|
||||||
div = $.el "div",
|
div = $.el "div",
|
||||||
@ -199,11 +207,11 @@ MascotTools =
|
|||||||
innerHTML: "<label><input type=#{item[2]} class=field name='#{name}' #{if value then 'checked'}>#{item[0]}</label>"
|
innerHTML: "<label><input type=#{item[2]} class=field name='#{name}' #{if value then 'checked'}>#{item[0]}</label>"
|
||||||
$.on $('input', div), 'click', ->
|
$.on $('input', div), 'click', ->
|
||||||
editMascot[@name] = if @checked then true else false
|
editMascot[@name] = if @checked then true else false
|
||||||
MascotTools.init editMascot
|
MascotTools.change editMascot
|
||||||
|
|
||||||
$.add container, div
|
$.add container, div
|
||||||
|
|
||||||
MascotTools.init editMascot
|
MascotTools.change editMascot
|
||||||
|
|
||||||
$.on $('#save > a', dialog), 'click', ->
|
$.on $('#save > a', dialog), 'click', ->
|
||||||
MascotTools.save editMascot
|
MascotTools.save editMascot
|
||||||
@ -266,23 +274,25 @@ MascotTools =
|
|||||||
else
|
else
|
||||||
return alert "Creation of \"#{name}\" aborted."
|
return alert "Creation of \"#{name}\" aborted."
|
||||||
|
|
||||||
for type in ["Enabled Mascots", "Enabled Mascots sfw", "Enabled Mascots nsfw"]
|
Mascots[name] = JSON.parse JSON.stringify mascot
|
||||||
unless Conf[type].contains name
|
|
||||||
Conf[type].push name
|
|
||||||
$.set type, Conf[type]
|
|
||||||
Mascots[name] = JSON.parse(JSON.stringify(mascot))
|
|
||||||
Conf["mascot"] = name
|
|
||||||
delete Mascots[name].name
|
delete Mascots[name].name
|
||||||
$.get "userMascots", {}, (item) ->
|
|
||||||
userMascots = item['userMascots']
|
$.get "userMascots", {}, ({userMascots}) ->
|
||||||
userMascots[name] = Mascots[name]
|
userMascots[name] = Mascots[name]
|
||||||
$.set 'userMascots', userMascots
|
$.set 'userMascots', userMascots
|
||||||
|
|
||||||
|
Conf["mascot"] = name
|
||||||
|
|
||||||
|
for type in ["Enabled Mascots", "Enabled Mascots sfw", "Enabled Mascots nsfw"]
|
||||||
|
unless Conf[type].contains name
|
||||||
|
Conf[type].push name
|
||||||
|
$.set type, Conf[type]
|
||||||
alert "Mascot \"#{name}\" saved."
|
alert "Mascot \"#{name}\" saved."
|
||||||
|
|
||||||
click: (e) ->
|
click: (e) ->
|
||||||
return if e.button isnt 0 # not LMB
|
return if e.button isnt 0 # not LMB
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
MascotTools.init()
|
MascotTools.toggle()
|
||||||
|
|
||||||
close: ->
|
close: ->
|
||||||
Conf['editMode'] = false
|
Conf['editMode'] = false
|
||||||
|
|||||||
@ -23,8 +23,6 @@ Style =
|
|||||||
hyphenated = "#{name}#{if setting[2] then " #{Conf[name]}" else ""}".toLowerCase().replace(/^4/, 'four').replace /\s+/g, '-'
|
hyphenated = "#{name}#{if setting[2] then " #{Conf[name]}" else ""}".toLowerCase().replace(/^4/, 'four').replace /\s+/g, '-'
|
||||||
$.addClass doc, hyphenated
|
$.addClass doc, hyphenated
|
||||||
|
|
||||||
MascotTools.init()
|
|
||||||
|
|
||||||
if g.VIEW is 'index'
|
if g.VIEW is 'index'
|
||||||
$.asap (-> $ '.mPagelist'), ->
|
$.asap (-> $ '.mPagelist'), ->
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user