[ESLint] Fix style complaints

This commit is contained in:
Sindrake 2024-07-17 14:22:24 -07:00
parent 82891b91d1
commit 6cbe400cc5
37 changed files with 1103 additions and 1093 deletions

View File

@ -12,6 +12,7 @@
"editor.detectIndentation": false, "editor.detectIndentation": false,
"editor.tabSize": 2, "editor.tabSize": 2,
"editor.insertSpaces": true, "editor.insertSpaces": true,
"editor.rulers": [100],
"editor.formatOnSave": false, "editor.formatOnSave": false,
// Eslint shenanigans // Eslint shenanigans

View File

@ -1,28 +1,26 @@
import Utility from './utility'; import Utility from "./utility";
import { SendQueue } from './send_queue'; import { SendQueue } from "./send_queue";
const Artist = {}; const Artist = {};
Artist.update = function (id, params) { Artist.update = function (id, params) {
SendQueue.add(function() { SendQueue.add(() => {
$.ajax({ $.ajax({
type: "PUT", type: "PUT",
url: "/artists/" + id + ".json", url: "/artists/" + id + ".json",
data: params, data: params,
success: function() { success: () => { Utility.notice("Artist updated."); },
Utility.notice("Artist updated."); error: () => {
},
error: function() {
Utility.error(`There was an error updating <a href="/artists/${id}">artist #${id}</a>`); Utility.error(`There was an error updating <a href="/artists/${id}">artist #${id}</a>`);
} },
}); });
}); });
}; };
function init() { function init () {
$("#undelete-artist-link").on('click', e => { $("#undelete-artist-link").on("click", e => {
if (confirm("Are you sure you want to undelete this artist?")) if (confirm("Are you sure you want to undelete this artist?"))
Artist.update($(e.target).data('aid'), {"artist[is_active]": true}); Artist.update($(e.target).data("aid"), {"artist[is_active]": true});
e.preventDefault(); e.preventDefault();
}); });
} }

View File

