-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
125 lines (113 loc) · 3.63 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
let seuVotoPara = document.querySelector('.d-1-1 span');
let cargo = document.querySelector('.d-1-2 span');
let descricao = document.querySelector('.d-1-4');
let aviso = document.querySelector('.d-2');
let lateral = document.querySelector('.d-1-right');
let numeros = document.querySelector('.d-1-3');
let etapaAtual = 0;
let numero = '';
let votoBranco = false;
let votos = [];
function comecarEtapa() {
let etapa = etapas[etapaAtual];
let numeroHtml = '';
numero = '';
votoBranco = false;
for(let i = 0; i < etapa.numeros; i++) {
if(i === 0) {
numeroHtml += '<div class="numero pisca"></div>';
} else {
numeroHtml += '<div class="numero"></div>';
}
}
seuVotoPara.style.display = 'none';
cargo.innerHTML = etapa.titulo;
descricao.innerHTML = '';
aviso.style.display = 'none';
lateral.innerHTML = '';
numeros.innerHTML = numeroHtml;
}
function atualizaInterface(){
let etapa = etapas[etapaAtual];
let candidato = etapa.candidatos.filter((item) => {
if(item.numero === numero) {
return true;
} else {
return false;
}
});
if(candidato.length > 0 ){
candidato = candidato[0];
seuVotoPara.style.display = 'block';
aviso.style.display = 'block';
descricao.innerHTML = `Nome: ${candidato.nome}<br/>Partido: ${candidato.partido}`;
let fotosHtml = '';
for(let i in candidato.fotos) {
if (candidato.fotos[i].small){
fotosHtml += `<div class="d-1-image small"><img src="img/${candidato.fotos[i].url}" alt="">${candidato.fotos[i].legenda}</div>`;
} else {
fotosHtml += `<div class="d-1-image"><img src="img/${candidato.fotos[i].url}" alt="">${candidato.fotos[i].legenda}</div>`;
}
}
lateral.innerHTML = fotosHtml;
} else {
seuVotoPara.style.display = 'block';
aviso.style.display = 'block';
descricao.innerHTML = '<div class="aviso-grande pisca">VOTO NULO</div>';
}
}
function clicou(n) {
let elNumero = document.querySelector('.numero.pisca');
if(elNumero !== null) {
elNumero.innerHTML = n;
numero = `${numero}${n}`;
elNumero.classList.remove('pisca');
if(elNumero.nextElementSibling !== null) {
elNumero.nextElementSibling.classList.add('pisca');
} else {
atualizaInterface();
}
}
}
function branco() {
if (numero === ''){
votoBranco = true;
seuVotoPara.style.display = 'block';
aviso.style.display = 'block';
numeros.innerHTML = '';
descricao.innerHTML = '<div class="aviso-grande-2 pisca">VOTO EM BRANCO</div>';
lateral.innerHTML = '';
} else {
alert('Para votar em BRANCO, não pode ter digitado nem um número')
}
}
function corrige() {
comecarEtapa();
}
function confirmar() {
let etapa = etapas[etapaAtual];
let votoConfirmado = false;
if (votoBranco === true) {
votoConfirmado = true;
votos.push({
etapa: etapas[etapaAtual].titulo,
voto: 'branco'
});
} else if (numero.length === etapa.numeros) {
votoConfirmado = true;
votos.push({
etapa: etapas[etapaAtual].titulo,
voto: numero
});
}
if (votoConfirmado) {
etapaAtual++;
if (etapas[etapaAtual] !== undefined) {
comecarEtapa();
} else {
document.querySelector('.tela').innerHTML = '<div class="aviso-grande-fim pisca">FIM</div>';
console.log(votos);
}
}
}
comecarEtapa();