-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
90 lines (82 loc) · 3.36 KB
/
Copy pathscript.js
File metadata and controls
90 lines (82 loc) · 3.36 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
const $ = document.querySelector.bind(document)
// container com textos
const divText = $('.text')
// guardando ultimo input selecionado
let lastInput
// criando eventos dos botões
$('.t').addEventListener('click', () => {
if (!lastInput) return alert('Nenhum componente selecionado')
if (lastInput.style.fontSize === '25px') lastInput.style.fontSize = '15px'
else lastInput.style.fontSize = '25px'
})
$('.b').addEventListener('click', () => {
if (!lastInput) return alert('Nenhum componente selecionado')
if (lastInput.style.fontWeight === 'bold') lastInput.style.fontWeight = ''
else lastInput.style.fontWeight = 'bold'
})
$('.i').addEventListener('click', () => {
if (!lastInput) return alert('Nenhum componente selecionado')
if (lastInput.style.fontStyle === "italic") lastInput.style.fontStyle = ""
else lastInput.style.fontStyle = "italic"
})
$('.u').addEventListener('click', () => {
if (!lastInput) return alert('Nenhum componente selecionado')
if (lastInput.style.textDecoration === "underline") {
lastInput.style.textDecoration = ''
}else lastInput.style.textDecoration = 'underline'
})
$('.s').addEventListener('click', () => {
if (!lastInput) return alert('Nenhum componente selecionado')
if (lastInput.style.textDecoration === "line-through") {
lastInput.style.textDecoration = ''
}else lastInput.style.textDecoration = 'line-through'
})
$('.link').addEventListener('click', () => {
if (!lastInput) return alert('Nenhum componente selecionado')
const domain = prompt("Digite o link do dominio que deseja redirecionar\n obs: incluindo o https://")
if (!domain) return;
const content = lastInput.value
const container = lastInput.parentElement
lastInput.remove()
const link = document.createElement('a')
link.setAttribute('href', domain)
link.setAttribute('class', 'input-link')
link.innerHTML = content
container.insertAdjacentElement('afterbegin', link)
})
$('.left').addEventListener('click', () => {
if (!lastInput) return alert('Nenhum componente selecionado')
lastInput.style.textAlign = 'left'
})
$('.center').addEventListener('click', () => {
if (!lastInput) return alert('Nenhum componente selecionado')
lastInput.style.textAlign = 'center'
})
$('.right').addEventListener('click', () => {
if (!lastInput) return alert('Nenhum componente selecionado')
lastInput.style.textAlign = 'right'
})
$('.justify').addEventListener('click', () => {
if (!lastInput) return alert('Nenhum componente selecionado')
lastInput.style.textAlign = 'justify'
})
$('.add').addEventListener('click', () => {
const container = document.createElement('div')
container.setAttribute('class', 'text-box')
const text = document.createElement('input')
text.setAttribute('type', 'text')
text.setAttribute('onfocus', 'saveLastState(event)')
const span = document.createElement('span')
span.setAttribute('class', 'delete')
span.setAttribute('onclick', 'handleRemove(event)')
span.innerHTML = '<i class="fas fa-times"></i>'
container.appendChild(text)
container.appendChild(span)
divText.appendChild(container)
})
document.addEventListener('keypress', event => console.log(event.key))
function handleRemove (event) {
event.target.parentElement.remove()
lastInput = null
}
function saveLastState (event) { lastInput = event.target }