-
Notifications
You must be signed in to change notification settings - Fork 0
/
gossip-grid.js
65 lines (55 loc) · 1.95 KB
/
gossip-grid.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
import { gossips } from "./gossip-grid.data.js"
let body = document.body
let form = document.createElement("form")
let texteria = document.createElement("textarea")
let button = document.createElement("button")
let filterdiv = document.createElement("div")
filterdiv.classList.add("ranges")
texteria.setAttribute("placeholder", "Share gossip!")
button.innerText = "Share gossip!"
form.classList.add("gossip")
body.append(form)
form.append(texteria)
form.append(button)
body.append(filterdiv)
form.addEventListener("submit", (e) => {
e.preventDefault()
const input = texteria.value.trim()
if (input.length > 0) {
gossips.unshift(input)
texteria.value = ""
updateGossipGrid()
}
})
function updateGossipGrid() {
document.querySelectorAll('.gossip:not(form)').forEach(gossip => gossip.remove())
gossips.forEach(gossipText => {
let div = document.createElement("div")
div.classList.add("gossip")
div.innerText = gossipText
div.style.width = `${document.getElementById("width").value}px`
div.style.fontSize = `${document.getElementById("fontSize").value}px`
div.style.backgroundColor = `hsl(278, 70%, ${document.getElementById("background").value}%)`
body.append(div)
})
}
function grid() {
filterdiv.innerHTML = ""
const ranges = [
{ id: "width", min: 200, max: 800, value: 200 },
{ id: "fontSize", min: 20, max: 40, value: 20 },
{ id: "background", min: 20, max: 75, value: 50 }
]
ranges.forEach(range => {
let filter = document.createElement("input")
filter.setAttribute("type", "range")
filter.setAttribute("id", range.id)
filter.setAttribute("min", range.min)
filter.setAttribute("max", range.max)
filter.setAttribute("value", range.value)
filter.addEventListener("input", updateGossipGrid)
filterdiv.append(filter)
})
updateGossipGrid()
}
export { grid }