-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
93 lines (87 loc) · 3.65 KB
/
index.html
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
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="bootstrap.min.css" rel="stylesheet">
<title>Case Convert JS</title>
</head>
<body>
<div class="container mt-4">
<h3 class="text-center">Converta as letras</h3>
<p class="lead text-center">Altere seu texto entre as opções:</p>
<div class="container">
<div class="row justify-content-center">
<div class="col-2">
<ul>
<li>Maiúscula</li>
<li>Minúscula</li>
<li>Título</li>
<li>Capitalizar</li>
</ul>
</div>
</div>
</div>
<form name="form_name" id="formulario" class="row justify-content-center">
<textarea type="text" name="texto" id="campo" class="col-10" rows="8"></textarea>
<div class="row justify-content-center">
<div class="d-inline-flex justify-content-center mt-3">
<select name="selecao" id="seletor">
<option value="">Escolha uma opção</option>
<option value="maiuscula">Maiúscula</option>
<option value="minuscula">Minúscula</option>
<option value="title">Título</option>
<option value="capital">Capitalizar</option>
</select>
</div>
<fieldset class="text-center mt-4">
<legend>Contador de Caracteres</legend>
<label for="count">Caracteres: </label>
<span id="count"></span>
</fieldset>
<span class="text-center mt-4"><strong>*Dica:</strong> para capitalizar, (iniciar toda frase com letra maiúscula), use apenas ponto final com um espaço no final ". "</span>
</div>
</form>
</div>
<script>
const form = document.getElementById('formulario')
const campo = document.getElementById('campo')
const escolha = document.querySelector('select')
campo.addEventListener('input', function(e) {
const caracteres = campo.value
const contador = caracteres.length
document.querySelector('#count').innerText = contador
})
escolha.addEventListener('change', setCase)
function setCase() {
const choice = escolha.value;
switch(choice) {
case 'maiuscula':
var str = campo.value.toUpperCase();
campo.value = str;
break
case 'minuscula':
var str = campo.value.toLowerCase();
campo.value = str;
break
case 'title':
var str = campo.value.toLowerCase();
var newstr = str.split(' ').map(
w => w[0].toUpperCase() + w.substring(1)
).join(' ')
campo.value = newstr;
break
case 'capital':
var str = campo.value.toLowerCase();
var newstr = str.split('. ').map(
w => w[0].toUpperCase() + w.substring(1)
).join('. ')
campo.value = newstr;
break
}
}
</script>
<script src="bootstrap.bundle.min.js"></script>
</body>
</html>