-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
128 lines (113 loc) · 3.72 KB
/
Copy pathscript.js
File metadata and controls
128 lines (113 loc) · 3.72 KB
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
126
127
128
let seuVotoPara = document.querySelector('.d-1-1 span');
let cargo = document.querySelector('.d-1-2 span');
let desc = document.querySelector('.d-1-4');
let aviso = document.querySelector('.d-2');
let lateral = document.querySelector('.d-1-rigth');
let numeros = document.querySelector('.d-1-3');
let etapaAtual = 0;
let numero = '';
let votoBranco = false;
let votos = [];
function comecarEtapa() {
let etapa = etapas[etapaAtual];
numero = '';
let numeroHtml = '';
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';
desc.innerHTML = '';
cargo.innerHTML = etapa.titulo;
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; //Irá retornar o próprio item em formato de array
} else {
return false
}
});
if (candidato.length > 0) {
candidato = candidato[0]; //É um objeto
seuVotoPara.style.display = 'block';
aviso.style.display = 'block';
desc.innerHTML = `Nome:${candidato.nome}<br/>Partido:${candidato.partido}`;
let fotosHtml = '';
//Dúvida nessa parte:
for(let i in candidato.fotos) {
if(candidato.fotos[i].small) {
fotosHtml += `<div class="d-1-image small"><img src="images/${candidato.fotos[i].url}" alt="" />${candidato.fotos[i].legenda}</div>`;
} else {
fotosHtml += `<div class="d-1-image"><img src="images/${candidato.fotos[i].url}" alt="" />${candidato.fotos[i].legenda}</div>`; //Fotos[i] é um objeto
}
}
lateral.innerHTML = fotosHtml;
} else {
seuVotoPara.style.display = 'block';
aviso.style.display = 'block';
desc.innerHTML = '<div class="aviso-grande pisca">VOTO NULO</div>';
}
}
function clicou(n) {
let eleNumero = document.querySelector('.numero.pisca');
if (eleNumero !== null) {
eleNumero.innerHTML = n;
numero = `${numero}${n}`; //Não entendi
eleNumero.classList.remove('pisca');
if (eleNumero.nextElementSibling !== null) {
eleNumero.nextElementSibling.classList.add('pisca');
} else {
atualizaInterface();
}
}
}
function branco() {
if (numero == '') {
votoBranco = true;
seuVotoPara.style.display = 'block';
aviso.style.display = 'block';
numeros.innerHTML = '';
desc.innerHTML = '<div class="aviso-grande pisca">VOTO EM BRANCO</div>';
} else {
alert('Para votar BRANCO é necessário que nehum número tenha sido digitado!')
}
}
function confirma() {
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--gigante pisca">FIM</div>';
console.log(votos);
}
}
}
function corrige() {
comecarEtapa();
}
comecarEtapa();