-
Notifications
You must be signed in to change notification settings - Fork 0
/
typechecker.js
91 lines (62 loc) · 2.43 KB
/
typechecker.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
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 sentenceTag = document.querySelector('input[type="text"]')
const typesizeTag = document.querySelector('input[name="typesize"]')
const typesizeOutput = document.querySelector('span.typesize-output')
const lineheightTag = document.querySelector('input[name="lineheight"]')
const lineheightOutput = document.querySelector('span.lineheight-output')
const fontweightTag = document.querySelector('input[name="fontweight"]')
const fontweightOutput = document.querySelector('span.fontweight-output')
const italicTag = document.querySelector('input[name="italic"]')
const typefaceTag = document.querySelector('select[name="typeface"]')
const colorTags = document.querySelectorAll('div.colors div')
const outputTag = document.querySelector("textarea.output")
const originalText = outputTag.value;
// when type the sentence, update the output. If there is no value, use original text
sentenceTag.addEventListener("keyup", function () {
if (this.value) {
outputTag.value = this.value;
} else {
outputTag.value = originalText;
}
})
// when I type in the output, update the sentence
outputTag.addEventListener("keyup", function() {
sentenceTag.value = this.value;
})
// when change the slider, update the text size
typesizeTag.addEventListener("input", function() {
outputTag.style.fontSize = this.value + "px";
typesizeOutput.innerHTML= this.value + "pixels"
})
// line height
lineheightTag.addEventListener("input", function() {
outputTag.style.lineHeight = this.value;
lineheightOutput.innerHTML = this.value;
})
// font weight
fontweightTag.addEventListener("input", function() {
outputTag.style.fontWeight = this.value;
fontweightOutput.innerHTML = this.value;
})
// when box is checked make italic
italicTag.addEventListener("change", function() {
if(this.checked) {
outputTag.style.fontStyle = "italic"
} else {
outputTag.style.fontStyle = "normal"
}
})
// change the font
typefaceTag.addEventListener("input", function() {
outputTag.style.fontFamily = this.value;
})
// change background and text color, and make this tag as "selected"
colorTags.forEach((tag) => {
tag.addEventListener("click", function() {
outputTag.style.backgroundColor = this.style.backgroundColor
outputTag.style.color = this.style.color
colorTags.forEach(tag => {
tag.classList.remove("selected")
})
this.classList.add("selected")
})
})