mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-02-07 23:06:42 +01:00
linting fixes
This commit is contained in:
parent
55760ea57e
commit
a4cad4e534
1 changed files with 24 additions and 25 deletions
|
@ -193,29 +193,28 @@ function setupImageUpload() {
|
||||||
function validateTags() {
|
function validateTags() {
|
||||||
const tags = $$('.tag');
|
const tags = $$('.tag');
|
||||||
if (tags.length === 0) {
|
if (tags.length === 0) {
|
||||||
createTagError("Tag input must contain at least 3 tags")
|
createTagError('Tag input must contain at least 3 tags');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let tags_arr = [];
|
const tagsArr = [];
|
||||||
for (const i in tags) {
|
for (const i in tags) {
|
||||||
let tag = tags[i].innerText;
|
let tag = tags[i].innerText;
|
||||||
tag = tag.substring(0, tag.length - 2); // remove " x" from the end
|
tag = tag.substring(0, tag.length - 2); // remove " x" from the end
|
||||||
tags_arr.push(tag);
|
tagsArr.push(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
let ratings_tags = ["safe", "suggestive", "questionable", "explicit",
|
const ratingsTags = ['safe', 'suggestive', 'questionable', 'explicit', 'semi-grimdark', 'grimdark', 'grotesque'];
|
||||||
"semi-grimdark", "grimdark", "grotesque"];
|
|
||||||
|
|
||||||
let errors = [];
|
const errors = [];
|
||||||
|
|
||||||
let hasRating = false;
|
let hasRating = false;
|
||||||
let hasSafe = false;
|
let hasSafe = false;
|
||||||
let hasOtherRating = false;
|
let hasOtherRating = false;
|
||||||
tags_arr.forEach(tag => {
|
tagsArr.forEach(tag => {
|
||||||
if (ratings_tags.includes(tag)) {
|
if (ratingsTags.includes(tag)) {
|
||||||
hasRating = true;
|
hasRating = true;
|
||||||
if (tag === "safe") {
|
if (tag === 'safe') {
|
||||||
hasSafe = true;
|
hasSafe = true;
|
||||||
} else {
|
} else {
|
||||||
hasOtherRating = true;
|
hasOtherRating = true;
|
||||||
|
@ -224,18 +223,18 @@ function setupImageUpload() {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!hasRating) {
|
if (!hasRating) {
|
||||||
errors.push("Tag input must contain at least one rating tag");
|
errors.push('Tag input must contain at least one rating tag');
|
||||||
} else if (hasSafe && hasOtherRating) {
|
} else if (hasSafe && hasOtherRating) {
|
||||||
errors.push("Tag input may not contain any other rating if safe")
|
errors.push('Tag input may not contain any other rating if safe');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tags_arr.length < 3) {
|
if (tagsArr.length < 3) {
|
||||||
errors.push("Tag input must contain at least 3 tags");
|
errors.push('Tag input must contain at least 3 tags');
|
||||||
}
|
}
|
||||||
|
|
||||||
errors.forEach(msg => createTagError(msg));
|
errors.forEach(msg => createTagError(msg));
|
||||||
|
|
||||||
return errors.length == 0; // true: valid if no errors
|
return errors.length === 0; // true: valid if no errors
|
||||||
}
|
}
|
||||||
|
|
||||||
function enableUploadButton() {
|
function enableUploadButton() {
|
||||||
|
@ -250,7 +249,7 @@ function setupImageUpload() {
|
||||||
const submitButton = $('.input--separate-top');
|
const submitButton = $('.input--separate-top');
|
||||||
if (submitButton !== null) {
|
if (submitButton !== null) {
|
||||||
submitButton.disabled = true;
|
submitButton.disabled = true;
|
||||||
submitButton.innerText = "Please wait...";
|
submitButton.innerText = 'Please wait...';
|
||||||
}
|
}
|
||||||
|
|
||||||
// delay is needed because Safari stops the submit if the button is immediately disabled
|
// delay is needed because Safari stops the submit if the button is immediately disabled
|
||||||
|
@ -274,7 +273,8 @@ function setupImageUpload() {
|
||||||
// allow form submission
|
// allow form submission
|
||||||
disableUploadButton();
|
disableUploadButton();
|
||||||
return true;
|
return true;
|
||||||
} else {
|
}
|
||||||
|
|
||||||
//tags invalid
|
//tags invalid
|
||||||
enableUploadButton(); // enable Upload button
|
enableUploadButton(); // enable Upload button
|
||||||
anchorToTop(); // move view to top of page
|
anchorToTop(); // move view to top of page
|
||||||
|
@ -283,7 +283,6 @@ function setupImageUpload() {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fileField.addEventListener('change', registerBeforeUnload);
|
fileField.addEventListener('change', registerBeforeUnload);
|
||||||
fetchButton.addEventListener('click', registerBeforeUnload);
|
fetchButton.addEventListener('click', registerBeforeUnload);
|
||||||
|
|
Loading…
Reference in a new issue