From 8101a0bb0cdd13243410b9d1ac845fc4526d451b Mon Sep 17 00:00:00 2001 From: Julian Dehm Date: Wed, 30 Oct 2024 15:41:47 +0100 Subject: [PATCH] fix eslint errors since new config --- apps/captcha/assets/captcheck.js | 1 + apps/home/assets/newsletter.js | 117 +++++++++++++++---------------- 2 files changed, 56 insertions(+), 62 deletions(-) diff --git a/apps/captcha/assets/captcheck.js b/apps/captcha/assets/captcheck.js index a637d1b4..1dee2187 100644 --- a/apps/captcha/assets/captcheck.js +++ b/apps/captcha/assets/captcheck.js @@ -82,6 +82,7 @@ window.onload = function () { } } + // eslint-disable-next-line let nonce = '' /* Loop over all the CAPTCHA containers on the page, setting up a different CAPTCHA in each */ Array.prototype.forEach.call(document.getElementsByClassName('captcheck_container'), function (container) { diff --git a/apps/home/assets/newsletter.js b/apps/home/assets/newsletter.js index 3453edb9..dc0e455a 100644 --- a/apps/home/assets/newsletter.js +++ b/apps/home/assets/newsletter.js @@ -1,80 +1,73 @@ -document.addEventListener('DOMContentLoaded', function() { - document.getElementById('newsletter_subscribe').addEventListener('click', function() { - var newsletterForm = document.getElementById('newsletter_form') +document.addEventListener('DOMContentLoaded', function () { + document.getElementById('newsletter_subscribe').addEventListener('click', function () { + const newsletterForm = document.getElementById('newsletter_form') window.ValidateForm(newsletterForm) }) }) -function ValidateForm() { - var mailformat = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/ - var formInput = document.getElementById('id_email') - var inputValid = document.getElementById("id_email_valid") - var inputInvalid = document.getElementById("id_email_invalid") - var formCheckbox = document.getElementById('id_data_protection') - var formCheckboxInvalid = document.getElementById("id_data_protection_invalid") - var formCheckboxLabel = document.getElementById("id_data_protection_label") - var formAction = document.getElementById("id_form_action") +function ValidateForm () { + const mailformat = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/ + const formInput = document.getElementById('id_email') + const inputValid = document.getElementById('id_email_valid') + const inputInvalid = document.getElementById('id_email_invalid') + const formCheckbox = document.getElementById('id_data_protection') + const formCheckboxInvalid = document.getElementById('id_data_protection_invalid') + const formCheckboxLabel = document.getElementById('id_data_protection_label') + const formAction = document.getElementById('id_form_action') - if(formInput.value.match(mailformat) && formCheckbox.checked) - { - formInput.classList.add("u-d-none") - formCheckbox.classList.add("u-d-none") - formCheckboxLabel.classList.add("u-d-none") - inputValid.classList.remove("u-d-none") - formCheckboxInvalid.classList.add("u-d-none") - inputInvalid.classList.add("u-d-none") - formAction.classList.add("u-d-none") - document.getElementById("newsletter_form").submit() - return false - } - else if (formInput.value.match(mailformat)) - { - formCheckbox.classList.add("is-invalid") - formCheckboxInvalid.classList.remove("u-d-none") - formInput.classList.remove("is-invalid") - inputInvalid.classList.add("u-d-none") - } - else if (formCheckbox.checked) - { - formInput.classList.add("is-invalid") - inputInvalid.classList.remove("u-d-none") - formCheckbox.classList.remove("is-invalid") - formCheckboxInvalid.classList.add("u-d-none") - } - else - { - formInput.classList.add("is-invalid") - formCheckbox.classList.add("is-invalid") - formCheckboxInvalid.classList.remove("u-d-none") - inputInvalid.classList.remove("u-d-none") - document.newsletter_form.input2.focus() - return false - } + if (formInput.value.match(mailformat) && formCheckbox.checked) { + formInput.classList.add('u-d-none') + formCheckbox.classList.add('u-d-none') + formCheckboxLabel.classList.add('u-d-none') + inputValid.classList.remove('u-d-none') + formCheckboxInvalid.classList.add('u-d-none') + inputInvalid.classList.add('u-d-none') + formAction.classList.add('u-d-none') + document.getElementById('newsletter_form').submit() + return false + } else if (formInput.value.match(mailformat)) { + formCheckbox.classList.add('is-invalid') + formCheckboxInvalid.classList.remove('u-d-none') + formInput.classList.remove('is-invalid') + inputInvalid.classList.add('u-d-none') + } else if (formCheckbox.checked) { + formInput.classList.add('is-invalid') + inputInvalid.classList.remove('u-d-none') + formCheckbox.classList.remove('is-invalid') + formCheckboxInvalid.classList.add('u-d-none') + } else { + formInput.classList.add('is-invalid') + formCheckbox.classList.add('is-invalid') + formCheckboxInvalid.classList.remove('u-d-none') + inputInvalid.classList.remove('u-d-none') + document.newsletter_form.input2.focus() + return false } +} -function getCookie(name) { +function getCookie (name) { let cookieValue = null if (document.cookie && document.cookie !== '') { - const cookies = document.cookie.split(';') - for (let i = 0; i < cookies.length; i++) { - const cookie = cookies[i].trim() - // Does this cookie string begin with the name we want? - if (cookie.substring(0, name.length + 1) === (name + '=')) { - cookieValue = decodeURIComponent(cookie.substring(name.length + 1)) - break - } + const cookies = document.cookie.split(';') + for (let i = 0; i < cookies.length; i++) { + const cookie = cookies[i].trim() + // Does this cookie string begin with the name we want? + if (cookie.substring(0, name.length + 1) === (name + '=')) { + cookieValue = decodeURIComponent(cookie.substring(name.length + 1)) + break } + } } return cookieValue } -var form = document.getElementById('newsletter_form'), - input = document.createElement('input') +const form = document.getElementById('newsletter_form') +const input = document.createElement('input') - input.name = "csrfmiddlewaretoken" - input.type = "hidden" - input.value = getCookie('csrftoken') +input.name = 'csrfmiddlewaretoken' +input.type = 'hidden' +input.value = getCookie('csrftoken') - form.appendChild(input) +form.appendChild(input) window.ValidateForm = ValidateForm