-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
125 lines (111 loc) · 3.45 KB
/
script.js
File metadata and controls
125 lines (111 loc) · 3.45 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
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 = true
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.name}<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="src/${candidato.fotos[i].url}">${candidato.fotos[i].legenda}</div>`
} else {
fotosHtml += `<div class="d-1-image"><img src="src/${candidato.fotos[i].url}">${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>'
}
console.log('candidato', candidato)
}
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(){
numero = ''
votoBranco = true
seuVotoPara.style.display = 'block'
aviso.style.display = 'block'
numeros.innerHTML = ''
descricao.innerHTML = '<div class="aviso--grande pisca">VOTO EM BRANCO</div>'
lateral.innerHTML = ''
}
function corrige(){
comecarEtapa()
}
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)
}
}
}
comecarEtapa()