@ -1,6 +1,6 @@
import Utility from './utility' import Utility from "./utility";
import LS from './local_storage' import LS from "./local_storage";
import Post from './posts'; import Post from "./posts";
let Blacklist = {}; let Blacklist = {};
@ -36,16 +36,16 @@ Blacklist.lineSet = function (line, enabled) {
}; };
Blacklist.entryParse = function (string) { Blacklist.entryParse = function (string) {
const fixInsanity = function(input) { const fixInsanity = function (input) {
switch(input) { switch (input) {
case '=>': case "=>":
return '>='; return ">=";
case '=<': case "=<":
return '<='; return "<=";
case '=': case "=":
return '=='; return "==";
case '': case "":
return '=='; return "==";
default: default:
return input; return input;
} }
@ -59,13 +59,13 @@ Blacklist.entryParse = function (string) {
"hits": 0, "hits": 0,
"score_comparison": null, "score_comparison": null,
"username": false, "username": false,
"user_id": 0 "user_id": 0,
}; };
const matches = string.match(/\S+/g) || []; const matches = string.match(/\S+/g) || [];
for (const tag of matches) { for (const tag of matches) {
if (tag.charAt(0) === '-') { if (tag.charAt(0) === "-") {
entry.exclude.push(tag.slice(1)); entry.exclude.push(tag.slice(1));
} else if (tag.charAt(0) === '~') { } else if (tag.charAt(0) === "~") {
entry.optional.push(tag.slice(1)); entry.optional.push(tag.slice(1));
} else if (tag.match(/^score:[<=>]{0,2}-?\d+/)) { } else if (tag.match(/^score:[<=>]{0,2}-?\d+/)) {
const score = tag.match(/^score:([<=>]{0,2})(-?\d+)/); const score = tag.match(/^score:([<=>]{0,2})(-?\d+)/);
@ -166,7 +166,7 @@ Blacklist.sidebarUpdate = function () {
$("#blacklist-box").show(); $("#blacklist-box").show();
} };
Blacklist.initialize_disable_all_blacklists = function () { Blacklist.initialize_disable_all_blacklists = function () {
if (LS.get("dab") === "1") { if (LS.get("dab") === "1") {
@ -184,7 +184,7 @@ Blacklist.initialize_disable_all_blacklists = function () {
Blacklist.entriesAllSet(true); Blacklist.entriesAllSet(true);
Blacklist.apply(); Blacklist.apply();
}); });
} };
Blacklist.apply = function () { Blacklist.apply = function () {
Blacklist.post_count = 0; Blacklist.post_count = 0;
@ -220,25 +220,25 @@ Blacklist.apply = function () {
} }
Blacklist.sidebarUpdate(); Blacklist.sidebarUpdate();
} };
Blacklist.posts = function () { Blacklist.posts = function () {
return $(".post-preview, #image-container, #c-comments .post, .post-thumbnail"); return $(".post-preview, #image-container, #c-comments .post, .post-thumbnail");
} };
Blacklist.postMatch = function (post, entry) { Blacklist.postMatch = function (post, entry) {
const $post = $(post); const $post = $(post);
if ($post.hasClass('post-no-blacklist')) if ($post.hasClass("post-no-blacklist"))
return false; return false;
let post_data = { let post_data = {
id: $post.data('id'), id: $post.data("id"),
score: parseInt($post.data('score'), 10), score: parseInt($post.data("score"), 10),
tags: $post.data('tags').toString(), tags: $post.data("tags").toString(),
rating: $post.data('rating'), rating: $post.data("rating"),
uploader_id: $post.data('uploader-id'), uploader_id: $post.data("uploader-id"),
user: $post.data('uploader').toString().toLowerCase(), user: $post.data("uploader").toString().toLowerCase(),
flags: $post.data('flags'), flags: $post.data("flags"),
is_fav: $post.data('is-favorited') is_fav: $post.data("is-favorited"),
}; };
return Blacklist.postMatchObject(post_data, entry); return Blacklist.postMatchObject(post_data, entry);
}; };
@ -246,18 +246,18 @@ Blacklist.postMatch = function (post, entry) {
Blacklist.postMatchObject = function (post, entry) { Blacklist.postMatchObject = function (post, entry) {
const rangeComparator = function (comparison, target) { const rangeComparator = function (comparison, target) {
// Bad comparison, post matches score. // Bad comparison, post matches score.
if (!Array.isArray(comparison) || typeof target === 'undefined' || comparison.length !== 2) if (!Array.isArray(comparison) || typeof target === "undefined" || comparison.length !== 2)
return true; return true;
switch (comparison[0]) { switch (comparison[0]) {
case '<': case "<":
return target < comparison[1]; return target < comparison[1];
case '<=': case "<=":
return target <= comparison[1]; return target <= comparison[1];
case '==': case "==":
return target == comparison[1]; return target == comparison[1];
case '>=': case ">=":
return target >= comparison[1]; return target >= comparison[1];
case '>': case ">":
return target > comparison[1]; return target > comparison[1];
default: default:
return true; return true;
@ -272,8 +272,8 @@ Blacklist.postMatchObject = function (post, entry) {
tags.push(`user:${post.user}`); tags.push(`user:${post.user}`);
tags.push(`height:${post.height}`); tags.push(`height:${post.height}`);
tags.push(`width:${post.width}`); tags.push(`width:${post.width}`);
if(post.is_fav) if (post.is_fav)
tags.push('fav:me'); tags.push("fav:me");
$.each(post.flags.match(/\S+/g) || [], function (i, v) { $.each(post.flags.match(/\S+/g) || [], function (i, v) {
tags.push(`status:${v}`); tags.push(`status:${v}`);
}); });
@ -281,7 +281,7 @@ Blacklist.postMatchObject = function (post, entry) {
return (Utility.is_subset(tags, entry.require) && score_test) return (Utility.is_subset(tags, entry.require) && score_test)
&& (!entry.optional.length || Utility.intersect(tags, entry.optional).length) && (!entry.optional.length || Utility.intersect(tags, entry.optional).length)
&& !Utility.intersect(tags, entry.exclude).length; && !Utility.intersect(tags, entry.exclude).length;
} };
Blacklist.initialize_all = function () { Blacklist.initialize_all = function () {
Blacklist.entriesParse(); Blacklist.entriesParse();
@ -289,18 +289,18 @@ Blacklist.initialize_all = function () {
Blacklist.initialize_disable_all_blacklists(); Blacklist.initialize_disable_all_blacklists();
Blacklist.apply(); Blacklist.apply();
$("#blacklisted-hider").remove(); $("#blacklisted-hider").remove();
} };
Blacklist.initialize_anonymous_blacklist = function () { Blacklist.initialize_anonymous_blacklist = function () {
if ($(document.body).data('user-is-anonymous') !== true) { if ($(document.body).data("user-is-anonymous") !== true) {
return; return;
} }
const anonBlacklist = LS.get('anonymous-blacklist'); const anonBlacklist = LS.get("anonymous-blacklist");
if (anonBlacklist) { if (anonBlacklist) {
$("meta[name=blacklisted-tags]").attr("content", anonBlacklist); $("meta[name=blacklisted-tags]").attr("content", anonBlacklist);
} }
} };
Blacklist.initialize_blacklist_editor = function () { Blacklist.initialize_blacklist_editor = function () {
$("#blacklist-edit-dialog").dialog({ $("#blacklist-edit-dialog").dialog({
@ -309,21 +309,21 @@ Blacklist.initialize_blacklist_editor = function () {
height: 400, height: 400,
}); });
$("#blacklist-cancel").on('click', function () { $("#blacklist-cancel").on("click", function () {
$("#blacklist-edit-dialog").dialog('close'); $("#blacklist-edit-dialog").dialog("close");
}); });
$("#blacklist-save").on('click', function () { $("#blacklist-save").on("click", function () {
const blacklist_content = $("#blacklist-edit").val(); const blacklist_content = $("#blacklist-edit").val();
const blacklist_json = JSON.stringify(blacklist_content.split(/\n\r?/)); const blacklist_json = JSON.stringify(blacklist_content.split(/\n\r?/));
if($(document.body).data('user-is-anonymous') === true) { if ($(document.body).data("user-is-anonymous") === true) {
LS.put('anonymous-blacklist', blacklist_json); LS.put("anonymous-blacklist", blacklist_json);
} else { } else {
$.ajax("/users/" + Utility.meta("current-user-id") + ".json", { $.ajax("/users/" + Utility.meta("current-user-id") + ".json", {
method: "PUT", method: "PUT",
data: { data: {
"user[blacklisted_tags]": blacklist_content "user[blacklisted_tags]": blacklist_content,
} },
}).done(function () { }).done(function () {
Utility.notice("Blacklist updated"); Utility.notice("Blacklist updated");
}).fail(function () { }).fail(function () {
@ -331,42 +331,42 @@ Blacklist.initialize_blacklist_editor = function () {
}); });
} }
$("#blacklist-edit-dialog").dialog('close'); $("#blacklist-edit-dialog").dialog("close");
$("meta[name=blacklisted-tags]").attr("content", blacklist_json); $("meta[name=blacklisted-tags]").attr("content", blacklist_json);
Blacklist.initialize_all(); Blacklist.initialize_all();
}); });
$("#blacklist-edit-link").on('click', function (event) { $("#blacklist-edit-link").on("click", function (event) {
event.preventDefault(); event.preventDefault();
let entries = JSON.parse(Utility.meta("blacklisted-tags") || "[]"); let entries = JSON.parse(Utility.meta("blacklisted-tags") || "[]");
entries = entries.map(e => e.replace(/(rating:[qes])\w+/ig, "$1").toLowerCase()); entries = entries.map(e => e.replace(/(rating:[qes])\w+/ig, "$1").toLowerCase());
entries = entries.filter(e => e.trim() !== ""); entries = entries.filter(e => e.trim() !== "");
$("#blacklist-edit").val(entries.join('\n')); $("#blacklist-edit").val(entries.join("\n"));
$("#blacklist-edit-dialog").dialog('open'); $("#blacklist-edit-dialog").dialog("open");
}); });
}; };
Blacklist.collapseGet = function () { Blacklist.collapseGet = function () {
const lsValue = LS.get('bc') || '1'; const lsValue = LS.get("bc") || "1";
return lsValue === '1'; return lsValue === "1";
}; };
Blacklist.collapseSet = function (collapsed) { Blacklist.collapseSet = function (collapsed) {
LS.put('bc', collapsed ? "1" : "0"); LS.put("bc", collapsed ? "1" : "0");
}; };
Blacklist.collapseUpdate = function () { Blacklist.collapseUpdate = function () {
if (Blacklist.collapseGet()) { if (Blacklist.collapseGet()) {
$('#blacklist-list').hide(); $("#blacklist-list").hide();
$('#blacklist-collapse').addClass('hidden'); $("#blacklist-collapse").addClass("hidden");
} else { } else {
$('#blacklist-list').show(); $("#blacklist-list").show();
$('#blacklist-collapse').removeClass('hidden'); $("#blacklist-collapse").removeClass("hidden");
} }
}; };
Blacklist.initialize_collapse = function () { Blacklist.initialize_collapse = function () {
$("#blacklist-collapse").on('click', function (e) { $("#blacklist-collapse").on("click", function (e) {
e.preventDefault(); e.preventDefault();
const current = Blacklist.collapseGet(); const current = Blacklist.collapseGet();
Blacklist.collapseSet(!current); Blacklist.collapseSet(!current);
@ -382,4 +382,4 @@ $(document).ready(function () {
Blacklist.initialize_all(); Blacklist.initialize_all();
}); });
export default Blacklist export default Blacklist;

View File

@ -1,3 +1,4 @@
/* eslint-disable quotes */
import Utility from './utility.js'; import Utility from './utility.js';
let Blip = {}; let Blip = {};
@ -9,8 +10,8 @@ Blip.atme = function (id) {
dataType: 'json', dataType: 'json',
accept: 'text/javascript', accept: 'text/javascript',
data: { data: {
id: id id: id,
} },
}).done(function (data) { }).done(function (data) {
$('#blip_body_for_')[0].value += '@' + data.creator_name.replace(/ /g, "_") + ': '; $('#blip_body_for_')[0].value += '@' + data.creator_name.replace(/ /g, "_") + ': ';
$("#blip_body_for_")[0].focus(); $("#blip_body_for_")[0].focus();
@ -27,8 +28,8 @@ Blip.quote = function (id) {
dataType: 'json', dataType: 'json',
accept: 'text/javascript', accept: 'text/javascript',
data: { data: {
id: id id: id,
} },
}).done(function (data) { }).done(function (data) {
const stripped_body = data.body.replace(/\[quote\](?:.|\n|\r)+?\[\/quote\][\n\r]*/gm, ""); const stripped_body = data.body.replace(/\[quote\](?:.|\n|\r)+?\[\/quote\][\n\r]*/gm, "");
$('#blip_body_for_')[0].value += `[quote]"${data.creator_name}":/users/${data.creator_id} said: $('#blip_body_for_')[0].value += `[quote]"${data.creator_name}":/users/${data.creator_id} said:
@ -43,8 +44,8 @@ ${stripped_body}
}); });
}; };
Blip.initialize_all = function() { Blip.initialize_all = function () {
if($("#c-blips").length) { if ($("#c-blips").length) {
$(".blip-atme-link").on('click', e => { $(".blip-atme-link").on('click', e => {
Blip.atme($(e.target).data('bid')); Blip.atme($(e.target).data('bid'));
e.preventDefault(); e.preventDefault();
@ -54,17 +55,17 @@ Blip.initialize_all = function() {
e.preventDefault(); e.preventDefault();
}); });
} }
} };
Blip.reinitialize_all = function() { Blip.reinitialize_all = function () {
if($("#c-blips").length) { if ($("#c-blips").length) {
$(".blip-atme-link").off('click'); $(".blip-atme-link").off('click');
$(".blip-reply-link").off('click'); $(".blip-reply-link").off('click');
Blip.initialize_all(); Blip.initialize_all();
} }
} };
$(function() { $(function () {
Blip.initialize_all(); Blip.initialize_all();
}); });

View File

@ -7,50 +7,50 @@ Comment.initialize_all = function () {
if ($("#c-posts").length || $("#c-comments").length) { if ($("#c-posts").length || $("#c-comments").length) {
$(".edit_comment_link").on("click", Comment.show_edit_form); $(".edit_comment_link").on("click", Comment.show_edit_form);
$(".expand-comment-response").on("click", Comment.show_new_comment_form); $(".expand-comment-response").on("click", Comment.show_new_comment_form);
$('.comment-vote-up-link').on("click", Comment.vote_up); $(".comment-vote-up-link").on("click", Comment.vote_up);
$(".comment-vote-down-link").on("click", Comment.vote_down); $(".comment-vote-down-link").on("click", Comment.vote_down);
$(".comment-reply-link").on('click', Comment.quote); $(".comment-reply-link").on("click", Comment.quote);
$(".comment-hide-link").on('click', Comment.hide); $(".comment-hide-link").on("click", Comment.hide);
$(".comment-unhide-link").on('click', Comment.unhide); $(".comment-unhide-link").on("click", Comment.unhide);
$(".comment-delete-link").on('click', Comment.delete); $(".comment-delete-link").on("click", Comment.delete);
$(".show-all-comments-for-post-link").on('click', Comment.show_all); $(".show-all-comments-for-post-link").on("click", Comment.show_all);
$(".comment-tag-hide-link").on("click", Comment.toggle_post_tags); $(".comment-tag-hide-link").on("click", Comment.toggle_post_tags);
} }
} };
Comment.reinitialize_all = function () { Comment.reinitialize_all = function () {
if ($("#c-posts").length || $("#c-comments").length) { if ($("#c-posts").length || $("#c-comments").length) {
$(".comment-reply-link").off('click'); $(".comment-reply-link").off("click");
$(".comment-hide-link").off('click'); $(".comment-hide-link").off("click");
$(".comment-unhide-link").off('click'); $(".comment-unhide-link").off("click");
$(".comment-delete-link").off('click'); $(".comment-delete-link").off("click");
$(".show-all-comments-for-post-link").off('click'); $(".show-all-comments-for-post-link").off("click");
$(".comment-tag-hide-link").off("click"); $(".comment-tag-hide-link").off("click");
$(".edit_comment_link").off('click'); $(".edit_comment_link").off("click");
$(".expand-comment-response").off('click'); $(".expand-comment-response").off("click");
$('.comment-vote-up-link').off('click'); $(".comment-vote-up-link").off("click");
$(".comment-vote-down-link").off('click'); $(".comment-vote-down-link").off("click");
Comment.initialize_all(); Comment.initialize_all();
DText.initialize_all_inputs(); DText.initialize_all_inputs();
} }
} };
Comment.show_all = function(e) { Comment.show_all = function (e) {
e.preventDefault(); e.preventDefault();
const target = $(e.target); const target = $(e.target);
const post_id = target.data('pid'); const post_id = target.data("pid");
$.ajax({ $.ajax({
url: `/posts/${post_id}/comments.json`, url: `/posts/${post_id}/comments.json`,
type: 'GET', type: "GET",
dataType: 'json' dataType: "json",
}).done(function(data) { }).done(function (data) {
$(`#threshold-comments-notice-for-${post_id}`).hide(); $(`#threshold-comments-notice-for-${post_id}`).hide();
const current_comment_section = $(`div.comments-for-post[data-post-id=${post_id}] div.list-of-comments`); const current_comment_section = $(`div.comments-for-post[data-post-id=${post_id}] div.list-of-comments`);
current_comment_section.html(data.html); current_comment_section.html(data.html);
Comment.reinitialize_all(); Comment.reinitialize_all();
$(window).trigger("e621:add_deferred_posts", data.posts); $(window).trigger("e621:add_deferred_posts", data.posts);
}).fail(function() { }).fail(function () {
Utility.error("Failed to fetch all comments for this post."); Utility.error("Failed to fetch all comments for this post.");
}); });
}; };
@ -59,15 +59,15 @@ Comment.hide = function (e) {
e.preventDefault(); e.preventDefault();
if (!confirm("Are you sure you want to hide this comment?")) if (!confirm("Are you sure you want to hide this comment?"))
return; return;
const parent = $(e.target).parents('article.comment'); const parent = $(e.target).parents("article.comment");
const cid = parent.data('comment-id'); const cid = parent.data("comment-id");
$.ajax({ $.ajax({
url: `/comments/${cid}/hide.json`, url: `/comments/${cid}/hide.json`,
type: 'POST', type: "POST",
dataType: 'json' dataType: "json",
}).done(function () { }).done(function () {
$(`.comment[data-comment-id="${cid}"] div.author h1`).append(" (hidden)"); $(`.comment[data-comment-id="${cid}"] div.author h1`).append(" (hidden)");
$(`.comment[data-comment-id="${cid}"]`).attr('data-is-deleted', 'true'); $(`.comment[data-comment-id="${cid}"]`).attr("data-is-deleted", "true");
}).fail(function () { }).fail(function () {
Utility.error("Failed to hide comment."); Utility.error("Failed to hide comment.");
}); });
@ -77,16 +77,16 @@ Comment.unhide = function (e) {
e.preventDefault(); e.preventDefault();
if (!confirm("Are you sure you want to unhide this comment?")) if (!confirm("Are you sure you want to unhide this comment?"))
return; return;
const parent = $(e.target).parents('article.comment'); const parent = $(e.target).parents("article.comment");
const cid = parent.data('comment-id'); const cid = parent.data("comment-id");
$.ajax({ $.ajax({
url: `/comments/${cid}/unhide.json`, url: `/comments/${cid}/unhide.json`,
type: 'POST', type: "POST",
dataType: 'json' dataType: "json",
}).done(function () { }).done(function () {
const $author = $(`.comment[data-comment-id="${cid}"] div.author h1`); const $author = $(`.comment[data-comment-id="${cid}"] div.author h1`);
$author.text($author.text().replace(" (hidden)", "")); $author.text($author.text().replace(" (hidden)", ""));
$(`.comment[data-comment-id="${cid}"]`).attr('data-is-deleted', 'false'); $(`.comment[data-comment-id="${cid}"]`).attr("data-is-deleted", "false");
}).fail(function () { }).fail(function () {
Utility.error("Failed to unhide comment."); Utility.error("Failed to unhide comment.");
}); });
@ -96,12 +96,12 @@ Comment.delete = function (e) {
e.preventDefault(); e.preventDefault();
if (!confirm("Are you sure you want to permanently delete this comment?")) if (!confirm("Are you sure you want to permanently delete this comment?"))
return; return;
const parent = $(e.target).parents('article.comment'); const parent = $(e.target).parents("article.comment");
const cid = parent.data('comment-id'); const cid = parent.data("comment-id");
$.ajax({ $.ajax({
url: `/comments/${cid}.json`, url: `/comments/${cid}.json`,
type: 'DELETE', type: "DELETE",
dataType: 'json' dataType: "json",
}).done(function () { }).done(function () {
parent.remove(); parent.remove();
}).fail(function () { }).fail(function () {
@ -111,17 +111,17 @@ Comment.delete = function (e) {
Comment.quote = function (e) { Comment.quote = function (e) {
e.preventDefault(); e.preventDefault();
const parent = $(e.target).parents('article.comment'); const parent = $(e.target).parents("article.comment");
const pid = parent.data('post-id'); const pid = parent.data("post-id");
const cid = parent.data('comment-id'); const cid = parent.data("comment-id");
$.ajax({ $.ajax({
url: `/comments/${cid}.json`, url: `/comments/${cid}.json`,
type: 'GET', type: "GET",
dataType: 'json', dataType: "json",
accept: 'text/javascript' accept: "text/javascript",
}).done(function (data) { }).done(function (data) {
let stripped_body = data.body.replace(/\[quote\](?:.|\n|\r)+?\[\/quote\][\n\r]*/gm, ""); let stripped_body = data.body.replace(/\[quote\](?:.|\n|\r)+?\[\/quote\][\n\r]*/gm, "");
stripped_body = `[quote]"${parent.data('creator')}":/users/${parent.data('creator-id')} said: stripped_body = `[quote]"${parent.data("creator")}":/users/${parent.data("creator-id")} said:
${stripped_body} ${stripped_body}
[/quote] [/quote]
@ -145,8 +145,8 @@ ${stripped_body}
Comment.toggle_post_tags = function (e) { Comment.toggle_post_tags = function (e) {
e.preventDefault(); e.preventDefault();
const link = $(e.target); const link = $(e.target);
$(`#post-tags-${link.data('post-id')}`).toggleClass("hidden"); $(`#post-tags-${link.data("post-id")}`).toggleClass("hidden");
} };
Comment.show_new_comment_form = function (e) { Comment.show_new_comment_form = function (e) {
e.preventDefault(); e.preventDefault();
@ -154,55 +154,55 @@ Comment.show_new_comment_form = function (e) {
var $form = $(e.target).closest("div.new-comment").find("form"); var $form = $(e.target).closest("div.new-comment").find("form");
$form.show(); $form.show();
$form[0].scrollIntoView(false); $form[0].scrollIntoView(false);
} };
Comment.show_edit_form = function (e) { Comment.show_edit_form = function (e) {
e.preventDefault(); e.preventDefault();
$(this).closest(".comment").find(".edit_comment").show(); $(this).closest(".comment").find(".edit_comment").show();
} };
Comment.vote_up = function (e) { Comment.vote_up = function (e) {
var id = $(e.target).attr('data-id'); var id = $(e.target).attr("data-id");
Comment.vote(id, 1); Comment.vote(id, 1);
} };
Comment.vote_down = function (e) { Comment.vote_down = function (e) {
var id = $(e.target).attr('data-id'); var id = $(e.target).attr("data-id");
Comment.vote(id, -1); Comment.vote(id, -1);
} };
Comment.vote = function (id, score) { Comment.vote = function (id, score) {
$.ajax({ $.ajax({
method: 'POST', method: "POST",
url: `/comments/${id}/votes.json`, url: `/comments/${id}/votes.json`,
data: { data: {
score: score score: score,
}, },
dataType: 'json' dataType: "json",
}).done(function (data) { }).done(function (data) {
const scoreClasses = 'score-neutral score-positive score-negative'; const scoreClasses = "score-neutral score-positive score-negative";
const commentID = id; const commentID = id;
const commentScore = data.score; const commentScore = data.score;
const ourScore = data.our_score; const ourScore = data.our_score;
function scoreToClass(inScore) { function scoreToClass (inScore) {
if (inScore === 0) return 'score-neutral'; if (inScore === 0) return "score-neutral";
return inScore > 0 ? 'score-positive' : 'score-negative'; return inScore > 0 ? "score-positive" : "score-negative";
} }
$("#comment-score-"+commentID).removeClass(scoreClasses); $("#comment-score-" + commentID).removeClass(scoreClasses);
$("#comment-vote-up-"+commentID).removeClass(scoreClasses); $("#comment-vote-up-" + commentID).removeClass(scoreClasses);
$("#comment-vote-down-"+commentID).removeClass(scoreClasses); $("#comment-vote-down-" + commentID).removeClass(scoreClasses);
$('#comment-score-'+commentID).text(commentScore); $("#comment-score-" + commentID).text(commentScore);
$("#comment-score-"+commentID).addClass(scoreToClass(commentScore)); $("#comment-score-" + commentID).addClass(scoreToClass(commentScore));
$('#comment-vote-up-'+commentID).addClass(ourScore > 0 ? 'score-positive' : 'score-neutral'); $("#comment-vote-up-" + commentID).addClass(ourScore > 0 ? "score-positive" : "score-neutral");
$('#comment-vote-down-'+commentID).addClass(ourScore < 0 ? 'score-negative' : 'score-neutral'); $("#comment-vote-down-" + commentID).addClass(ourScore < 0 ? "score-negative" : "score-neutral");
Utility.notice('Vote saved'); Utility.notice("Vote saved");
}).fail(function(data) { }).fail(function (data) {
Utility.error(data.responseJSON.message); Utility.error(data.responseJSON.message);
}); });
} };
$(document).ready(function () { $(document).ready(function () {
Comment.initialize_all(); Comment.initialize_all();
}); });
export default Comment export default Comment;

View File

@ -1,29 +1,29 @@
import Cookie from './cookie' import Cookie from "./cookie";
import LS from './local_storage' import LS from "./local_storage";
import Utility from './utility' import Utility from "./utility";
function initSearch() { function initSearch () {
const $searchForm = $("#searchform"); const $searchForm = $("#searchform");
const $searchShow = $("#search-form-show-link"); const $searchShow = $("#search-form-show-link");
const $searchHide = $("#search-form-hide-link"); const $searchHide = $("#search-form-hide-link");
if ($searchForm.length) { if ($searchForm.length) {
$searchShow.on('click', e => { $searchShow.on("click", e => {
e.preventDefault(); e.preventDefault();
$searchForm.fadeIn('fast'); $searchForm.fadeIn("fast");
$searchShow.hide(); $searchShow.hide();
$searchHide.show(); $searchHide.show();
}); });
$searchHide.on('click', e => { $searchHide.on("click", e => {
e.preventDefault(); e.preventDefault();
$searchForm.fadeOut('fast'); $searchForm.fadeOut("fast");
$searchShow.show(); $searchShow.show();
$searchHide.hide(); $searchHide.hide();
}); });
} }
} }
$(function() { $(function () {
$("#theme-switcher").change(function() { $("#theme-switcher").change(function () {
let theme = $(this).val(); let theme = $(this).val();
LS.put("theme", theme); LS.put("theme", theme);
$("body").attr("data-th-main", theme); $("body").attr("data-th-main", theme);
@ -36,7 +36,7 @@ $(function() {
} }
// Account notices // Account notices
$("#hide-dmail-notice").on("click.danbooru", function(e) { $("#hide-dmail-notice").on("click.danbooru", function (e) {
var $dmail_notice = $("#dmail-notice"); var $dmail_notice = $("#dmail-notice");
$dmail_notice.hide(); $dmail_notice.hide();
var dmail_id = $dmail_notice.data("id"); var dmail_id = $dmail_notice.data("id");
@ -44,27 +44,27 @@ $(function() {
e.preventDefault(); e.preventDefault();
}); });
$("#close-notice-link").on("click.danbooru", function(e) { $("#close-notice-link").on("click.danbooru", function (e) {
$('#notice').fadeOut("fast"); $("#notice").fadeOut("fast");
e.preventDefault(); e.preventDefault();
}); });
$(".revert-item-link").on('click', e => { $(".revert-item-link").on("click", e => {
e.preventDefault(); e.preventDefault();
const target = $(e.target); const target = $(e.target);
const noun = target.data('noun'); const noun = target.data("noun");
if (!confirm(`Are you sure you want to revert ${noun} to this version?`)) if (!confirm(`Are you sure you want to revert ${noun} to this version?`))
return; return;
const path = target.attr('href'); const path = target.attr("href");
$.ajax({ $.ajax({
method: "PUT", method: "PUT",
url: path, url: path,
dataType: 'json' dataType: "json",
}).done(() => { }).done(() => {
location.reload(); location.reload();
}).fail(() => { }).fail(() => {
Utility.error("Failed to revert to specified version."); Utility.error("Failed to revert to specified version.");
}) });
}); });
initSearch(); initSearch();
@ -72,4 +72,4 @@ $(function() {
window.submitInvisibleRecaptchaForm = function () { window.submitInvisibleRecaptchaForm = function () {
document.getElementById("signup-form").submit(); document.getElementById("signup-form").submit();
} };

View File

@ -2,7 +2,7 @@ import Utility from "./utility";
let Cookie = {}; let Cookie = {};
Cookie.put = function(name, value, days) { Cookie.put = function (name, value, days) {
var expires = ""; var expires = "";
if (days !== "session") { if (days !== "session") {
if (!days) { if (!days) {
@ -19,12 +19,12 @@ Cookie.put = function(name, value, days) {
document.cookie = new_val; document.cookie = new_val;
return true; return true;
} else { } else {
Utility.error("You have too many cookies on this site. Consider deleting them all.") Utility.error("You have too many cookies on this site. Consider deleting them all.");
return false; return false;
} }
} };
Cookie.raw_get = function(name) { Cookie.raw_get = function (name) {
var nameEq = name + "="; var nameEq = name + "=";
var ca = document.cookie.split(";"); var ca = document.cookie.split(";");
@ -41,18 +41,18 @@ Cookie.raw_get = function(name) {
} }
return ""; return "";
} };
Cookie.get = function(name) { Cookie.get = function (name) {
return this.unescape(this.raw_get(name)); return this.unescape(this.raw_get(name));
} };
Cookie.remove = function(name) { Cookie.remove = function (name) {
this.put(name, "", -1); this.put(name, "", -1);
} };
Cookie.unescape = function(val) { Cookie.unescape = function (val) {
return decodeURIComponent(val.replace(/\+/g, " ")); return decodeURIComponent(val.replace(/\+/g, " "));
} };
export default Cookie export default Cookie;

View File

@ -1,8 +1,8 @@
import { SendQueue } from './send_queue'; import { SendQueue } from "./send_queue";
const DText = {}; const DText = {};
DText.initialze_input = function($element) { DText.initialze_input = function ($element) {
const $preview = $(".dtext-formatter-preview", $element); const $preview = $(".dtext-formatter-preview", $element);
const $textarea = $(".dtext-formatter-input", $element); const $textarea = $(".dtext-formatter-input", $element);
const $charcount = $(".dtext-formatter-charcount", $element); const $charcount = $(".dtext-formatter-charcount", $element);
@ -10,7 +10,7 @@ DText.initialze_input = function($element) {
// Tab switching // Tab switching
$(".dtext-formatter-tabs a", $element).on("click", event => { $(".dtext-formatter-tabs a", $element).on("click", event => {
event.preventDefault(); event.preventDefault();
if($element.attr("data-editing") == "true") { if ($element.attr("data-editing") == "true") {
$preview.css("min-height", $textarea.outerHeight()); $preview.css("min-height", $textarea.outerHeight());
$element.attr("data-editing", "false"); $element.attr("data-editing", "false");
update_preview($textarea, $preview); update_preview($textarea, $preview);
@ -30,12 +30,12 @@ DText.initialze_input = function($element) {
DText.initialize_formatting_buttons($element); DText.initialize_formatting_buttons($element);
$element.attr("data-initialized", "true"); $element.attr("data-initialized", "true");
} };
DText.initialize_formatting_buttons = function(element) { DText.initialize_formatting_buttons = function (element) {
const $textarea = $(".dtext-formatter-input", element); const $textarea = $(".dtext-formatter-input", element);
for(const button of $(".dtext-formatter-buttons a", element)) { for (const button of $(".dtext-formatter-buttons a", element)) {
const $button = $(button); const $button = $(button);
const content = $button.attr("data-content"); const content = $button.attr("data-content");
$button.off("click"); $button.off("click");
@ -44,21 +44,21 @@ DText.initialize_formatting_buttons = function(element) {
DText.process_formatting(content, $textarea); DText.process_formatting(content, $textarea);
}); });
} }
} };
/** Refreshes the preview field to match the provided input */ /** Refreshes the preview field to match the provided input */
function update_preview(input, preview) { function update_preview (input, preview) {
const currentText = input.val().trim(); const currentText = input.val().trim();
// The input is empty, reset everything // The input is empty, reset everything
if(!currentText) { if (!currentText) {
preview.text(""); preview.text("");
input.removeData("cache"); input.removeData("cache");
return; return;
} }
// The input is identical to the previous lookup // The input is identical to the previous lookup
if(input.data("cache") == currentText) return; if (input.data("cache") == currentText) return;
input.data("cache", currentText); input.data("cache", currentText);
preview preview
@ -74,7 +74,7 @@ function update_preview(input, preview) {
// The loading was cancelled, since the user toggled back // The loading was cancelled, since the user toggled back
// to the editing tab and potentially changed the input // to the editing tab and potentially changed the input
if(preview.attr("loading") !== "true" || input.data("cache") !== currentText) if (preview.attr("loading") !== "true" || input.data("cache") !== currentText)
return; return;
preview preview
@ -87,7 +87,7 @@ function update_preview(input, preview) {
.attr("loading", "false") .attr("loading", "false")
.text("Unable to fetch DText preview."); .text("Unable to fetch DText preview.");
input.removeData("cache"); input.removeData("cache");
} },
}); });
}); });
} }
@ -120,14 +120,14 @@ DText.process_formatting = function (content, input) {
input.prop("selectionStart", position.start + offset.start); input.prop("selectionStart", position.start + offset.start);
input.prop("selectionEnd", position.start + content.length - offset.end); input.prop("selectionEnd", position.start + content.length - offset.end);
input.trigger("focus"); input.trigger("focus");
} };
/** Add formatters to all appropriate inputs */ /** Add formatters to all appropriate inputs */
DText.initialize_all_inputs = function() { DText.initialize_all_inputs = function () {
$(".dtext-formatter[data-initialized='false']").each((index, element) => { $(".dtext-formatter[data-initialized='false']").each((index, element) => {
DText.initialze_input($(element)); DText.initialze_input($(element));
}); });
} };
$(function () { $(function () {
DText.initialize_all_inputs(); DText.initialize_all_inputs();

View File

@ -1,6 +1,6 @@
import Post from './posts' import Post from "./posts";
import Utility from './utility' import Utility from "./utility";
import {SendQueue} from './send_queue' import {SendQueue} from "./send_queue";
let Favorite = {}; let Favorite = {};
@ -35,9 +35,9 @@ Favorite.create = function (post_id) {
type: "POST", type: "POST",
url: "/favorites.json", url: "/favorites.json",
data: { data: {
post_id: post_id post_id: post_id,
}, },
dataType: 'json' dataType: "json",
}).done(function () { }).done(function () {
Post.notice_update("dec"); Post.notice_update("dec");
Favorite.after_action(post_id, 1); Favorite.after_action(post_id, 1);
@ -55,7 +55,7 @@ Favorite.destroy = function (post_id) {
$.ajax({ $.ajax({
type: "DELETE", type: "DELETE",
url: "/favorites/" + post_id + ".json", url: "/favorites/" + post_id + ".json",
dataType: 'json' dataType: "json",
}).done(function () { }).done(function () {
Post.notice_update("dec"); Post.notice_update("dec");
Favorite.after_action(post_id, -1); Favorite.after_action(post_id, -1);
@ -68,4 +68,4 @@ Favorite.destroy = function (post_id) {
$(Favorite.initialize_actions); $(Favorite.initialize_actions);
export default Favorite export default Favorite;

View File

@ -2,59 +2,59 @@ import Utility from "./utility";
let ForumPost = {}; let ForumPost = {};
ForumPost.initialize_all = function() { ForumPost.initialize_all = function () {
if ($("#c-forum-topics #a-show,#c-forum-posts #a-show").length) { if ($("#c-forum-topics #a-show,#c-forum-posts #a-show").length) {
$(".edit_forum_post_link").on("click.danbooru", function(e) { $(".edit_forum_post_link").on("click.danbooru", function (e) {
var link_id = $(this).attr("id"); var link_id = $(this).attr("id");
var forum_post_id = link_id.match(/^edit_forum_post_link_(\d+)$/)[1]; var forum_post_id = link_id.match(/^edit_forum_post_link_(\d+)$/)[1];
$("#edit_forum_post_" + forum_post_id).fadeToggle("fast"); $("#edit_forum_post_" + forum_post_id).fadeToggle("fast");
e.preventDefault(); e.preventDefault();
}); });
$(".edit_forum_topic_link").on("click.danbooru", function(e) { $(".edit_forum_topic_link").on("click.danbooru", function (e) {
var link_id = $(this).attr("id"); var link_id = $(this).attr("id");
var forum_topic_id = link_id.match(/^edit_forum_topic_link_(\d+)$/)[1]; var forum_topic_id = link_id.match(/^edit_forum_topic_link_(\d+)$/)[1];
$("#edit_forum_topic_" + forum_topic_id).fadeToggle("fast"); $("#edit_forum_topic_" + forum_topic_id).fadeToggle("fast");
e.preventDefault(); e.preventDefault();
}); });
$(".forum-post-reply-link").on('click', ForumPost.quote); $(".forum-post-reply-link").on("click", ForumPost.quote);
$(".forum-post-hide-link").on('click', ForumPost.hide); $(".forum-post-hide-link").on("click", ForumPost.hide);
$(".forum-post-unhide-link").on('click', ForumPost.unhide); $(".forum-post-unhide-link").on("click", ForumPost.unhide);
$(".forum-vote-up").on('click', evt => ForumPost.vote(evt, 1)); $(".forum-vote-up").on("click", evt => ForumPost.vote(evt, 1));
$(".forum-vote-meh").on('click', evt => ForumPost.vote(evt, 0)); $(".forum-vote-meh").on("click", evt => ForumPost.vote(evt, 0));
$(".forum-vote-down").on('click', evt => ForumPost.vote(evt, -1)); $(".forum-vote-down").on("click", evt => ForumPost.vote(evt, -1));
$(document).on('click', ".forum-vote-remove", ForumPost.vote_remove); $(document).on("click", ".forum-vote-remove", ForumPost.vote_remove);
} }
} };
ForumPost.reinitialize_all = function() { ForumPost.reinitialize_all = function () {
if ($("#c-forum-topics #a-show,#c-forum-posts #a-show").length) { if ($("#c-forum-topics #a-show,#c-forum-posts #a-show").length) {
$(".edit_forum_post_link").off("click.danbooru"); $(".edit_forum_post_link").off("click.danbooru");
$(".edit_forum_topic_link").off("click.danbooru"); $(".edit_forum_topic_link").off("click.danbooru");
$(".forum-post-reply-link").off('click'); $(".forum-post-reply-link").off("click");
$(".forum-post-hide-link").off('click'); $(".forum-post-hide-link").off("click");
$(".forum-post-unhide-link").off('click'); $(".forum-post-unhide-link").off("click");
$(".forum-vote-up").off('click'); $(".forum-vote-up").off("click");
$(".forum-vote-meh").off('click'); $(".forum-vote-meh").off("click");
$(".forum-vote-down").off('click'); $(".forum-vote-down").off("click");
$(document).off('click', ".forum-vote-remove"); $(document).off("click", ".forum-vote-remove");
this.initialize_all(); this.initialize_all();
} }
} };
ForumPost.vote = function(evt, score) { ForumPost.vote = function (evt, score) {
evt.preventDefault(); evt.preventDefault();
const create_post = function(new_vote) { const create_post = function (new_vote) {
const score_map = { const score_map = {
"1": { fa_class: "fa-thumbs-up", e6_class: "up" }, "1": { fa_class: "fa-thumbs-up", e6_class: "up" },
"0": { fa_class: "fa-face-meh", e6_class: "meh" }, "0": { fa_class: "fa-face-meh", e6_class: "meh" },
"-1": { fa_class: "fa-thumbs-down", e6_class: "down" }, "-1": { fa_class: "fa-thumbs-down", e6_class: "down" },
} };
const icon = $('<a>').attr('href', '#').attr('data-forum-id', new_vote.forum_post_id).addClass('forum-vote-remove').append($('<i>').addClass('fa-regular').addClass(score_map[new_vote.score.toString()].fa_class)); const icon = $("<a>").attr("href", "#").attr("data-forum-id", new_vote.forum_post_id).addClass("forum-vote-remove").append($("<i>").addClass("fa-regular").addClass(score_map[new_vote.score.toString()].fa_class));
const username = $('<a>').attr('href', `/users/${new_vote.creator_id}`).text(new_vote.creator_name); const username = $("<a>").attr("href", `/users/${new_vote.creator_id}`).text(new_vote.creator_name);
const container = $('<li>').addClass(`vote-score-${score_map[new_vote.score].e6_class}`).addClass('own-forum-vote'); const container = $("<li>").addClass(`vote-score-${score_map[new_vote.score].e6_class}`).addClass("own-forum-vote");
container.append(icon).append(' ').append(username); container.append(icon).append(" ").append(username);
$(`#forum-post-votes-for-${new_vote.forum_post_id}`).prepend(container); $(`#forum-post-votes-for-${new_vote.forum_post_id}`).prepend(container);
}; };
const id = $(evt.currentTarget).data("forum-id"); const id = $(evt.currentTarget).data("forum-id");
@ -63,20 +63,20 @@ ForumPost.vote = function(evt, score) {
type: "POST", type: "POST",
dataType: "json", dataType: "json",
accept: "text/javascript", accept: "text/javascript",
data: { "forum_post_vote[score]": score } data: { "forum_post_vote[score]": score },
}).done(function(data) { }).done(function (data) {
create_post(data); create_post(data);
$(`#forum-post-votes-for-${id} .forum-post-vote-block`).hide(); $(`#forum-post-votes-for-${id} .forum-post-vote-block`).hide();
}).fail(function(data) { }).fail(function (data) {
if(data?.responseJSON?.reason) { if (data?.responseJSON?.reason) {
Utility.error(data.responseJSON.reason); Utility.error(data.responseJSON.reason);
} else { } else {
Utility.error("Failed to vote on forum post."); Utility.error("Failed to vote on forum post.");
} }
}); });
} };
ForumPost.vote_remove = function(evt) { ForumPost.vote_remove = function (evt) {
evt.preventDefault(); evt.preventDefault();
const id = $(evt.currentTarget).data("forum-id"); const id = $(evt.currentTarget).data("forum-id");
$.ajax({ $.ajax({
@ -84,32 +84,32 @@ ForumPost.vote_remove = function(evt) {
type: "DELETE", type: "DELETE",
dataType: "json", dataType: "json",
accept: "text/javascript", accept: "text/javascript",
}).done(function() { }).done(function () {
$(evt.target).parents(".own-forum-vote").remove(); $(evt.target).parents(".own-forum-vote").remove();
$(`#forum-post-votes-for-${id} .forum-post-vote-block`).show(); $(`#forum-post-votes-for-${id} .forum-post-vote-block`).show();
Utility.notice("Vote removed."); Utility.notice("Vote removed.");
}).fail(function() { }).fail(function () {
Utility.error("Failed to unvote on forum post."); Utility.error("Failed to unvote on forum post.");
}) });
} };
ForumPost.quote = function (e) { ForumPost.quote = function (e) {
e.preventDefault(); e.preventDefault();
const parent = $(e.target).parents('article.forum-post'); const parent = $(e.target).parents("article.forum-post");
const fpid = parent.data('forum-post-id'); const fpid = parent.data("forum-post-id");
$.ajax({ $.ajax({
url: `/forum_posts/${fpid}.json`, url: `/forum_posts/${fpid}.json`,
type: 'GET', type: "GET",
dataType: 'json', dataType: "json",
accept: 'text/javascript' accept: "text/javascript",
}).done(function (data) { }).done(function (data) {
let stripped_body = data.body.replace(/\[quote\](?:.|\n|\r)+?\[\/quote\][\n\r]*/gm, ""); let stripped_body = data.body.replace(/\[quote\](?:.|\n|\r)+?\[\/quote\][\n\r]*/gm, "");
stripped_body = `[quote]"${parent.data('creator')}":/users/${parent.data('creator-id')} said: stripped_body = `[quote]"${parent.data("creator")}":/users/${parent.data("creator-id")} said:
${stripped_body} ${stripped_body}
[/quote] [/quote]
`; `;
var $textarea = $('#forum_post_body_for_'); var $textarea = $("#forum_post_body_for_");
var msg = stripped_body; var msg = stripped_body;
if ($textarea.val().length > 0) { if ($textarea.val().length > 0) {
msg = $textarea.val() + "\n\n" + msg; msg = $textarea.val() + "\n\n" + msg;
@ -117,9 +117,9 @@ ${stripped_body}
$textarea.val(msg); $textarea.val(msg);
$textarea.selectEnd(); $textarea.selectEnd();
$('#topic-response').show(); $("#topic-response").show();
setTimeout(function() { setTimeout(function () {
$('#topic-response')[0].scrollIntoView(); $("#topic-response")[0].scrollIntoView();
}, 15); }, 15);
}).fail(function (data) { }).fail(function (data) {
Utility.error(data.responseText); Utility.error(data.responseText);
@ -130,15 +130,15 @@ ForumPost.hide = function (e) {
e.preventDefault(); e.preventDefault();
if (!confirm("Are you sure you want to hide this post?")) if (!confirm("Are you sure you want to hide this post?"))
return; return;
const parent = $(e.target).parents('article.forum-post'); const parent = $(e.target).parents("article.forum-post");
const fpid = parent.data('forum-post-id'); const fpid = parent.data("forum-post-id");
$.ajax({ $.ajax({
url: `/forum_posts/${fpid}/hide.json`, url: `/forum_posts/${fpid}/hide.json`,
type: 'POST', type: "POST",
dataType: 'json' dataType: "json",
}).done(function () { }).done(function () {
$(`.forum-post[data-forum-post-id="${fpid}"] div.author h4`).append(" (hidden)"); $(`.forum-post[data-forum-post-id="${fpid}"] div.author h4`).append(" (hidden)");
$(`.forum-post[data-forum-post-id="${fpid}"]`).attr('data-is-hidden', 'true'); $(`.forum-post[data-forum-post-id="${fpid}"]`).attr("data-is-hidden", "true");
}).fail(function () { }).fail(function () {
Utility.error("Failed to hide post."); Utility.error("Failed to hide post.");
}); });
@ -148,23 +148,23 @@ ForumPost.unhide = function (e) {
e.preventDefault(); e.preventDefault();
if (!confirm("Are you sure you want to unhide this post?")) if (!confirm("Are you sure you want to unhide this post?"))
return; return;
const parent = $(e.target).parents('article.forum-post'); const parent = $(e.target).parents("article.forum-post");
const fpid = parent.data('forum-post-id'); const fpid = parent.data("forum-post-id");
$.ajax({ $.ajax({
url: `/forum_posts/${fpid}/unhide.json`, url: `/forum_posts/${fpid}/unhide.json`,
type: 'POST', type: "POST",
dataType: 'json' dataType: "json",
}).done(function () { }).done(function () {
const $author = $(`.forum-post[data-forum-post-id="${fpid}"] div.author h4`); const $author = $(`.forum-post[data-forum-post-id="${fpid}"] div.author h4`);
$author.text($author.text().replace(" (hidden)", "")); $author.text($author.text().replace(" (hidden)", ""));
$(`.forum-post[data-forum-post-id="${fpid}"]`).attr('data-is-hidden', 'false'); $(`.forum-post[data-forum-post-id="${fpid}"]`).attr("data-is-hidden", "false");
}).fail(function () { }).fail(function () {
Utility.error("Failed to unhide post."); Utility.error("Failed to unhide post.");
}); });
}; };
$(document).ready(function() { $(document).ready(function () {
ForumPost.initialize_all(); ForumPost.initialize_all();
}); });
export default ForumPost export default ForumPost;

View File

@ -1,22 +1,22 @@
import Cookie from "./cookie"; import Cookie from "./cookie";
const GuestWarning = { const GuestWarning = {
init() { init () {
const hider = $(".guest-warning"); const hider = $(".guest-warning");
const gw = Cookie.get("gw"); const gw = Cookie.get("gw");
if (gw === "seen" || $("#a-terms-of-service").length > 0) { if (gw === "seen" || $("#a-terms-of-service").length > 0) {
return; return;
} }
hider.show(); hider.show();
$("#guest-warning-accept").on('click', function() { $("#guest-warning-accept").on("click", function () {
Cookie.put("gw", "seen"); Cookie.put("gw", "seen");
hider.hide(); hider.hide();
}); });
$("#guest-warning-decline").on('click', function() { $("#guest-warning-decline").on("click", function () {
Cookie.put("gw", "reject"); Cookie.put("gw", "reject");
window.location.assign("https://www.google.com/"); window.location.assign("https://www.google.com/");
}); });
} },
}; };
$(document).ready(function () { $(document).ready(function () {

View File

@ -1,14 +1,14 @@
let LS = { let LS = {
put(name, value) { put (name, value) {
localStorage[name] = value; localStorage[name] = value;
}, },
putObject(name, value) { putObject (name, value) {
this.put(name, JSON.stringify(value)); this.put(name, JSON.stringify(value));
}, },
get(name) { get (name) {
return localStorage[name]; return localStorage[name];
}, },
getObject(name) { getObject (name) {
const value = this.get(name); const value = this.get(name);
try { try {
return JSON.parse(value); return JSON.parse(value);
@ -16,7 +16,7 @@ let LS = {
console.log(error); console.log(error);
return null; return null;
} }
} },
}; };
export default LS; export default LS;

View File

@ -1,44 +1,44 @@
import LS from './local_storage' import LS from "./local_storage";
const Mascots = { const Mascots = {
current: 0 current: 0,
}; };
function showMascot(mascot) { function showMascot (mascot) {
$('body').css("background-image", "url(" + mascot.background_url + ")"); $("body").css("background-image", "url(" + mascot.background_url + ")");
$('body').css("background-color", mascot.background_color); $("body").css("background-color", mascot.background_color);
$('.mascotbox').css("background-image", "url(" + mascot.background_url + ")"); $(".mascotbox").css("background-image", "url(" + mascot.background_url + ")");
$('.mascotbox').css("background-color", mascot.background_color); $(".mascotbox").css("background-color", mascot.background_color);
const artistLink = $("<span>").text("Mascot by ").append($("<a>").text(mascot.artist_name).attr("href", mascot.artist_url)); const artistLink = $("<span>").text("Mascot by ").append($("<a>").text(mascot.artist_name).attr("href", mascot.artist_url));
$("#mascot_artist").empty().append(artistLink); $("#mascot_artist").empty().append(artistLink);
} }
function changeMascot() { function changeMascot () {
const mascots = window.mascots; const mascots = window.mascots;
const availableMascotIds = Object.keys(mascots); const availableMascotIds = Object.keys(mascots);
const currentMascotIndex = availableMascotIds.indexOf(Mascots.current); const currentMascotIndex = availableMascotIds.indexOf(Mascots.current);
Mascots.current = availableMascotIds[(currentMascotIndex + 1) % availableMascotIds.length]; Mascots.current = availableMascotIds[(currentMascotIndex + 1) % availableMascotIds.length];
showMascot(mascots[Mascots.current]); showMascot(mascots[Mascots.current]);
LS.put('mascot', Mascots.current); LS.put("mascot", Mascots.current);
} }
function initMascots() { function initMascots () {
$('#change-mascot').on('click', changeMascot); $("#change-mascot").on("click", changeMascot);
const mascots = window.mascots; const mascots = window.mascots;
Mascots.current = LS.get("mascot"); Mascots.current = LS.get("mascot");
if (!mascots[Mascots.current]) { if (!mascots[Mascots.current]) {
const availableMascotIds = Object.keys(mascots); const availableMascotIds = Object.keys(mascots);
const mascotIndex = Math.floor(Math.random() * availableMascotIds.length); const mascotIndex = Math.floor(Math.random() * availableMascotIds.length);
Mascots.current = availableMascotIds[mascotIndex]; Mascots.current = availableMascotIds[mascotIndex];
} }
showMascot(mascots[Mascots.current]); showMascot(mascots[Mascots.current]);
} }
$(function () { $(function () {
if ($('#c-static > #a-home').length) if ($("#c-static > #a-home").length)
initMascots(); initMascots();
}); });

View File

@ -1,10 +1,10 @@
import Utility from './utility' import Utility from "./utility";
import Post from './posts' import Post from "./posts";
import LS from './local_storage'; import LS from "./local_storage";
let ModQueue = {}; let ModQueue = {};
ModQueue.detailed_rejection_dialog = function() { ModQueue.detailed_rejection_dialog = function () {
const postID = $(this).data("post-id"); const postID = $(this).data("post-id");
$("#post_disapproval_post_id").val(postID); $("#post_disapproval_post_id").val(postID);
$("#detailed-rejection-dialog").find("form")[0].reset(); $("#detailed-rejection-dialog").find("form")[0].reset();
@ -12,19 +12,19 @@ ModQueue.detailed_rejection_dialog = function() {
$("#new_post_disapproval") $("#new_post_disapproval")
.off("submit.danbooru") .off("submit.danbooru")
.on("submit.danbooru", () => { .on("submit.danbooru", () => {
Post.disapprove(postID, $("#post_disapproval_reason").val(), $("#post_disapproval_message").val()) Post.disapprove(postID, $("#post_disapproval_reason").val(), $("#post_disapproval_message").val());
return false; return false;
}); });
Utility.dialog("Detailed Rejection", "#detailed-rejection-dialog"); Utility.dialog("Detailed Rejection", "#detailed-rejection-dialog");
return false; return false;
} };
$(function() { $(function () {
// Toolbar visibility // Toolbar visibility
let toolbarVisible = LS.get("jtb") == "true"; let toolbarVisible = LS.get("jtb") == "true";
const toolbar = $("#pending-approval-notice"); const toolbar = $("#pending-approval-notice");
if(toolbarVisible) toolbar.addClass("enabled"); if (toolbarVisible) toolbar.addClass("enabled");
const toolbarToggle = $("#janitor-toolbar-toggle") const toolbarToggle = $("#janitor-toolbar-toggle")
.on("click", (event) => { .on("click", (event) => {
@ -41,15 +41,15 @@ $(function() {
// Toolbar buttons // Toolbar buttons
$(document).on("click.danbooru", ".quick-mod .detailed-rejection-link", ModQueue.detailed_rejection_dialog); $(document).on("click.danbooru", ".quick-mod .detailed-rejection-link", ModQueue.detailed_rejection_dialog);
$(".delete-with-reason-link").on('click', function(e) { $(".delete-with-reason-link").on("click", function (e) {
e.preventDefault(); e.preventDefault();
const post_id = $(e.target).attr('data-post-id'); const post_id = $(e.target).attr("data-post-id");
const prompt = $(e.target).data('prompt'); const prompt = $(e.target).data("prompt");
const reason = $(e.target).data('reason'); const reason = $(e.target).data("reason");
if (confirm(`Delete post for ${prompt}?`)) if (confirm(`Delete post for ${prompt}?`))
Post.delete_with_reason(post_id, reason, true); Post.delete_with_reason(post_id, reason, true);
}); });
}); });
export default ModQueue export default ModQueue;

View File

@ -1,4 +1,4 @@
import LS from './local_storage' import LS from "./local_storage";
let NewsUpdate = {}; let NewsUpdate = {};
@ -8,12 +8,12 @@ NewsUpdate.initialize = function () {
} }
const key = parseInt($("#news").data("id"), 10); const key = parseInt($("#news").data("id"), 10);
$('#news').on('click', function () { $("#news").on("click", function () {
$('#news').toggleClass('open'); $("#news").toggleClass("open");
}); });
$('#news-closebutton').on('click', function () { $("#news-closebutton").on("click", function () {
$('#news').hide(); $("#news").hide();
LS.put('hide_news_notice', key.toString()); LS.put("hide_news_notice", key.toString());
}); });
if (parseInt(LS.get("hide_news_notice") || 0, 10) < key) { if (parseInt(LS.get("hide_news_notice") || 0, 10) < key) {
$("#news").show(); $("#news").show();
@ -24,4 +24,4 @@ $(function () {
NewsUpdate.initialize(); NewsUpdate.initialize();
}); });
export default NewsUpdate export default NewsUpdate;

View File

@ -1,31 +1,31 @@
import Utility from './utility' import Utility from "./utility";
let Note = { let Note = {
Box: { Box: {
create: function(id) { create: function (id) {
var $inner_border = $('<div/>'); var $inner_border = $("<div/>");
$inner_border.addClass("note-box-inner-border"); $inner_border.addClass("note-box-inner-border");
$inner_border.css({ $inner_border.css({
opacity: 0.5, opacity: 0.5,
}); });
var $note_box = $('<div/>'); var $note_box = $("<div/>");
$note_box.addClass("note-box"); $note_box.addClass("note-box");
$note_box.data("id", String(id)); $note_box.data("id", String(id));
$note_box.attr("data-id", String(id)); $note_box.attr("data-id", String(id));
$note_box.draggable({ $note_box.draggable({
containment: $("#image"), containment: $("#image"),
stop: function() { stop: function () {
Note.Box.update_data_attributes($note_box); Note.Box.update_data_attributes($note_box);
} },
}); });
$note_box.resizable({ $note_box.resizable({
containment: $("#image"), containment: $("#image"),
handles: "se, nw", handles: "se, nw",
stop: function() { stop: function () {
Note.Box.update_data_attributes($note_box); Note.Box.update_data_attributes($note_box);
} },
}); });
$note_box.css({position: "absolute"}); $note_box.css({position: "absolute"});
$note_box.append($inner_border); $note_box.append($inner_border);
@ -34,9 +34,9 @@ let Note = {
return $note_box; return $note_box;
}, },
update_data_attributes: function($note_box) { update_data_attributes: function ($note_box) {
var $image = $("#image"); var $image = $("#image");
var $image_container = $("#image-container") var $image_container = $("#image-container");
var ratio = $image.width() / parseFloat($image_container.data("width")); var ratio = $image.width() / parseFloat($image_container.data("width"));
var new_x = parseFloat($note_box.css("left")); var new_x = parseFloat($note_box.css("left"));
var new_y = parseFloat($note_box.css("top")); var new_y = parseFloat($note_box.css("top"));
@ -52,38 +52,38 @@ let Note = {
$note_box.data("height", new_height); $note_box.data("height", new_height);
}, },
bind_events: function($note_box) { bind_events: function ($note_box) {
$note_box.on( $note_box.on(
"dragstart.danbooru resizestart.danbooru", "dragstart.danbooru resizestart.danbooru",
function(e) { function (e) {
var $note_box_inner = $(e.currentTarget); var $note_box_inner = $(e.currentTarget);
$note_box_inner.find(".note-box-inner-border").addClass("unsaved"); $note_box_inner.find(".note-box-inner-border").addClass("unsaved");
Note.dragging = true; Note.dragging = true;
Note.clear_timeouts(); Note.clear_timeouts();
Note.Body.hide_all(); Note.Body.hide_all();
e.stopPropagation(); e.stopPropagation();
} },
); );
$note_box.on("resize.danbooru", $note_box.on("resize.danbooru",
function(e) { function (e) {
var $note_box_inner = $(e.currentTarget); var $note_box_inner = $(e.currentTarget);
Note.Box.resize_inner_border($note_box_inner); Note.Box.resize_inner_border($note_box_inner);
e.stopPropagation(); e.stopPropagation();
} },
); );
$note_box.on( $note_box.on(
"dragstop.danbooru resizestop.danbooru", "dragstop.danbooru resizestop.danbooru",
function(e) { function (e) {
Note.dragging = false; Note.dragging = false;
e.stopPropagation(); e.stopPropagation();
} },
); );
$note_box.on( $note_box.on(
"mouseover.danbooru mouseout.danbooru", "mouseover.danbooru mouseout.danbooru",
function(e) { function (e) {
if (Note.dragging) { if (Note.dragging) {
return; return;
} }
@ -106,15 +106,15 @@ let Note = {
} }
e.stopPropagation(); e.stopPropagation();
} },
); );
}, },
find: function(id) { find: function (id) {
return $("#note-container div.note-box[data-id=" + id + "]"); return $("#note-container div.note-box[data-id=" + id + "]");
}, },
show_highlighted: function($note_box) { show_highlighted: function ($note_box) {
var note_id = $note_box.data("id"); var note_id = $note_box.data("id");
Note.Body.show(note_id); Note.Body.show(note_id);
@ -123,11 +123,11 @@ let Note = {
$note_box[0].scrollIntoView(false); $note_box[0].scrollIntoView(false);
}, },
resize_inner_border: function($note_box) { resize_inner_border: function ($note_box) {
var $inner_border = $note_box.find("div.note-box-inner-border"); var $inner_border = $note_box.find("div.note-box-inner-border");
$inner_border.css({ $inner_border.css({
height: $note_box.height() - 2, height: $note_box.height() - 2,
width: $note_box.width() - 2 width: $note_box.width() - 2,
}); });
if ($inner_border.width() >= $note_box.width() - 2) { if ($inner_border.width() >= $note_box.width() - 2) {
@ -139,48 +139,48 @@ let Note = {
} }
}, },
scale: function($note_box) { scale: function ($note_box) {
var $image = $("#image"); var $image = $("#image");
var $image_container = $("#image-container") var $image_container = $("#image-container");
var ratio = $image.width() / parseFloat($image_container.data("width")); var ratio = $image.width() / parseFloat($image_container.data("width"));
var MIN_SIZE = 5; var MIN_SIZE = 5;
$note_box.css({ $note_box.css({
top: Math.ceil(parseFloat($note_box.data("y")) * ratio), top: Math.ceil(parseFloat($note_box.data("y")) * ratio),
left: Math.ceil(parseFloat($note_box.data("x")) * ratio), left: Math.ceil(parseFloat($note_box.data("x")) * ratio),
width: Math.max(MIN_SIZE, Math.ceil(parseFloat($note_box.data("width")) * ratio)), width: Math.max(MIN_SIZE, Math.ceil(parseFloat($note_box.data("width")) * ratio)),
height: Math.max(MIN_SIZE, Math.ceil(parseFloat($note_box.data("height")) * ratio)) height: Math.max(MIN_SIZE, Math.ceil(parseFloat($note_box.data("height")) * ratio)),
}); });
Note.Box.resize_inner_border($note_box); Note.Box.resize_inner_border($note_box);
}, },
scale_all: function() { scale_all: function () {
var $container = $("#note-container"); var $container = $("#note-container");
if ($container.length === 0) { if ($container.length === 0) {
return; return;
} }
// Hide notes while rescaling, to prevent unnecessary reflowing // Hide notes while rescaling, to prevent unnecessary reflowing
$container.data("resizing", true); $container.data("resizing", true);
$(".note-box").each(function(i, v) { $(".note-box").each(function (i, v) {
Note.Box.scale($(v)); Note.Box.scale($(v));
}); });
$container.data("resizing", false); $container.data("resizing", false);
}, },
toggle_all: function() { toggle_all: function () {
var $note_container = $("#note-container"); var $note_container = $("#note-container");
var is_hidden = ($note_container.css('visibility') === 'hidden'); var is_hidden = ($note_container.css("visibility") === "hidden");
if (is_hidden) { if (is_hidden) {
$note_container.css('visibility', 'visible'); $note_container.css("visibility", "visible");
} else { } else {
$note_container.css('visibility', 'hidden'); $note_container.css("visibility", "hidden");
} }
} },
}, },
Body: { Body: {
create: function(id) { create: function (id) {
var $note_body = $('<div></div>'); var $note_body = $("<div></div>");
$note_body.addClass("note-body"); $note_body.addClass("note-body");
$note_body.data("id", String(id)); $note_body.data("id", String(id));
$note_body.attr("data-id", String(id)); $note_body.attr("data-id", String(id));
@ -189,52 +189,54 @@ let Note = {
return $note_body; return $note_body;
}, },
initialize: function($note_body) { initialize: function ($note_body) {
var $note_box = Note.Box.find($note_body.data("id")); var $note_box = Note.Box.find($note_body.data("id"));
$note_body.css({ $note_body.css({
top: $note_box.position().top + $note_box.height() + 5, top: $note_box.position().top + $note_box.height() + 5,
left: $note_box.position().left left: $note_box.position().left,
}); });
Note.Body.bound_position($note_body); Note.Body.bound_position($note_body);
}, },
bound_position: function($note_body) { bound_position: function ($note_body) {
var $image = $("#image"); var $image = $("#image");
var doc_width = $image.offset().left + $image.width(); var doc_width = $image.offset().left + $image.width();
if ($note_body.offset().left + $note_body.width() > doc_width) { if ($note_body.offset().left + $note_body.width() > doc_width) {
$note_body.css({ $note_body.css({
left: $note_body.position().left - 10 - ($note_body.offset().left + $note_body.width() - doc_width) left: $note_body.position().left - 10 - ($note_body.offset().left + $note_body.width() - doc_width),
}); });
} }
}, },
show: function(id) { show: function (id) {
Note.Body.hide_all(); Note.Body.hide_all();
Note.clear_timeouts(); Note.clear_timeouts();
var $note_body = Note.Body.find(id); var $note_body = Note.Body.find(id);
if (!$note_body.data('resized')) { if (!$note_body.data("resized")) {
Note.Body.resize($note_body); Note.Body.resize($note_body);
$note_body.data('resized', 'true'); $note_body.data("resized", "true");
} }
$note_body.show(); $note_body.show();
Note.Body.initialize($note_body); Note.Body.initialize($note_body);
}, },
find: function(id) { find: function (id) {
return $("#note-container div.note-body[data-id=" + id + "]"); return $("#note-container div.note-body[data-id=" + id + "]");
}, },
hide: function(id) { hide: function (id) {
var $note_body = Note.Body.find(id); var $note_body = Note.Body.find(id);
Note.timeouts.push(setTimeout(function() {$note_body.hide();}, 350)); Note.timeouts.push(
setTimeout(() => { $note_body.hide(); }, 350),
);
}, },
hide_all: function() { hide_all: function () {
$("#note-container div.note-body").hide(); $("#note-container div.note-body").hide();
}, },
resize: function($note_body) { resize: function ($note_body) {
$note_body.css("min-width", ""); $note_body.css("min-width", "");
var w = $note_body.width(); var w = $note_body.width();
var h = $note_body.height(); var h = $note_body.height();
@ -269,7 +271,7 @@ let Note = {
x = (lo + hi) / 2; x = (lo + hi) / 2;
$note_body.css("min-width", x); $note_body.css("min-width", x);
if ($note_body.height() > h) { if ($note_body.height() > h) {
lo = x lo = x;
} else { } else {
hi = x; hi = x;
} }
@ -280,31 +282,31 @@ let Note = {
} }
}, },
set_text: function($note_body, $note_box, text) { set_text: function ($note_body, $note_box, text) {
Note.Body.display_text($note_body, text); Note.Body.display_text($note_body, text);
Note.Body.resize($note_body); Note.Body.resize($note_body);
Note.Body.bound_position($note_body); Note.Body.bound_position($note_body);
}, },
display_text: function($note_body, text) { display_text: function ($note_body, text) {
$note_body.html(text); $note_body.html(text);
}, },
bind_events: function($note_body) { bind_events: function ($note_body) {
$note_body.on("mouseover.danbooru", function(e) { $note_body.on("mouseover.danbooru", function (e) {
var $note_body_inner = $(e.currentTarget); var $note_body_inner = $(e.currentTarget);
Note.Body.show($note_body_inner.data("id")); Note.Body.show($note_body_inner.data("id"));
e.stopPropagation(); e.stopPropagation();
}); });
$note_body.on("mouseout.danbooru", function(e) { $note_body.on("mouseout.danbooru", function (e) {
var $note_body_inner = $(e.currentTarget); var $note_body_inner = $(e.currentTarget);
Note.Body.hide($note_body_inner.data("id")); Note.Body.hide($note_body_inner.data("id"));
e.stopPropagation(); e.stopPropagation();
}); });
if (Utility.meta("current-user-name") !== "Anonymous") { if (Utility.meta("current-user-name") !== "Anonymous") {
$note_body.on("click.danbooru", function(e) { $note_body.on("click.danbooru", function (e) {
if (e.target.tagName !== "A") { if (e.target.tagName !== "A") {
var $note_body_inner = $(e.currentTarget); var $note_body_inner = $(e.currentTarget);
Note.Edit.show($note_body_inner); Note.Edit.show($note_body_inner);
@ -312,18 +314,18 @@ let Note = {
e.stopPropagation(); e.stopPropagation();
}); });
} else { } else {
$note_body.on("click.danbooru", function(e) { $note_body.on("click.danbooru", function (e) {
if (e.target.tagName !== "A") { if (e.target.tagName !== "A") {
Utility.error("You must be logged in to edit notes"); Utility.error("You must be logged in to edit notes");
} }
e.stopPropagation(); e.stopPropagation();
}); });
} }
} },
}, },
Edit: { Edit: {
show: function($note_body) { show: function ($note_body) {
var id = $note_body.data("id"); var id = $note_body.data("id");
if (Note.editing) { if (Note.editing) {
@ -333,7 +335,7 @@ let Note = {
$(".note-box").resizable("disable"); $(".note-box").resizable("disable");
$(".note-box").draggable("disable"); $(".note-box").draggable("disable");
let $textarea = $('<textarea></textarea>'); let $textarea = $("<textarea></textarea>");
$textarea.css({ $textarea.css({
width: "97%", width: "97%",
height: "92%", height: "92%",
@ -344,7 +346,7 @@ let Note = {
$textarea.val($note_body.data("original-body")); $textarea.val($note_body.data("original-body"));
} }
let $dialog = $('<div></div>'); let $dialog = $("<div></div>");
$dialog.append($textarea); $dialog.append($textarea);
$dialog.data("id", id); $dialog.data("id", id);
$dialog.dialog({ $dialog.dialog({
@ -353,7 +355,7 @@ let Note = {
position: { position: {
my: "right", my: "right",
at: "right-20", at: "right-20",
of: window of: window,
}, },
classes: { classes: {
"ui-dialog": "note-edit-dialog", "ui-dialog": "note-edit-dialog",
@ -364,15 +366,15 @@ let Note = {
"Preview": Note.Edit.preview, "Preview": Note.Edit.preview,
"Cancel": Note.Edit.cancel, "Cancel": Note.Edit.cancel,
"Delete": Note.Edit.destroy, "Delete": Note.Edit.destroy,
"History": Note.Edit.history "History": Note.Edit.history,
} },
}); });
$dialog.data("uiDialog")._title = function(title) { $dialog.data("uiDialog")._title = function (title) {
title.html(this.options.title); // Allow unescaped html in dialog title title.html(this.options.title); // Allow unescaped html in dialog title
} };
$dialog.dialog("option", "title", 'Edit note #' + id + ' (<a href="/wiki_pages/e621:notes">view help</a>)'); $dialog.dialog("option", "title", "Edit note #" + id + " (<a href=\"/wiki_pages/e621:notes\">view help</a>)");
$dialog.on("dialogclose.danbooru", function() { $dialog.on("dialogclose.danbooru", function () {
Note.editing = false; Note.editing = false;
$(".note-box").resizable("enable"); $(".note-box").resizable("enable");
$(".note-box").draggable("enable"); $(".note-box").draggable("enable");
@ -382,7 +384,7 @@ let Note = {
Note.editing = true; Note.editing = true;
}, },
parameterize_note: function($note_box, $note_body) { parameterize_note: function ($note_box, $note_body) {
var $image = $("#image"); var $image = $("#image");
var $image_container = $("#image-container"); var $image_container = $("#image-container");
var original_width = parseInt($image_container.data("width")); var original_width = parseInt($image_container.data("width"));
@ -395,8 +397,8 @@ let Note = {
width: $note_box.width() / ratio, width: $note_box.width() / ratio,
height: $note_box.height() / ratio, height: $note_box.height() / ratio,
body: $note_body.data("original-body"), body: $note_body.data("original-body"),
} },
} };
if ($note_box.data("id").match(/x/)) { if ($note_box.data("id").match(/x/)) {
hash.note.html_id = $note_box.data("id"); hash.note.html_id = $note_box.data("id");
@ -406,11 +408,11 @@ let Note = {
return hash; return hash;
}, },
error_handler: function(xhr) { error_handler: function (xhr) {
Utility.error("Error: " + (xhr.responseJSON.reason || xhr.responseJSON.reasons.join("; "))); Utility.error("Error: " + (xhr.responseJSON.reason || xhr.responseJSON.reasons.join("; ")));
}, },
success_handler: function(data) { success_handler: function (data) {
var $note_box = null; var $note_box = null;
if (data.html_id) { // new note if (data.html_id) { // new note
@ -425,7 +427,7 @@ let Note = {
} }
}, },
save: function() { save: function () {
var $this = $(this); var $this = $(this);
var $textarea = $this.find("textarea"); var $textarea = $this.find("textarea");
var id = $this.data("id"); var id = $this.data("id");
@ -434,7 +436,7 @@ let Note = {
var text = $textarea.val(); var text = $textarea.val();
$note_body.data("original-body", text); $note_body.data("original-body", text);
Note.Body.set_text($note_body, $note_box, "Loading..."); Note.Body.set_text($note_body, $note_box, "Loading...");
$.post("/dtext_preview.json", {body: text}).then(function(data) { $.post("/dtext_preview.json", {body: text}).then(function (data) {
Note.Body.set_text($note_body, $note_box, data.html); Note.Body.set_text($note_body, $note_box, data.html);
Note.Box.resize_inner_border($note_box); Note.Box.resize_inner_border($note_box);
$note_body.show(); $note_body.show();
@ -447,19 +449,19 @@ let Note = {
type: "PUT", type: "PUT",
data: Note.Edit.parameterize_note($note_box, $note_body), data: Note.Edit.parameterize_note($note_box, $note_body),
error: Note.Edit.error_handler, error: Note.Edit.error_handler,
success: Note.Edit.success_handler success: Note.Edit.success_handler,
}); });
} else { } else {
$.ajax("/notes.json", { $.ajax("/notes.json", {
type: "POST", type: "POST",
data: Note.Edit.parameterize_note($note_box, $note_body), data: Note.Edit.parameterize_note($note_box, $note_body),
error: Note.Edit.error_handler, error: Note.Edit.error_handler,
success: Note.Edit.success_handler success: Note.Edit.success_handler,
}); });
} }
}, },
preview: function() { preview: function () {
var $this = $(this); var $this = $(this);
var $textarea = $this.find("textarea"); var $textarea = $this.find("textarea");
var id = $this.data("id"); var id = $this.data("id");
@ -468,20 +470,20 @@ let Note = {
var $note_box = Note.Box.find(id); var $note_box = Note.Box.find(id);
$note_box.find(".note-box-inner-border").addClass("unsaved"); $note_box.find(".note-box-inner-border").addClass("unsaved");
Note.Body.set_text($note_body, $note_box, "Loading..."); Note.Body.set_text($note_body, $note_box, "Loading...");
$.post("/dtext_preview.json", {body: text}).then(function(data) { $.post("/dtext_preview.json", {body: text}).then(function (data) {
Note.Body.set_text($note_body, $note_box, data.html); Note.Body.set_text($note_body, $note_box, data.html);
$note_body.show(); $note_body.show();
$(window).trigger("e621:add_deferred_posts", data.posts); $(window).trigger("e621:add_deferred_posts", data.posts);
}); });
}, },
cancel: function() { cancel: function () {
$(this).dialog("close"); $(this).dialog("close");
}, },
destroy: function() { destroy: function () {
if (!confirm("Do you really want to delete this note?")) { if (!confirm("Do you really want to delete this note?")) {
return return;
} }
var $this = $(this); var $this = $(this);
@ -490,29 +492,29 @@ let Note = {
if (id.match(/\d/)) { if (id.match(/\d/)) {
$.ajax("/notes/" + id + ".json", { $.ajax("/notes/" + id + ".json", {
type: "DELETE", type: "DELETE",
success: function() { success: function () {
Note.Box.find(id).remove(); Note.Box.find(id).remove();
Note.Body.find(id).remove(); Note.Body.find(id).remove();
$this.dialog("close"); $this.dialog("close");
} },
}); });
} }
}, },
history: function() { history: function () {
var $this = $(this); var $this = $(this);
var id = $this.data("id"); var id = $this.data("id");
if (id.match(/\d/)) { if (id.match(/\d/)) {
window.location.href = "/note_versions?search[note_id]=" + id; window.location.href = "/note_versions?search[note_id]=" + id;
} }
$(this).dialog("close"); $(this).dialog("close");
} },
}, },
TranslationMode: { TranslationMode: {
active: false, active: false,
toggle: function(e) { toggle: function (e) {
if (Note.TranslationMode.active) { if (Note.TranslationMode.active) {
Note.TranslationMode.stop(e); Note.TranslationMode.stop(e);
} else { } else {
@ -520,7 +522,7 @@ let Note = {
} }
}, },
start: function(e) { start: function (e) {
e.preventDefault(); e.preventDefault();
if (Utility.meta("current-user-id") === "") { if (Utility.meta("current-user-id") === "") {
@ -541,11 +543,11 @@ let Note = {
$(document).on("mouseup.danbooru.note", Note.TranslationMode.Drag.stop); $(document).on("mouseup.danbooru.note", Note.TranslationMode.Drag.stop);
$("#mark-as-translated-section").show(); $("#mark-as-translated-section").show();
Utility.notice('Translation mode is on. Drag on the image to create notes. <a href="#">Turn translation mode off</a> (shortcut is <span class="key">n</span>).'); Utility.notice("Translation mode is on. Drag on the image to create notes. <a href=\"#\">Turn translation mode off</a> (shortcut is <span class=\"key\">n</span>).");
$("#notice a:contains(Turn translation mode off)").on("click.danbooru", Note.TranslationMode.stop); $("#notice a:contains(Turn translation mode off)").on("click.danbooru", Note.TranslationMode.stop);
}, },
stop: function(e) { stop: function (e) {
e.preventDefault(); e.preventDefault();
Note.TranslationMode.active = false; Note.TranslationMode.active = false;
@ -558,7 +560,7 @@ let Note = {
$("#mark-as-translated-section").hide(); $("#mark-as-translated-section").hide();
}, },
create_note: function(e, x, y, w, h) { create_note: function (e, x, y, w, h) {
var offset = $("#image").offset(); var offset = $("#image").offset();
if (w > 9 || h > 9) { /* minimum note size: 10px */ if (w > 9 || h > 9) { /* minimum note size: 10px */
@ -570,7 +572,7 @@ let Note = {
Note.create(x - offset.left, y - offset.top, w, h); Note.create(x - offset.left, y - offset.top, w, h);
} }
$("#note-container").css('visibility', 'visible'); $("#note-container").css("visibility", "visible");
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
}, },
@ -638,12 +640,12 @@ let Note = {
Note.TranslationMode.Drag.h = -Note.TranslationMode.Drag.dragDistanceY; Note.TranslationMode.Drag.h = -Note.TranslationMode.Drag.dragDistanceY;
} }
$('#note-preview').css({ $("#note-preview").css({
display: 'block', display: "block",
left: (Note.TranslationMode.Drag.x + 1), left: (Note.TranslationMode.Drag.x + 1),
top: (Note.TranslationMode.Drag.y + 1), top: (Note.TranslationMode.Drag.y + 1),
width: (Note.TranslationMode.Drag.w - 3), width: (Note.TranslationMode.Drag.w - 3),
height: (Note.TranslationMode.Drag.h - 3) height: (Note.TranslationMode.Drag.h - 3),
}); });
} }
}, },
@ -658,7 +660,7 @@ let Note = {
$(document).off("mousemove", Note.TranslationMode.Drag.drag); $(document).off("mousemove", Note.TranslationMode.Drag.drag);
if (Note.TranslationMode.Drag.dragging) { if (Note.TranslationMode.Drag.dragging) {
$('#note-preview').css({ display: 'none' }); $("#note-preview").css({ display: "none" });
Note.TranslationMode.create_note(e, Note.TranslationMode.Drag.x, Note.TranslationMode.Drag.y, Note.TranslationMode.Drag.w - 1, Note.TranslationMode.Drag.h - 1); Note.TranslationMode.create_note(e, Note.TranslationMode.Drag.x, Note.TranslationMode.Drag.y, Note.TranslationMode.Drag.w - 1, Note.TranslationMode.Drag.h - 1);
Note.TranslationMode.Drag.dragging = false; /* border of the note is pixel-perfect on the preview border */ Note.TranslationMode.Drag.dragging = false; /* border of the note is pixel-perfect on the preview border */
} else { /* no dragging -> toggle display of notes */ } else { /* no dragging -> toggle display of notes */
@ -667,8 +669,8 @@ let Note = {
Note.TranslationMode.Drag.dragStartX = 0; Note.TranslationMode.Drag.dragStartX = 0;
Note.TranslationMode.Drag.dragStartY = 0; Note.TranslationMode.Drag.dragStartY = 0;
} },
} },
}, },
id: "x", id: "x",
@ -677,14 +679,14 @@ let Note = {
timeouts: [], timeouts: [],
pending: {}, pending: {},
add: function(container, id, x, y, w, h, original_body, sanitized_body) { add: function (container, id, x, y, w, h, original_body, sanitized_body) {
var $note_box = Note.Box.create(id); var $note_box = Note.Box.create(id);
var $note_body = Note.Body.create(id); var $note_body = Note.Body.create(id);
$note_box.data('x', x); $note_box.data("x", x);
$note_box.data('y', y); $note_box.data("y", y);
$note_box.data('width', w); $note_box.data("width", w);
$note_box.data('height', h); $note_box.data("height", h);
container.appendChild($note_box[0]); container.appendChild($note_box[0]);
container.appendChild($note_body[0]); container.appendChild($note_body[0]);
$note_body.data("original-body", original_body); $note_body.data("original-body", original_body);
@ -692,14 +694,14 @@ let Note = {
Note.Body.display_text($note_body, sanitized_body); Note.Body.display_text($note_body, sanitized_body);
}, },
create: function(x, y, w, h) { create: function (x, y, w, h) {
var $note_box = Note.Box.create(Note.id); var $note_box = Note.Box.create(Note.id);
var $note_body = Note.Body.create(Note.id); var $note_body = Note.Body.create(Note.id);
$note_box.css({ $note_box.css({
top: y, top: y,
left: x, left: x,
width: w, width: w,
height: h height: h,
}); });
Note.Box.update_data_attributes($note_box); Note.Box.update_data_attributes($note_box);
$note_box.find(".note-box-inner-border").addClass("unsaved"); $note_box.find(".note-box-inner-border").addClass("unsaved");
@ -710,17 +712,17 @@ let Note = {
Note.id += "x"; Note.id += "x";
}, },
clear_timeouts: function() { clear_timeouts: function () {
$.each(Note.timeouts, function(i, v) { $.each(Note.timeouts, function (i, v) {
clearTimeout(v); clearTimeout(v);
}); });
Note.timeouts = []; Note.timeouts = [];
}, },
load_all: function() { load_all: function () {
var fragment = document.createDocumentFragment(); var fragment = document.createDocumentFragment();
$.each($("#notes article"), function(i, article) { $.each($("#notes article"), function (i, article) {
var $article = $(article); var $article = $(article);
Note.add( Note.add(
fragment, fragment,
@ -730,13 +732,13 @@ let Note = {
$article.data("width"), $article.data("width"),
$article.data("height"), $article.data("height"),
$article.data("body"), $article.data("body"),
$article.html() $article.html(),
); );
}); });
$("#note-container").append(fragment); $("#note-container").append(fragment);
}, },
initialize_all: function() { initialize_all: function () {
if ($("#c-posts #a-show #image").length === 0 || $("video#image").length) { if ($("#c-posts #a-show #image").length === 0 || $("video#image").length) {
return; return;
} }
@ -748,12 +750,12 @@ let Note = {
$(document).on("hashchange.danbooru.note", this.initialize_highlight); $(document).on("hashchange.danbooru.note", this.initialize_highlight);
}, },
initialize_shortcuts: function() { initialize_shortcuts: function () {
$("#translate").on("click.danbooru", Note.TranslationMode.toggle); $("#translate").on("click.danbooru", Note.TranslationMode.toggle);
$("#image").on("click.danbooru", Note.Box.toggle_all); $("#image").on("click.danbooru", Note.Box.toggle_all);
}, },
initialize_highlight: function() { initialize_highlight: function () {
var matches = window.location.hash.match(/^#note-(\d+)$/); var matches = window.location.hash.match(/^#note-(\d+)$/);
if (matches) { if (matches) {
@ -761,10 +763,10 @@ let Note = {
Note.Box.show_highlighted($note_box); Note.Box.show_highlighted($note_box);
} }
}, },
} };
$(function() { $(function () {
Note.initialize_all(); Note.initialize_all();
}); });
export default Note export default Note;

View File

@ -4,7 +4,7 @@ let Pool = {};
Pool.dialog_setup = false; Pool.dialog_setup = false;
Pool.initialize_all = function() { Pool.initialize_all = function () {
if ($("#c-posts").length && $("#a-show").length) { if ($("#c-posts").length && $("#a-show").length) {
this.initialize_add_to_pool_link(); this.initialize_add_to_pool_link();
} }
@ -14,8 +14,8 @@ Pool.initialize_all = function() {
} }
}; };
Pool.initialize_add_to_pool_link = function() { Pool.initialize_add_to_pool_link = function () {
$("#pool").on("click.danbooru", function(e) { $("#pool").on("click.danbooru", function (e) {
if (!Pool.dialog_setup) { if (!Pool.dialog_setup) {
$("#add-to-pool-dialog").dialog({autoOpen: false}); $("#add-to-pool-dialog").dialog({autoOpen: false});
Pool.dialog_setup = true; Pool.dialog_setup = true;
@ -24,34 +24,34 @@ Pool.initialize_add_to_pool_link = function() {
$("#add-to-pool-dialog").dialog("open"); $("#add-to-pool-dialog").dialog("open");
}); });
$("#recent-pools li").on("click.danbooru", function(e) { $("#recent-pools li").on("click.danbooru", function (e) {
e.preventDefault(); e.preventDefault();
$("#pool_name").val($(this).attr("data-value")); $("#pool_name").val($(this).attr("data-value"));
}); });
} };
Pool.initialize_simple_edit = function() { Pool.initialize_simple_edit = function () {
$("#sortable").sortable({ $("#sortable").sortable({
placeholder: "ui-state-placeholder" placeholder: "ui-state-placeholder",
}); });
$("#sortable").disableSelection(); $("#sortable").disableSelection();
$("#ordering-form").submit(function(e) { $("#ordering-form").submit(function (e) {
e.preventDefault(); e.preventDefault();
$.ajax({ $.ajax({
type: "post", type: "post",
url: e.target.action, url: e.target.action,
data: $("#sortable").sortable("serialize") + "&" + $(e.target).serialize() + "&format=json" data: $("#sortable").sortable("serialize") + "&" + $(e.target).serialize() + "&format=json",
}).done(() => { }).done(() => {
window.location.href = e.target.action; window.location.href = e.target.action;
}).fail((data) => { }).fail((data) => {
Utility.error(`Error: ${data.responseText}`); Utility.error(`Error: ${data.responseText}`);
}); });
}); });
} };
$(document).ready(function() { $(document).ready(function () {
Pool.initialize_all(); Pool.initialize_all();
}); });
export default Pool export default Pool;

View File

@ -1,6 +1,6 @@
let PostDeletion = {}; let PostDeletion = {};
PostDeletion.init = function() { PostDeletion.init = function () {
const input = $("#reason"); const input = $("#reason");
let inputVal = input.val() + ""; let inputVal = input.val() + "";
@ -37,7 +37,7 @@ PostDeletion.init = function() {
const $button = $(element); const $button = $(element);
$button.find("input[type=text]").on("input", () => { $button.find("input[type=text]").on("input", () => {
$button.trigger("e621:refresh"); $button.trigger("e621:refresh");
}) });
}); });
buttons.trigger("e621:refresh"); buttons.trigger("e621:refresh");
@ -49,11 +49,11 @@ PostDeletion.init = function() {
$("#delreason-clear").on("click", () => { $("#delreason-clear").on("click", () => {
input.val("").trigger("input"); input.val("").trigger("input");
}); });
} };
$(function() { $(function () {
if($("div#c-confirm-delete").length) if ($("div#c-confirm-delete").length)
Danbooru.PostDeletion.init(); Danbooru.PostDeletion.init();
}); });
export default PostDeletion export default PostDeletion;

View File

@ -1,16 +1,16 @@
import Utility from './utility' import Utility from "./utility";
import LS from './local_storage' import LS from "./local_storage";
import Post from './posts' import Post from "./posts";
import Favorite from './favorites' import Favorite from "./favorites";
import PostSet from './post_sets' import PostSet from "./post_sets";
import TagScript from './tag_script' import TagScript from "./tag_script";
import { SendQueue } from './send_queue' import { SendQueue } from "./send_queue";
import Rails from '@rails/ujs' import Rails from "@rails/ujs";
import Shortcuts from './shortcuts' import Shortcuts from "./shortcuts";
let PostModeMenu = {}; let PostModeMenu = {};
PostModeMenu.initialize = function() { PostModeMenu.initialize = function () {
if ($("#c-posts").length || $("#c-favorites").length || $("#c-pools").length) { if ($("#c-posts").length || $("#c-favorites").length || $("#c-pools").length) {
this.initialize_selector(); this.initialize_selector();
this.initialize_preview_link(); this.initialize_preview_link();
@ -19,17 +19,17 @@ PostModeMenu.initialize = function() {
this.initialize_shortcuts(); this.initialize_shortcuts();
PostModeMenu.change(); PostModeMenu.change();
} }
} };
PostModeMenu.initialize_shortcuts = function() { PostModeMenu.initialize_shortcuts = function () {
Shortcuts.keydown("1 2 3 4 5 6 7 8 9 0", "change_tag_script", PostModeMenu.change_tag_script); Shortcuts.keydown("1 2 3 4 5 6 7 8 9 0", "change_tag_script", PostModeMenu.change_tag_script);
} };
PostModeMenu.show_notice = function(i) { PostModeMenu.show_notice = function (i) {
Utility.notice("Switched to tag script #" + i + ". To switch tag scripts, use the number keys."); Utility.notice("Switched to tag script #" + i + ". To switch tag scripts, use the number keys.");
} };
PostModeMenu.change_tag_script = function(e) { PostModeMenu.change_tag_script = function (e) {
if ($("#mode-box-mode").val() === "tag-script") { if ($("#mode-box-mode").val() === "tag-script") {
const old_tag_script_id = LS.get("current_tag_script_id") || "1"; const old_tag_script_id = LS.get("current_tag_script_id") || "1";
@ -44,9 +44,9 @@ PostModeMenu.change_tag_script = function(e) {
e.preventDefault(); e.preventDefault();
} }
} };
PostModeMenu.initialize_selector = function() { PostModeMenu.initialize_selector = function () {
if (!LS.get("mode")) { if (!LS.get("mode")) {
LS.put("mode", "view"); LS.put("mode", "view");
$("#mode-box-mode").val("view"); $("#mode-box-mode").val("view");
@ -54,82 +54,82 @@ PostModeMenu.initialize_selector = function() {
$("#mode-box-mode").val(LS.get("mode")); $("#mode-box-mode").val(LS.get("mode"));
} }
$("#mode-box-mode").on("change.danbooru", function() { $("#mode-box-mode").on("change.danbooru", function () {
PostModeMenu.change(); PostModeMenu.change();
$("#tag-script-field:visible").focus().select(); $("#tag-script-field:visible").focus().select();
}); });
} };
PostModeMenu.initialize_preview_link = function() { PostModeMenu.initialize_preview_link = function () {
$(".post-preview a").on("click.danbooru", PostModeMenu.click); $(".post-preview a").on("click.danbooru", PostModeMenu.click);
} };
PostModeMenu.initialize_edit_form = function() { PostModeMenu.initialize_edit_form = function () {
$("#quick-edit-div").hide(); $("#quick-edit-div").hide();
$("#quick-edit-form input[value=Cancel]").on("click.danbooru", function(e) { $("#quick-edit-form input[value=Cancel]").on("click.danbooru", function (e) {
PostModeMenu.close_edit_form(); PostModeMenu.close_edit_form();
e.preventDefault(); e.preventDefault();
}); });
$("#quick-edit-form").on("submit.danbooru", function(e) { $("#quick-edit-form").on("submit.danbooru", function (e) {
$.ajax({ $.ajax({
type: "put", type: "put",
url: $("#quick-edit-form").attr("action"), url: $("#quick-edit-form").attr("action"),
data: { data: {
post: { post: {
tag_string: $("#post_tag_string").val() tag_string: $("#post_tag_string").val(),
} },
}, },
complete: function() { complete: function () {
Rails.enableElement(document.getElementById("quick-edit-form")); Rails.enableElement(document.getElementById("quick-edit-form"));
}, },
success: function(data) { success: function (data) {
Post.update_data(data); Post.update_data(data);
Utility.notice("Post #" + data.post.id + " updated"); Utility.notice("Post #" + data.post.id + " updated");
PostModeMenu.close_edit_form(); PostModeMenu.close_edit_form();
} },
}); });
e.preventDefault(); e.preventDefault();
}); });
} };
PostModeMenu.close_edit_form = function() { PostModeMenu.close_edit_form = function () {
Shortcuts.disabled = false; Shortcuts.disabled = false;
$("#quick-edit-div").slideUp("fast"); $("#quick-edit-div").slideUp("fast");
if (Utility.meta("enable-auto-complete") === "true") { if (Utility.meta("enable-auto-complete") === "true") {
$("#post_tag_string").data("uiAutocomplete").close(); $("#post_tag_string").data("uiAutocomplete").close();
} }
} };
PostModeMenu.initialize_tag_script_field = function() { PostModeMenu.initialize_tag_script_field = function () {
$("#tag-script-field").blur(function() { $("#tag-script-field").blur(function () {
const script = $(this).val(); const script = $(this).val();
const current_script_id = LS.get("current_tag_script_id"); const current_script_id = LS.get("current_tag_script_id");
LS.put("tag-script-" + current_script_id, script); LS.put("tag-script-" + current_script_id, script);
}); });
} };
PostModeMenu.update_sets_menu = function() { PostModeMenu.update_sets_menu = function () {
let target = $('#set-id'); let target = $("#set-id");
target.off('change'); target.off("change");
SendQueue.add(function() { SendQueue.add(function () {
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: "/post_sets/for_select.json", url: "/post_sets/for_select.json",
}).fail(function(data) { }).fail(function (data) {
$(window).trigger('danbooru:error', "Error getting sets list: " + data.message); $(window).trigger("danbooru:error", "Error getting sets list: " + data.message);
}).done(function(data) { }).done(function (data) {
target.on('change', function(e) { target.on("change", function (e) {
LS.put('set', e.target.value); LS.put("set", e.target.value);
}); });
target.empty(); target.empty();
const target_set = LS.get('set') || 0; const target_set = LS.get("set") || 0;
['Owned', "Maintained"].forEach(function(v) { ["Owned", "Maintained"].forEach(function (v) {
let group = $('<optgroup>', {label: v}); let group = $("<optgroup>", {label: v});
data[v].forEach(function(gi) { data[v].forEach(function (gi) {
group.append($('<option>', {value: gi[1], selected: (gi[1] == target_set)}).text(gi[0])); group.append($("<option>", {value: gi[1], selected: (gi[1] == target_set)}).text(gi[0]));
}); });
target.append(group); target.append(group);
}); });
@ -137,7 +137,7 @@ PostModeMenu.update_sets_menu = function() {
}); });
}; };
PostModeMenu.change = function() { PostModeMenu.change = function () {
$("#quick-edit-div").slideUp("fast"); $("#quick-edit-div").slideUp("fast");
const s = $("#mode-box-mode").val(); const s = $("#mode-box-mode").val();
if (s === undefined) { if (s === undefined) {
@ -159,15 +159,15 @@ PostModeMenu.change = function() {
$("#tag-script-field").val(script).show(); $("#tag-script-field").val(script).show();
PostModeMenu.show_notice(current_script_id); PostModeMenu.show_notice(current_script_id);
} else if (s === 'add-to-set' || s === 'remove-from-set') { } else if (s === "add-to-set" || s === "remove-from-set") {
PostModeMenu.update_sets_menu(); PostModeMenu.update_sets_menu();
$("#set-id").show(); $("#set-id").show();
} else if (s === 'delete') { } else if (s === "delete") {
$("#quick-mode-reason").show(); $("#quick-mode-reason").show();
} }
} };
PostModeMenu.open_edit = function(post_id) { PostModeMenu.open_edit = function (post_id) {
Shortcuts.disabled = true; Shortcuts.disabled = true;
var $post = $("#post_" + post_id); var $post = $("#post_" + post_id);
$("#quick-edit-div").slideDown("fast"); $("#quick-edit-div").slideDown("fast");
@ -179,9 +179,9 @@ PostModeMenu.open_edit = function(post_id) {
var padding = $("#post_tag_string").innerHeight() - $("#post_tag_string").height(); var padding = $("#post_tag_string").innerHeight() - $("#post_tag_string").height();
var height = $("#post_tag_string").prop("scrollHeight") - padding; var height = $("#post_tag_string").prop("scrollHeight") - padding;
$("#post_tag_string").height(height); $("#post_tag_string").height(height);
} };
PostModeMenu.click = function(e) { PostModeMenu.click = function (e) {
var s = $("#mode-box-mode").val(); var s = $("#mode-box-mode").val();
var post_id = $(e.target).closest("article").data("id"); var post_id = $(e.target).closest("article").data("id");
@ -191,33 +191,33 @@ PostModeMenu.click = function(e) {
Favorite.destroy(post_id); Favorite.destroy(post_id);
} else if (s === "edit") { } else if (s === "edit") {
PostModeMenu.open_edit(post_id); PostModeMenu.open_edit(post_id);
} else if (s === 'vote-down') { } else if (s === "vote-down") {
Post.vote(post_id, -1, true); Post.vote(post_id, -1, true);
} else if (s === 'vote-up') { } else if (s === "vote-up") {
Post.vote(post_id, 1, true); Post.vote(post_id, 1, true);
} else if (s === 'add-to-set') { } else if (s === "add-to-set") {
PostSet.add_post($("#set-id").val(), post_id); PostSet.add_post($("#set-id").val(), post_id);
} else if (s === 'remove-from-set') { } else if (s === "remove-from-set") {
PostSet.remove_post($("#set-id").val(), post_id); PostSet.remove_post($("#set-id").val(), post_id);
} else if (s === 'rating-q') { } else if (s === "rating-q") {
Post.update(post_id, {"post[rating]": "q"}) Post.update(post_id, {"post[rating]": "q"});
} else if (s === 'rating-s') { } else if (s === "rating-s") {
Post.update(post_id, {"post[rating]": "s"}) Post.update(post_id, {"post[rating]": "s"});
} else if (s === 'rating-e') { } else if (s === "rating-e") {
Post.update(post_id, {"post[rating]": "e"}) Post.update(post_id, {"post[rating]": "e"});
} else if (s === 'lock-rating') { } else if (s === "lock-rating") {
Post.update(post_id, {"post[is_rating_locked]": "1"}); Post.update(post_id, {"post[is_rating_locked]": "1"});
} else if (s === 'lock-note') { } else if (s === "lock-note") {
Post.update(post_id, {"post[is_note_locked]": "1"}); Post.update(post_id, {"post[is_note_locked]": "1"});
} else if (s === 'delete') { } else if (s === "delete") {
Post.delete_with_reason(post_id, $("#quick-mode-reason").val(), false); Post.delete_with_reason(post_id, $("#quick-mode-reason").val(), false);
} else if (s === 'undelete') { } else if (s === "undelete") {
Post.undelete(post_id); Post.undelete(post_id);
} else if (s === 'unflag') { } else if (s === "unflag") {
Post.unflag(post_id, "none", false); Post.unflag(post_id, "none", false);
} else if (s === 'approve') { } else if (s === "approve") {
Post.approve(post_id); Post.approve(post_id);
} else if (s === 'remove-parent') { } else if (s === "remove-parent") {
Post.update(post_id, {"post[parent_id]": ""}); Post.update(post_id, {"post[parent_id]": ""});
} else if (s === "tag-script") { } else if (s === "tag-script") {
const current_script_id = LS.get("current_tag_script_id"); const current_script_id = LS.get("current_tag_script_id");
@ -226,7 +226,7 @@ PostModeMenu.click = function(e) {
e.preventDefault(); e.preventDefault();
return; return;
} }
const postTags = $("#post_" + post_id).data('tags').split(' '); const postTags = $("#post_" + post_id).data("tags").split(" ");
const tags = new Set(postTags); const tags = new Set(postTags);
const changes = TagScript.run(tags, tag_script); const changes = TagScript.run(tags, tag_script);
Post.tagScript(post_id, changes); Post.tagScript(post_id, changes);
@ -235,10 +235,10 @@ PostModeMenu.click = function(e) {
} }
e.preventDefault(); e.preventDefault();
} };
$(function() { $(function () {
PostModeMenu.initialize(); PostModeMenu.initialize();
}); });
export default PostModeMenu export default PostModeMenu;

View File

@ -1,4 +1,4 @@
import Utility from './utility' import Utility from "./utility";
let PostReplacement = {}; let PostReplacement = {};
@ -29,9 +29,9 @@ PostReplacement.approve = function (id, penalize_current_uploader) {
type: "PUT", type: "PUT",
url: `/post_replacements/${id}/approve.json`, url: `/post_replacements/${id}/approve.json`,
data: { data: {
penalize_current_uploader: penalize_current_uploader penalize_current_uploader: penalize_current_uploader,
}, },
dataType: 'json' dataType: "json",
}).done(function () { }).done(function () {
set_status($row, "approved"); set_status($row, "approved");
}).fail(function (data) { }).fail(function (data) {
@ -48,14 +48,14 @@ PostReplacement.reject = function (id) {
$.ajax({ $.ajax({
type: "PUT", type: "PUT",
url: `/post_replacements/${id}/reject.json`, url: `/post_replacements/${id}/reject.json`,
dataType: 'json' dataType: "json",
}).done(function () { }).done(function () {
set_status($row, "rejected"); set_status($row, "rejected");
}).fail(function (data) { }).fail(function (data) {
Utility.error(data.responseText); Utility.error(data.responseText);
set_status($row, "rejecting failed"); set_status($row, "rejecting failed");
}); });
} };
PostReplacement.promote = function (id) { PostReplacement.promote = function (id) {
if (!confirm("Are you sure you want to promote this replacement?")) if (!confirm("Are you sure you want to promote this replacement?"))
@ -65,7 +65,7 @@ PostReplacement.promote = function (id) {
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: `/post_replacements/${id}/promote.json`, url: `/post_replacements/${id}/promote.json`,
dataType: 'json' dataType: "json",
}).done(function (data) { }).done(function (data) {
Utility.notice(`Replacement promoted to post #${data.post.id}`); Utility.notice(`Replacement promoted to post #${data.post.id}`);
set_status($row, "promoted"); set_status($row, "promoted");
@ -73,7 +73,7 @@ PostReplacement.promote = function (id) {
Utility.error(data.responseText); Utility.error(data.responseText);
set_status($row, "promoting failed"); set_status($row, "promoting failed");
}); });
} };
PostReplacement.toggle_penalize = function ($target) { PostReplacement.toggle_penalize = function ($target) {
const id = $target.data("replacement-id"); const id = $target.data("replacement-id");
@ -82,22 +82,22 @@ PostReplacement.toggle_penalize = function ($target) {
$.ajax({ $.ajax({
type: "PUT", type: "PUT",
url: `/post_replacements/${id}/toggle_penalize.json`, url: `/post_replacements/${id}/toggle_penalize.json`,
dataType: 'json' dataType: "json",
}).done(function () { }).done(function () {
$target.removeClass("disabled-link"); $target.removeClass("disabled-link");
$currentStatus.text($currentStatus.text() == "yes" ? "no" : "yes"); $currentStatus.text($currentStatus.text() == "yes" ? "no" : "yes");
}).fail(function (data) { }).fail(function (data) {
Utility.error(data.responseText); Utility.error(data.responseText);
}); });
} };
function make_processing($row) { function make_processing ($row) {
$row.removeClass("replacement-pending-row").addClass("replacement-processing-row"); $row.removeClass("replacement-pending-row").addClass("replacement-processing-row");
$row.find(".replacement-status").text("processing"); $row.find(".replacement-status").text("processing");
$row.find(".pending-links a").addClass("disabled-link"); $row.find(".pending-links a").addClass("disabled-link");
} }
function set_status($row, text) { function set_status ($row, text) {
$row.find(".replacement-status").text(text); $row.find(".replacement-status").text(text);
$row.removeClass("replacement-processing-row"); $row.removeClass("replacement-processing-row");
} }
@ -108,4 +108,4 @@ $(function () {
}); });
export default PostReplacement export default PostReplacement;

View File

@ -1,6 +1,6 @@
import {SendQueue} from './send_queue' import {SendQueue} from "./send_queue";
import Post from './posts' import Post from "./posts";
import LS from './local_storage' import LS from "./local_storage";
let PostSet = {}; let PostSet = {};
@ -14,9 +14,10 @@ PostSet.add_post = function (set_id, post_id) {
url: "/post_sets/" + set_id + "/add_posts.json", url: "/post_sets/" + set_id + "/add_posts.json",
data: {post_ids: [post_id]}, data: {post_ids: [post_id]},
}).fail(function (data) { }).fail(function (data) {
var message = $.map(data.responseJSON.errors, function(msg) { return msg; }).join('; '); console.log(data, data.responseJSON, data.responseJSON.error);
var message = $.map(data.responseJSON.errors, (msg) => msg).join("; ");
Post.notice_update("dec"); Post.notice_update("dec");
$(window).trigger('danbooru:error', "Error: " + message); $(window).trigger("danbooru:error", "Error: " + message);
}).done(function () { }).done(function () {
Post.notice_update("dec"); Post.notice_update("dec");
$(window).trigger("danbooru:notice", "Added post to set"); $(window).trigger("danbooru:notice", "Added post to set");
@ -32,9 +33,9 @@ PostSet.remove_post = function (set_id, post_id) {
url: "/post_sets/" + set_id + "/remove_posts.json", url: "/post_sets/" + set_id + "/remove_posts.json",
data: {post_ids: [post_id]}, data: {post_ids: [post_id]},
}).fail(function (data) { }).fail(function (data) {
var message = $.map(data.responseJSON.errors, function(msg) { return msg; }).join('; '); var message = $.map(data.responseJSON.errors, (msg) => msg).join("; ");
Post.notice_update("dec"); Post.notice_update("dec");
$(window).trigger('danbooru:error', "Error: " + message); $(window).trigger("danbooru:error", "Error: " + message);
}).done(function () { }).done(function () {
Post.notice_update("dec"); Post.notice_update("dec");
$(window).trigger("danbooru:notice", "Removed post from set"); $(window).trigger("danbooru:notice", "Removed post from set");
@ -42,8 +43,8 @@ PostSet.remove_post = function (set_id, post_id) {
}); });
}; };
PostSet.initialize_add_to_set_link = function() { PostSet.initialize_add_to_set_link = function () {
$("#set").on("click.danbooru", function(e) { $("#set").on("click.danbooru", function (e) {
if (!PostSet.dialog_setup) { if (!PostSet.dialog_setup) {
$("#add-to-set-dialog").dialog({autoOpen: false}); $("#add-to-set-dialog").dialog({autoOpen: false});
PostSet.dialog_setup = true; PostSet.dialog_setup = true;
@ -53,35 +54,35 @@ PostSet.initialize_add_to_set_link = function() {
$("#add-to-set-dialog").dialog("open"); $("#add-to-set-dialog").dialog("open");
}); });
$("#add-to-set-submit").on("click", function(e) { $("#add-to-set-submit").on("click", function (e) {
e.preventDefault(); e.preventDefault();
const post_id = $('#image-container').data('id'); const post_id = $("#image-container").data("id");
PostSet.add_post($("#add-to-set-id").val(), post_id); PostSet.add_post($("#add-to-set-id").val(), post_id);
$('#add-to-set-dialog').dialog('close'); $("#add-to-set-dialog").dialog("close");
}); });
}; };
PostSet.update_sets_menu = function() { PostSet.update_sets_menu = function () {
const target = $('#add-to-set-id'); const target = $("#add-to-set-id");
target.empty(); target.empty();
target.append($('<option>').text('Loading...')); target.append($("<option>").text("Loading..."));
target.off('change'); target.off("change");
SendQueue.add(function() { SendQueue.add(function () {
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: "/post_sets/for_select.json", url: "/post_sets/for_select.json",
}).fail(function(data) { }).fail(function (data) {
$(window).trigger('danbooru:error', "Error getting sets list: " + data.message); $(window).trigger("danbooru:error", "Error getting sets list: " + data.message);
}).done(function(data) { }).done(function (data) {
target.on('change', function(e) { target.on("change", function (e) {
LS.put('set', e.target.value); LS.put("set", e.target.value);
}) });
const target_set = LS.get('set') || 0; const target_set = LS.get("set") || 0;
target.empty(); target.empty();
['Owned', "Maintained"].forEach(function(v) { ["Owned", "Maintained"].forEach(function (v) {
let group = $('<optgroup>', {label: v}); let group = $("<optgroup>", {label: v});
data[v].forEach(function(gi) { data[v].forEach(function (gi) {
group.append($('<option>', {value: gi[1], selected: (gi[1] == target_set)}).text(gi[0])); group.append($("<option>", {value: gi[1], selected: (gi[1] == target_set)}).text(gi[0]));
}); });
target.append(group); target.append(group);
}); });
@ -89,8 +90,8 @@ PostSet.update_sets_menu = function() {
}); });
}; };
$(function() { $(function () {
if ($("#c-posts").length && $('#a-show').length) { if ($("#c-posts").length && $("#a-show").length) {
PostSet.initialize_add_to_set_link(); PostSet.initialize_add_to_set_link();
} }
}); });

View File

@ -1,6 +1,6 @@
import Utility from './utility'; import Utility from "./utility";
import {SendQueue} from "./send_queue"; import {SendQueue} from "./send_queue";
import Post from './posts'; import Post from "./posts";
let PostVersion = {}; let PostVersion = {};
@ -8,11 +8,11 @@ PostVersion.updated = 0;
PostVersion.initialize_all = function () { PostVersion.initialize_all = function () {
if ($("#c-post-versions #a-index").length) { if ($("#c-post-versions #a-index").length) {
PostVersion.initialize_undo(); PostVersion.initialize_undo();
$('#subnav-select-all-link').on('click', function(event) { $("#subnav-select-all-link").on("click", function (event) {
event.preventDefault(); event.preventDefault();
$(".post-version-select:not(:disabled)").prop("checked", true).change(); $(".post-version-select:not(:disabled)").prop("checked", true).change();
}); });
$("#subnav-apply-tag-script-to-selected-link").on('click', PostVersion.tag_script_selected); $("#subnav-apply-tag-script-to-selected-link").on("click", PostVersion.tag_script_selected);
} }
}; };
@ -51,13 +51,13 @@ PostVersion.undo_selected = function () {
} }
}; };
PostVersion.tag_script_selected = function() { PostVersion.tag_script_selected = function () {
event.preventDefault(); event.preventDefault();
PostVersion.updated = 0; PostVersion.updated = 0;
let selected_rows = $(".post-version-select:checked").parents(".post-version"); let selected_rows = $(".post-version-select:checked").parents(".post-version");
const script = $("#update-tag-script").val(); const script = $("#update-tag-script").val();
if(!script) if (!script)
return; return;
for (let row of selected_rows) { for (let row of selected_rows) {
@ -69,7 +69,7 @@ PostVersion.tag_script_selected = function() {
Utility.notice(`${++PostVersion.updated}/${selected_rows.length} changes applied.`); Utility.notice(`${++PostVersion.updated}/${selected_rows.length} changes applied.`);
}); });
} }
} };
$(document).ready(PostVersion.initialize_all); $(document).ready(PostVersion.initialize_all);
export default PostVersion; export default PostVersion;

File diff suppressed because it is too large Load Diff

View File

@ -4,15 +4,15 @@ import TagEditor from "./tag_editor.vue";
import { createApp } from "vue"; import { createApp } from "vue";
RelatedTag.tag_editor_setup = false; RelatedTag.tag_editor_setup = false;
RelatedTag.init_post_show_editor = function() { RelatedTag.init_post_show_editor = function () {
if (RelatedTag.tag_editor_setup) if (RelatedTag.tag_editor_setup)
return; return;
RelatedTag.tag_editor_setup = true; RelatedTag.tag_editor_setup = true;
const app = createApp(TagEditor); const app = createApp(TagEditor);
app.mount("#tag-string-editor"); app.mount("#tag-string-editor");
} };
$(function() { $(function () {
$(document).on("danbooru:open-post-edit-tab", RelatedTag.init_post_show_editor); $(document).on("danbooru:open-post-edit-tab", RelatedTag.init_post_show_editor);
}); });

View File

@ -2,8 +2,8 @@ import Replacer from "./replacement_uploader.vue";
import { createApp } from "vue"; import { createApp } from "vue";
export default { export default {
init() { init () {
const app = createApp(Replacer); const app = createApp(Replacer);
app.mount("#replacement-uploader"); app.mount("#replacement-uploader");
} },
} };

View File

@ -1,8 +1,8 @@
$(function() { $(function () {
$("#maintoggle").on("click.danbooru", function(e) { $("#maintoggle").on("click.danbooru", function (e) {
e.preventDefault(); e.preventDefault();
$('#nav').toggle(); $("#nav").toggle();
$('#maintoggle-on').toggle(); $("#maintoggle-on").toggle();
$('#maintoggle-off').toggle(); $("#maintoggle-off").toggle();
}); });
}); });

View File

@ -1,12 +1,12 @@
class CBQueue { class CBQueue {
constructor(timer) { constructor (timer) {
this.timeout = timer || 1000; this.timeout = timer || 1000;
this.queue = []; this.queue = [];
this.id = null; this.id = null;
this.running = true; this.running = true;
} }
tick() { tick () {
if (!this.running || !this.queue.length) { if (!this.running || !this.queue.length) {
clearInterval(this.id); clearInterval(this.id);
this.id = null; this.id = null;
@ -15,14 +15,14 @@ class CBQueue {
this.queue.shift()(); this.queue.shift()();
} }
add(cb) { add (cb) {
this.queue.push(cb); this.queue.push(cb);
if (this.running) { if (this.running) {
this.start(); this.start();
} }
} }
start() { start () {
let self = this; let self = this;
this.running = true; this.running = true;
if (!this.id) { if (!this.id) {
@ -33,7 +33,7 @@ class CBQueue {
} }
} }
stop() { stop () {
if (this.id) { if (this.id) {
clearInterval(this.id); clearInterval(this.id);
} }

View File

@ -1,21 +1,21 @@
import Utility from './utility' import Utility from "./utility";
let Shortcuts = {}; let Shortcuts = {};
Shortcuts.disabled = false; Shortcuts.disabled = false;
Shortcuts.initialize = function() { Shortcuts.initialize = function () {
Shortcuts.keydown("s", "scroll_down", Shortcuts.nav_scroll_down); Shortcuts.keydown("s", "scroll_down", Shortcuts.nav_scroll_down);
Shortcuts.keydown("w", "scroll_up", Shortcuts.nav_scroll_up); Shortcuts.keydown("w", "scroll_up", Shortcuts.nav_scroll_up);
Shortcuts.initialize_data_shortcuts(); Shortcuts.initialize_data_shortcuts();
} };
// Bind keyboard shortcuts to links that have a `data-shortcut="..."` attribute. If multiple links have the // Bind keyboard shortcuts to links that have a `data-shortcut="..."` attribute. If multiple links have the
// same shortcut, then only the first link will be triggered by the shortcut. // same shortcut, then only the first link will be triggered by the shortcut.
Shortcuts.initialize_data_shortcuts = function() { Shortcuts.initialize_data_shortcuts = function () {
$(document).off("keydown.danbooru.shortcut"); $(document).off("keydown.danbooru.shortcut");
$("[data-shortcut]").each((_i, element) => { $("[data-shortcut]").each((_i, element) => {
const $e = $(element) const $e = $(element);
const id = $e.attr("id"); const id = $e.attr("id");
const keys = $e.attr("data-shortcut"); const keys = $e.attr("data-shortcut");
const namespace = `shortcut.${id}`; const namespace = `shortcut.${id}`;
@ -39,7 +39,7 @@ Shortcuts.initialize_data_shortcuts = function() {
}); });
}; };
Shortcuts.keydown = function(keys, namespace, handler) { Shortcuts.keydown = function (keys, namespace, handler) {
if (Utility.meta("enable-js-navigation") === "true") { if (Utility.meta("enable-js-navigation") === "true") {
$(document).off("keydown.danbooru." + namespace); $(document).off("keydown.danbooru." + namespace);
$(document).on("keydown.danbooru." + namespace, null, keys, e => { $(document).on("keydown.danbooru." + namespace, null, keys, e => {
@ -51,16 +51,16 @@ Shortcuts.keydown = function(keys, namespace, handler) {
} }
}; };
Shortcuts.nav_scroll_down = function() { Shortcuts.nav_scroll_down = function () {
window.scrollBy(0, $(window).height() * 0.15); window.scrollBy(0, $(window).height() * 0.15);
} };
Shortcuts.nav_scroll_up = function() { Shortcuts.nav_scroll_up = function () {
window.scrollBy(0, $(window).height() * -0.15); window.scrollBy(0, $(window).height() * -0.15);
} };
$(document).ready(function() { $(document).ready(function () {
Shortcuts.initialize(); Shortcuts.initialize();
}); });
export default Shortcuts export default Shortcuts;

View File

@ -1,7 +1,7 @@
import Utility from './utility.js'; import Utility from "./utility.js";
class TagRelationships { class TagRelationships {
static approve(e) { static approve (e) {
e.preventDefault(); e.preventDefault();
const $e = $(e.target); const $e = $(e.target);
const parent = $e.parents(".tag-relationship"); const parent = $e.parents(".tag-relationship");
@ -15,17 +15,17 @@ class TagRelationships {
$.ajax({ $.ajax({
url: `/${route}/${id}/approve.json`, url: `/${route}/${id}/approve.json`,
type: 'POST', type: "POST",
dataType: 'json' dataType: "json",
}).done(function () { }).done(function () {
Utility.notice(`Accepted ${human}.`); Utility.notice(`Accepted ${human}.`);
parent.slideUp('fast'); parent.slideUp("fast");
}).fail(function () { }).fail(function () {
Utility.error(`Failed to accept ${human}.`); Utility.error(`Failed to accept ${human}.`);
}); });
} }
static reject(e) { static reject (e) {
e.preventDefault(); e.preventDefault();
const $e = $(e.target); const $e = $(e.target);
const parent = $e.parents(".tag-relationship"); const parent = $e.parents(".tag-relationship");
@ -33,30 +33,30 @@ class TagRelationships {
const human = parent.data("relationship-human"); const human = parent.data("relationship-human");
const id = parent.data("relationship-id"); const id = parent.data("relationship-id");
if(!confirm(`Are you sure you want to reject this ${human}?`)) { if (!confirm(`Are you sure you want to reject this ${human}?`)) {
return; return;
} }
$.ajax({ $.ajax({
url: `/${route}/${id}.json`, url: `/${route}/${id}.json`,
type: 'DELETE', type: "DELETE",
dataType: 'json' dataType: "json",
}).done(function () { }).done(function () {
Utility.notice(`Rejected ${human}.`); Utility.notice(`Rejected ${human}.`);
parent.slideUp('fast'); parent.slideUp("fast");
}).fail(function () { }).fail(function () {
Utility.error(`Failed to reject ${human}.`); Utility.error(`Failed to reject ${human}.`);
}); });
} }
} }
$(document).ready(function() { $(document).ready(function () {
$(".tag-relationship-accept").on('click', e => { $(".tag-relationship-accept").on("click", e => {
TagRelationships.approve(e); TagRelationships.approve(e);
}); });
$(".tag-relationship-reject").on('click', e => { $(".tag-relationship-reject").on("click", e => {
TagRelationships.reject(e); TagRelationships.reject(e);
}); });
}); });
export default TagRelationships export default TagRelationships;

View File

@ -1,12 +1,13 @@
/* eslint-disable comma-dangle */
const TagScript = { const TagScript = {
parse(script) { parse (script) {
return script.match(/\[.+?\]|\S+/g) return script.match(/\[.+?\]|\S+/g);
}, },
test(tags, predicate) { test (tags, predicate) {
const split_pred = predicate.match(/\S+/g); const split_pred = predicate.match(/\S+/g);
for (const x of split_pred) { for (const x of split_pred) {
if (x[0] === '-') { if (x[0] === "-") {
if (tags.has(x.substr(1))) { if (tags.has(x.substr(1))) {
return false; return false;
} }
@ -17,11 +18,11 @@ const TagScript = {
return true; return true;
}, },
process(tags, command) { process (tags, command) {
if (command.match(/^\[if/)) { if (command.match(/^\[if/)) {
const match = command.match(/\[if\s+(.+?)\s*,\s*(.+?)\]/); const match = command.match(/\[if\s+(.+?)\s*,\s*(.+?)\]/);
if (TagScript.test(tags, match[1])) { if (TagScript.test(tags, match[1])) {
return TagScript.process(tags, match[2]) return TagScript.process(tags, match[2]);
} else { } else {
return null; return null;
} }
@ -31,7 +32,7 @@ const TagScript = {
return command; return command;
} }
}, },
run(tags, tag_script) { run (tags, tag_script) {
const changes = []; const changes = [];
const commands = TagScript.parse(tag_script); const commands = TagScript.parse(tag_script);
@ -41,7 +42,7 @@ const TagScript = {
changes.push(result); changes.push(result);
} }
} }
return changes.join(' '); return changes.join(" ");
} }
}; };

View File

@ -1,9 +1,9 @@
import Utility from './utility.js'; import Utility from "./utility.js";
let Takedown = {}; let Takedown = {};
Takedown.destroy = function (id) { Takedown.destroy = function (id) {
Utility.notice('Deleting takedown #' + id + "..."); Utility.notice("Deleting takedown #" + id + "...");
$.ajax({ $.ajax({
url: "/takedown/destroy.json", url: "/takedown/destroy.json",
@ -11,8 +11,8 @@ Takedown.destroy = function (id) {
dataType: "json", dataType: "json",
headers: {accept: "text/javascript"}, headers: {accept: "text/javascript"},
data: { data: {
"id": id "id": id,
} },
}).done(function () { }).done(function () {
Utility.notice("Takedown deleted"); Utility.notice("Takedown deleted");
$("#takedown-" + id).fadeOut("fast"); $("#takedown-" + id).fadeOut("fast");
@ -30,8 +30,8 @@ Takedown.add_posts_by_tags_preview = function (id) {
headers: {accept: "text/javascript"}, headers: {accept: "text/javascript"},
data: { data: {
id: id, id: id,
post_tags: tags post_tags: tags,
} },
}).done(function (data) { }).done(function (data) {
var count = data.matched_post_count; var count = data.matched_post_count;
var preview_text = "<a href='/post/index?tags=" + tags.replace(" ", "+") + "+status:any'>" + count + " " + (count == 1 ? "post" : "posts") + "</a> " + (count == 1 ? "matches" : "match") + " the search '<a href='/post/index?tags=" + tags.replace(" ", "+") + "+status:any'>" + tags + "</a>'. Click Confirm to add " + (count == 1 ? "it" : "them") + " to the takedown."; var preview_text = "<a href='/post/index?tags=" + tags.replace(" ", "+") + "+status:any'>" + count + " " + (count == 1 ? "post" : "posts") + "</a> " + (count == 1 ? "matches" : "match") + " the search '<a href='/post/index?tags=" + tags.replace(" ", "+") + "+status:any'>" + tags + "</a>'. Click Confirm to add " + (count == 1 ? "it" : "them") + " to the takedown.";
@ -48,7 +48,7 @@ Takedown.add_posts_by_tags_preview = function (id) {
Takedown.add_posts_by_tags_cancel = function () { Takedown.add_posts_by_tags_cancel = function () {
$("#takedown-add-posts-tags-warning").hide(); $("#takedown-add-posts-tags-warning").hide();
$("#takedown-add-posts-tags").val('').prop("disabled", false); $("#takedown-add-posts-tags").val("").prop("disabled", false);
$("#takedown-add-posts-tags-preview").show().prop("disabled", true); $("#takedown-add-posts-tags-preview").show().prop("disabled", true);
$("#takedown-add-posts-tags-confirm").hide(); $("#takedown-add-posts-tags-confirm").hide();
$("#takedown-add-posts-tags-cancel").hide(); $("#takedown-add-posts-tags-cancel").hide();
@ -66,8 +66,8 @@ Takedown.add_posts_by_tags = function (id) {
headers: {accept: "text/javascript"}, headers: {accept: "text/javascript"},
data: { data: {
id: id, id: id,
post_tags: tags post_tags: tags,
} },
}).done(function (data) { }).done(function (data) {
const added_post_ids = data.added_post_ids; const added_post_ids = data.added_post_ids;
const count = added_post_ids.length; const count = added_post_ids.length;
@ -98,8 +98,8 @@ Takedown.add_posts_by_ids = function (id) {
headers: {accept: "text/javascript"}, headers: {accept: "text/javascript"},
data: { data: {
id: id, id: id,
post_ids: post_ids post_ids: post_ids,
} },
}).done(function (data) { }).done(function (data) {
Utility.notice(data.added_count + " post" + (data.added_count == 1 ? "" : "s") + " added to takedown"); Utility.notice(data.added_count + " post" + (data.added_count == 1 ? "" : "s") + " added to takedown");
@ -109,7 +109,7 @@ Takedown.add_posts_by_ids = function (id) {
$(html).appendTo($("#takedown-post-buttons")); $(html).appendTo($("#takedown-post-buttons"));
} }
$("#takedown-add-posts-ids").val(''); $("#takedown-add-posts-ids").val("");
$("#takedown-add-posts-ids-submit").prop("disabled", true); $("#takedown-add-posts-ids-submit").prop("disabled", true);
}).fail(function (data) { }).fail(function (data) {
Utility.error(data.responseText); Utility.error(data.responseText);
@ -126,10 +126,10 @@ Takedown.remove_post = function (id, post_id) {
headers: {accept: "text/javascript"}, headers: {accept: "text/javascript"},
data: { data: {
id: id, id: id,
post_ids: post_id post_ids: post_id,
} },
}).done(function () { }).done(function () {
Utility.notice("Post #" + post_id + " removed from takedown") Utility.notice("Post #" + post_id + " removed from takedown");
$("#takedown-post-" + post_id).remove(); $("#takedown-post-" + post_id).remove();
}).fail(function (data) { }).fail(function (data) {
Utility.error(data.responseText); Utility.error(data.responseText);
@ -140,22 +140,22 @@ Takedown.post_button_html = function (post_id) {
return "<div id='takedown-post-" + post_id + "' data-post-id='" + post_id + "' class='takedown-post'><div class='takedown-post-label takedown-post-remove' title='Remove this post from the takedown'>X</div> <label for='takedown_posts_" + post_id + "' class='takedown-post-label takedown-post-keep'><input name='takedown_posts[" + post_id + "]' type='hidden' value='0'><input id='takedown_posts_" + post_id + "' name='takedown_posts[" + post_id + "]' type='checkbox' value='1'> <span>Keep</span></label> <a href='/post/show/" + post_id + "'>post #" + post_id + "</a></div>"; return "<div id='takedown-post-" + post_id + "' data-post-id='" + post_id + "' class='takedown-post'><div class='takedown-post-label takedown-post-remove' title='Remove this post from the takedown'>X</div> <label for='takedown_posts_" + post_id + "' class='takedown-post-label takedown-post-keep'><input name='takedown_posts[" + post_id + "]' type='hidden' value='0'><input id='takedown_posts_" + post_id + "' name='takedown_posts[" + post_id + "]' type='checkbox' value='1'> <span>Keep</span></label> <a href='/post/show/" + post_id + "'>post #" + post_id + "</a></div>";
}; };
$(document).ready(function() { $(document).ready(function () {
$("#takedown-add-posts-ids-submit").on('click', e => { $("#takedown-add-posts-ids-submit").on("click", e => {
const $e = $(e.target); const $e = $(e.target);
Takedown.add_posts_by_ids($e.data('tid')); Takedown.add_posts_by_ids($e.data("tid"));
}); });
$("#takedown-add-posts-tags-cancel").on('click', () => { $("#takedown-add-posts-tags-cancel").on("click", () => {
Takedown.add_posts_by_tags_cancel(); Takedown.add_posts_by_tags_cancel();
}); });
$("#takedown-add-posts-tags-confirm").on('click', e => { $("#takedown-add-posts-tags-confirm").on("click", e => {
const $e = $(e.target); const $e = $(e.target);
Takedown.add_posts_by_tags($e.data('tid')); Takedown.add_posts_by_tags($e.data("tid"));
}); });
$("#takedown-add-posts-tags-preview").on('click', e => { $("#takedown-add-posts-tags-preview").on("click", e => {
const $e = $(e.target); const $e = $(e.target);
Takedown.add_posts_by_tags_preview($e.data('tid')); Takedown.add_posts_by_tags_preview($e.data("tid"));
}) });
}); });
export default Takedown export default Takedown;

View File

@ -1,22 +1,22 @@
import Blacklist from './blacklists'; import Blacklist from "./blacklists";
import LS from './local_storage'; import LS from "./local_storage";
const Thumbnails = {}; const Thumbnails = {};
Thumbnails.initialize = function () { Thumbnails.initialize = function () {
const clearPlaceholder = function (post) { const clearPlaceholder = function (post) {
if (post.hasClass('thumb-placeholder-link')) { if (post.hasClass("thumb-placeholder-link")) {
post.removeClass('thumb-placeholder-link'); post.removeClass("thumb-placeholder-link");
} else { } else {
post.empty(); post.empty();
} }
}; };
const postsData = window.___deferred_posts || {}; const postsData = window.___deferred_posts || {};
const posts = $('.post-thumb.placeholder, .thumb-placeholder-link'); const posts = $(".post-thumb.placeholder, .thumb-placeholder-link");
const DAB = LS.get("dab") === "1"; const DAB = LS.get("dab") === "1";
$.each(posts, function (i, post) { $.each(posts, function (i, post) {
const p = $(post); const p = $(post);
const postID = p.data('id'); const postID = p.data("id");
if (!postID) { if (!postID) {
clearPlaceholder(p); clearPlaceholder(p);
return; return;
@ -33,25 +33,25 @@ Thumbnails.initialize = function () {
blacklist_hit_count += 1; blacklist_hit_count += 1;
} }
}); });
const newTag = $('<div>'); const newTag = $("<div>");
const blacklisted = DAB ? false : blacklist_hit_count > 0; const blacklisted = DAB ? false : blacklist_hit_count > 0;
for (const key in postData) { for (const key in postData) {
newTag.attr("data-" + key.replace(/_/g, '-'), postData[key]); newTag.attr("data-" + key.replace(/_/g, "-"), postData[key]);
} }
newTag.attr('class', blacklisted ? "post-thumbnail blacklisted" : "post-thumbnail"); newTag.attr("class", blacklisted ? "post-thumbnail blacklisted" : "post-thumbnail");
if (p.hasClass('thumb-placeholder-link')) if (p.hasClass("thumb-placeholder-link"))
newTag.addClass('dtext'); newTag.addClass("dtext");
const img = $('<img>'); const img = $("<img>");
img.attr('src', postData.preview_url || '/images/deleted-preview.png'); img.attr("src", postData.preview_url || "/images/deleted-preview.png");
img.attr({ img.attr({
height: postData.preview_url ? postData.preview_height : 150, height: postData.preview_url ? postData.preview_height : 150,
width: postData.preview_url ? postData.preview_width : 150, width: postData.preview_url ? postData.preview_width : 150,
title: `Rating: ${postData.rating}\r\nID: ${postData.id}\r\nStatus: ${postData.status}\r\nDate: ${postData.created_at}\r\n\r\n${postData.tags}`, title: `Rating: ${postData.rating}\r\nID: ${postData.id}\r\nStatus: ${postData.status}\r\nDate: ${postData.created_at}\r\n\r\n${postData.tags}`,
alt: postData.tags, alt: postData.tags,
class: 'post-thumbnail-img' class: "post-thumbnail-img",
}); });
const link = $('<a>'); const link = $("<a>");
link.attr('href', `/posts/${postData.id}`); link.attr("href", `/posts/${postData.id}`);
link.append(img); link.append(img);
newTag.append(link); newTag.append(link);
p.replaceWith(newTag); p.replaceWith(newTag);
@ -60,12 +60,12 @@ Thumbnails.initialize = function () {
$(document).ready(function () { $(document).ready(function () {
Thumbnails.initialize(); Thumbnails.initialize();
$(window).on('e621:add_deferred_posts', (_, posts) => { $(window).on("e621:add_deferred_posts", (_, posts) => {
window.___deferred_posts = window.___deferred_posts || {} window.___deferred_posts = window.___deferred_posts || {};
window.___deferred_posts = $.extend(window.___deferred_posts, posts); window.___deferred_posts = $.extend(window.___deferred_posts, posts);
Thumbnails.initialize(); Thumbnails.initialize();
}); });
$(document).on('thumbnails:apply', Thumbnails.initialize); $(document).on("thumbnails:apply", Thumbnails.initialize);
}); });
export default Thumbnails; export default Thumbnails;

View File

@ -1,9 +1,9 @@
import Uploader from './uploader/uploader.vue.erb'; import Uploader from "./uploader/uploader.vue.erb";
import { createApp } from 'vue'; import { createApp } from "vue";
export default { export default {
init() { init () {
const app = createApp(Uploader); const app = createApp(Uploader);
app.mount('#uploader'); app.mount("#uploader");
} },
} };

View File

@ -1,23 +1,23 @@
import Blip from './blips.js'; import Blip from "./blips.js";
import Comment from './comments.js'; import Comment from "./comments.js";
import DText from './dtext.js'; import DText from "./dtext.js";
import ForumPost from './forum_posts.js'; import ForumPost from "./forum_posts.js";
import Utility from './utility.js'; import Utility from "./utility.js";
class UserWarnable { class UserWarnable {
static initialize_click_handlers() { static initialize_click_handlers () {
$('.item-mark-user-warned').on('click', evt => { $(".item-mark-user-warned").on("click", evt => {
evt.preventDefault(); evt.preventDefault();
const target = $(evt.target); const target = $(evt.target);
const type = target.data('item-route'); const type = target.data("item-route");
const id = target.data('item-id'); const id = target.data("item-id");
const item_type = target.data('item-type'); const item_type = target.data("item-type");
const record_type = target.data('record-type'); const record_type = target.data("record-type");
const message = record_type === "unmark" const message = record_type === "unmark"
? `Are you sure you want to unmark this ${item_type}?` ? `Are you sure you want to unmark this ${item_type}?`
: `Are you sure you want to mark this ${item_type} for having received ${record_type}?` : `Are you sure you want to mark this ${item_type} for having received ${record_type}?`;
if(!confirm(message)) { if (!confirm(message)) {
return; return;
} }
@ -25,7 +25,7 @@ class UserWarnable {
type: "POST", type: "POST",
url: `/${type}/${id}/warning.json`, url: `/${type}/${id}/warning.json`,
data: { data: {
'record_type': record_type "record_type": record_type,
}, },
}).done(data => { }).done(data => {
target.closest("article.blip, article.comment, article.forum-post").replaceWith(data.html); target.closest("article.blip, article.comment, article.forum-post").replaceWith(data.html);
@ -42,7 +42,7 @@ class UserWarnable {
}); });
} }
static reinitialize_click_handlers() { static reinitialize_click_handlers () {
$(".item-mark-user-warned").off("click"); $(".item-mark-user-warned").off("click");
this.initialize_click_handlers(); this.initialize_click_handlers();
} }

View File

@ -2,101 +2,101 @@ import Shortcuts from "./shortcuts";
let Utility = {}; let Utility = {};
Utility.delay = function(milliseconds) { Utility.delay = function (milliseconds) {
return new Promise(resolve => setTimeout(resolve, milliseconds)); return new Promise(resolve => setTimeout(resolve, milliseconds));
} };
Utility.meta = function(key) { Utility.meta = function (key) {
return $("meta[name=" + key + "]").attr("content"); return $("meta[name=" + key + "]").attr("content");
} };
Utility.test_max_width = function(width) { Utility.test_max_width = function (width) {
if (!window.matchMedia) { if (!window.matchMedia) {
return false; return false;
} }
var mq = window.matchMedia('(max-width: ' + width + 'px)'); var mq = window.matchMedia("(max-width: " + width + "px)");
return mq.matches; return mq.matches;
} };
Utility.notice_timeout_id = undefined; Utility.notice_timeout_id = undefined;
Utility.notice = function(msg, permanent) { Utility.notice = function (msg, permanent) {
$('#notice').addClass("ui-state-highlight").removeClass("ui-state-error").fadeIn("fast").children("span").html(msg); $("#notice").addClass("ui-state-highlight").removeClass("ui-state-error").fadeIn("fast").children("span").html(msg);
if (Utility.notice_timeout_id !== undefined) { if (Utility.notice_timeout_id !== undefined) {
clearTimeout(Utility.notice_timeout_id) clearTimeout(Utility.notice_timeout_id);
} }
if (!permanent) { if (!permanent) {
Utility.notice_timeout_id = setTimeout(function() { Utility.notice_timeout_id = setTimeout(function () {
$("#close-notice-link").click(); $("#close-notice-link").click();
Utility.notice_timeout_id = undefined; Utility.notice_timeout_id = undefined;
}, 6000); }, 6000);
} }
} };
Utility.error = function(msg) { Utility.error = function (msg) {
$('#notice').removeClass("ui-state-highlight").addClass("ui-state-error").fadeIn("fast").children("span").html(msg); $("#notice").removeClass("ui-state-highlight").addClass("ui-state-error").fadeIn("fast").children("span").html(msg);
if (Utility.notice_timeout_id !== undefined) { if (Utility.notice_timeout_id !== undefined) {
clearTimeout(Utility.notice_timeout_id) clearTimeout(Utility.notice_timeout_id);
} }
} };
Utility.dialog = function(title, html) { Utility.dialog = function (title, html) {
const $dialog = $(html).dialog({ const $dialog = $(html).dialog({
title: title, title: title,
width: 700, width: 700,
modal: true, modal: true,
close: function() { close: function () {
// Defer removing the dialog to avoid detaching the <form> tag before the // Defer removing the dialog to avoid detaching the <form> tag before the
// form is submitted (which would prevent the submission from going through). // form is submitted (which would prevent the submission from going through).
$(() => $dialog.dialog("destroy")); $(() => $dialog.dialog("destroy"));
}, },
buttons: { buttons: {
"Submit": function() { "Submit": function () {
$dialog.find("form").submit(); $dialog.find("form").submit();
}, },
"Cancel": function() { "Cancel": function () {
$dialog.dialog("close"); $dialog.dialog("close");
} },
} },
}); });
$dialog.find("form").on("submit.danbooru", function() { $dialog.find("form").on("submit.danbooru", function () {
$dialog.dialog("close"); $dialog.dialog("close");
}); });
} };
// TODO: Remove 2024-05-15 // TODO: Remove 2024-05-15
Object.defineProperty(Utility, "disableShortcuts", { Object.defineProperty(Utility, "disableShortcuts", {
get() { get () {
console.log("Utility.disableShortcuts is deprecated and will be removed at a later date, use Shortcuts.disabled instead"); console.log("Utility.disableShortcuts is deprecated and will be removed at a later date, use Shortcuts.disabled instead");
return Shortcuts.disabled; return Shortcuts.disabled;
}, },
set(value) { set (value) {
console.log("Utility.disableShortcuts is deprecated and will be removed at a later date, use Shortcuts.disabled instead"); console.log("Utility.disableShortcuts is deprecated and will be removed at a later date, use Shortcuts.disabled instead");
Shortcuts.disabled = value Shortcuts.disabled = value;
} },
}) });
Utility.keydown = function(keys, namespace, handler) { Utility.keydown = function (keys, namespace, handler) {
console.log("Utility.keydown is deprecated and will be removed at a later date, use Shortcuts.keydown instead"); console.log("Utility.keydown is deprecated and will be removed at a later date, use Shortcuts.keydown instead");
Shortcuts.keydown(keys, namespace, handler) Shortcuts.keydown(keys, namespace, handler);
}; };
Utility.is_subset = function(array, subarray) { Utility.is_subset = function (array, subarray) {
var all = true; var all = true;
$.each(subarray, function(i, val) { $.each(subarray, function (i, val) {
if ($.inArray(val, array) === -1) { if ($.inArray(val, array) === -1) {
all = false; all = false;
} }
}); });
return all; return all;
} };
Utility.intersect = function(a, b) { Utility.intersect = function (a, b) {
a = a.slice(0).sort(); a = a.slice(0).sort();
b = b.slice(0).sort(); b = b.slice(0).sort();
var result = []; var result = [];
@ -111,27 +111,27 @@ Utility.intersect = function(a, b) {
} }
} }
return result; return result;
} };
Utility.regexp_escape = function(string) { Utility.regexp_escape = function (string) {
return string.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1"); return string.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
} };
$.fn.selectEnd = function() { $.fn.selectEnd = function () {
return this.each(function() { return this.each(function () {
this.focus(); this.focus();
this.setSelectionRange(this.value.length, this.value.length); this.setSelectionRange(this.value.length, this.value.length);
}) });
} };
$(function() { $(function () {
$(window).on("danbooru:notice", function(event, msg) { $(window).on("danbooru:notice", function (event, msg) {
Utility.notice(msg); Utility.notice(msg);
}) });
$(window).on("danbooru:error", function(event, msg) { $(window).on("danbooru:error", function (event, msg) {
Utility.error(msg); Utility.error(msg);
}) });
}); });
export default Utility export default Utility;

View File

@ -1,76 +1,76 @@
import Utility from './utility'; import Utility from "./utility";
class VoteManager { class VoteManager {
constructor(itemType) { constructor (itemType) {
this._type = itemType; this._type = itemType;
this.allSelected = false; this.allSelected = false;
this.init(); this.init();
} }
init() { init () {
const self = this; const self = this;
self.lastSelected = 0; self.lastSelected = 0;
$("#votes").on('click', 'tbody tr', function (evt) { $("#votes").on("click", "tbody tr", function (evt) {
if ($(evt.target).is("a")) return; if ($(evt.target).is("a")) return;
evt.preventDefault(); evt.preventDefault();
if (evt.shiftKey) { if (evt.shiftKey) {
self.toggleRowsBetween([self.lastSelected, this.rowIndex]); self.toggleRowsBetween([self.lastSelected, this.rowIndex]);
} }
$(this).toggleClass('selected'); $(this).toggleClass("selected");
self.lastSelected = this.rowIndex; self.lastSelected = this.rowIndex;
}); });
$("#select-all-votes").on('click', () => self.selectAll()); $("#select-all-votes").on("click", () => self.selectAll());
$("#lock-votes").on('click', () => self.lockVotes()); $("#lock-votes").on("click", () => self.lockVotes());
$("#delete-votes").on('click', () => self.deleteVotes()); $("#delete-votes").on("click", () => self.deleteVotes());
} }
selectAll() { selectAll () {
this.allSelected = !this.allSelected; this.allSelected = !this.allSelected;
if(this.allSelected) if (this.allSelected)
$('#votes').find('tr').addClass('selected'); $("#votes").find("tr").addClass("selected");
else else
$('#votes').find('tr').removeClass('selected'); $("#votes").find("tr").removeClass("selected");
} }
toggleRowsBetween(indices) { toggleRowsBetween (indices) {
this.lastSelected = indices[1]; this.lastSelected = indices[1];
let rows = $('#votes').find('tr'); let rows = $("#votes").find("tr");
indices = indices.sort(); indices = indices.sort();
rows = rows.slice(indices[0], indices[1]); rows = rows.slice(indices[0], indices[1]);
rows.toggleClass('selected'); rows.toggleClass("selected");
} }
selectedVotes() { selectedVotes () {
return $("#votes>tbody>tr.selected").map(function () { return $("#votes>tbody>tr.selected").map(function () {
return $(this).attr('id').substr(1); return $(this).attr("id").substr(1);
}).get(); }).get();
} }
lockVotes() { lockVotes () {
const votes = this.selectedVotes(); const votes = this.selectedVotes();
if (!votes.length) return; if (!votes.length) return;
$.ajax({ $.ajax({
url: `/${this._type}_votes/lock.json`, url: `/${this._type}_votes/lock.json`,
method: "post", method: "post",
data: { data: {
ids: votes.join(',') ids: votes.join(","),
} },
}).done(() => { }).done(() => {
Utility.notice(`${this._type} votes locked.`); Utility.notice(`${this._type} votes locked.`);
}); });
} }
deleteVotes() { deleteVotes () {
const votes = this.selectedVotes(); const votes = this.selectedVotes();
if (!votes.length) return; if (!votes.length) return;
$.ajax({ $.ajax({
url: `/${this._type}_votes/delete.json`, url: `/${this._type}_votes/delete.json`,
method: "post", method: "post",
data: { data: {
ids: votes.join(',') ids: votes.join(","),
} },
}).done(() => { }).done(() => {
Utility.notice(`${this._type} votes deleted.`) Utility.notice(`${this._type} votes deleted.`);
}); });
} }
} }

View File

@ -21,14 +21,13 @@ export default [
"no-unused-vars": "warn", "no-unused-vars": "warn",
// https://eslint.style/packages/js // https://eslint.style/packages/js
/*
"array-bracket-newline": "warn", "array-bracket-newline": "warn",
"array-bracket-spacing": "off", "array-bracket-spacing": "off",
"array-element-newline": ["warn", "consistent"], "array-element-newline": ["warn", "consistent"],
"arrow-parens": "off", "arrow-parens": "off",
"arrow-spacing": "warn", "arrow-spacing": "warn",
"block-spacing": "warn", "block-spacing": "warn",
"brace-style": "warn", "brace-style": ["warn", "1tbs", { allowSingleLine: true }],
"comma-dangle": ["warn", "always-multiline"], "comma-dangle": ["warn", "always-multiline"],
"comma-spacing": "warn", "comma-spacing": "warn",
"comma-style": "warn", "comma-style": "warn",
@ -38,21 +37,21 @@ export default [
"function-call-argument-newline": ["warn", "consistent"], "function-call-argument-newline": ["warn", "consistent"],
"func-call-spacing": "warn", // function-call-spacing does not work ??? "func-call-spacing": "warn", // function-call-spacing does not work ???
"implicit-arrow-linebreak": "warn", "implicit-arrow-linebreak": "warn",
"indent": ["warn", 2], "indent": ["warn", 2, { SwitchCase: 1, }],
"key-spacing": ["warn", { "align": "value" }], // Might get annoying "key-spacing": ["warn", { mode: "minimum" }],
"keyword-spacing": "warn", "keyword-spacing": "warn",
"line-comment-position": "off", "line-comment-position": "off",
"linebreak-style": "error", "linebreak-style": "error",
"lines-around-comment": "off", "lines-around-comment": "off",
"lines-between-class-members": "warn", "lines-between-class-members": "warn",
"max-len": "warn", // Might get annoying, see https://eslint.style/rules/js/max-len // "max-len": ["warn", { code: 100, tabWidth: 2, ignoreComments: true }], // Might get annoying, see https://eslint.style/rules/js/max-len
"max-statements-per-line": "warn", "max-statements-per-line": "warn",
"multiline-comment-style": "off", "multiline-comment-style": "off",
"multiline-ternary": ["warn", "always-multiline"], "multiline-ternary": ["warn", "always-multiline"],
"new-parens": "warn", "new-parens": "warn",
"newline-per-chained-call": "off", "newline-per-chained-call": "off",
"no-confusing-arrow": "warn", "no-confusing-arrow": "warn",
"no-extra-parens": "warn", "no-extra-parens": "off",
"no-extra-semi": "warn", "no-extra-semi": "warn",
"no-floating-decimal": "warn", "no-floating-decimal": "warn",
"no-mixed-operators": "error", "no-mixed-operators": "error",
@ -63,7 +62,7 @@ export default [
"no-trailing-spaces": "warn", "no-trailing-spaces": "warn",
"no-whitespace-before-property": "warn", "no-whitespace-before-property": "warn",
"nonblock-statement-body-position": "off", "nonblock-statement-body-position": "off",
"object-curly-newline": ["warn", { "consistent": true }], "object-curly-newline": ["warn", { consistent: true }],
"one-var-declaration-per-line": "off", "one-var-declaration-per-line": "off",
"operator-linebreak": ["warn", "before"], "operator-linebreak": ["warn", "before"],
"padded-blocks": "off", "padded-blocks": "off",
@ -83,7 +82,6 @@ export default [
"switch-colon-spacing": "warn", "switch-colon-spacing": "warn",
"template-curly-spacing": "warn", "template-curly-spacing": "warn",
"template-tag-spacing": "warn", "template-tag-spacing": "warn",
*/
}, },
}, },
] ]