Last active
April 23, 2019 23:10
-
-
Save jeffersontpadua/35d4751c85012a6c43e98a8c4a54d703 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const candidatoVotado = document.getElementById('candidato-votado'); | |
const identificacaoVoto = document.getElementById('identificacao-voto'); | |
const corrigir = document.getElementById('corrigir'); | |
const confirmar = document.getElementById('confirmar'); | |
const fotoCandidato = document.getElementById('foto-candidato'); | |
const form = document.getElementById('formulario'); | |
if(!candidatoVotado) { | |
throw new Error('Nenhum input com o id candidato-votado adicionado'); | |
} | |
if(!identificacaoVoto) { | |
throw new Error('Nenhum H1 com o id identificacao-voto adicionado') | |
} | |
if(!corrigir) { | |
throw new Error('Nenhum button com o id corrigir adicionado') | |
} | |
if(!fotoCandidato) { | |
throw new Error('Nenhum button com o id foto-candidato adicionado') | |
} | |
const digitos = document.getElementsByClassName('digito-voto'); | |
function alterarVoto(voto) { | |
candidatoVotado.value = voto; | |
identificacaoVoto.innerHTML = '#' + candidatoVotado.value; | |
fotoCandidato.style.backgroundImage = "url('resources/img/" + voto + '.jpg' + "')"; | |
} | |
function onClickDigito(digito) { | |
alterarVoto(candidatoVotado.value + digito); | |
} | |
for(let index = 0; index < digitos.length; index++) { | |
console.log('Adicionando click events'); | |
const item = digitos.item(index); | |
item.addEventListener('click', onClickDigito.bind({}, item.innerHTML)) | |
} | |
corrigir.addEventListener('click', () => { | |
alterarVoto(''); | |
}); | |
confirmar.addEventListener('click', () => { | |
form.submit(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment