Skip to content

Commit

Permalink
fix eslint errors since new config
Browse files Browse the repository at this point in the history
  • Loading branch information
goapunk authored and hom3mad3 committed Oct 31, 2024
1 parent 6ff8b5f commit 8101a0b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 62 deletions.
1 change: 1 addition & 0 deletions apps/captcha/assets/captcheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
117 changes: 55 additions & 62 deletions apps/home/assets/newsletter.js
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8101a0b

Please sign in to comment.