mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-02-01 03:46:44 +01:00
linting fixes
This commit is contained in:
parent
55760ea57e
commit
a4cad4e534
1 changed files with 24 additions and 25 deletions
|
@ -173,7 +173,7 @@ function setupImageUpload() {
|
||||||
|
|
||||||
function createTagError(message) {
|
function createTagError(message) {
|
||||||
const buttonAfter = $('#tagsinput-save');
|
const buttonAfter = $('#tagsinput-save');
|
||||||
const errorElement = makeEl('span', { className: 'help-block tag-error'});
|
const errorElement = makeEl('span', { className: 'help-block tag-error' });
|
||||||
errorElement.innerText = message;
|
errorElement.innerText = message;
|
||||||
buttonAfter.parentElement.insertBefore(errorElement, buttonAfter);
|
buttonAfter.parentElement.insertBefore(errorElement, buttonAfter);
|
||||||
}
|
}
|
||||||
|
@ -182,7 +182,7 @@ function setupImageUpload() {
|
||||||
const tagErrorElements = document.getElementsByClassName('tag-error');
|
const tagErrorElements = document.getElementsByClassName('tag-error');
|
||||||
|
|
||||||
// remove() causes the length to decrease
|
// remove() causes the length to decrease
|
||||||
while(tagErrorElements.length > 0) {
|
while (tagErrorElements.length > 0) {
|
||||||
tagErrorElements[0].remove();
|
tagErrorElements[0].remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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,15 +273,15 @@ function setupImageUpload() {
|
||||||
// allow form submission
|
// allow form submission
|
||||||
disableUploadButton();
|
disableUploadButton();
|
||||||
return true;
|
return true;
|
||||||
} else {
|
|
||||||
//tags invalid
|
|
||||||
enableUploadButton(); // enable Upload button
|
|
||||||
anchorToTop(); // move view to top of page
|
|
||||||
|
|
||||||
// prevent form submission
|
|
||||||
event.preventDefault();
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//tags invalid
|
||||||
|
enableUploadButton(); // enable Upload button
|
||||||
|
anchorToTop(); // move view to top of page
|
||||||
|
|
||||||
|
// prevent form submission
|
||||||
|
event.preventDefault();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fileField.addEventListener('change', registerBeforeUnload);
|
fileField.addEventListener('change', registerBeforeUnload);
|
||||||
|
|
Loading…
Reference in a new issue