-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
108 lines (88 loc) · 2.92 KB
/
Copy pathapp.js
File metadata and controls
108 lines (88 loc) · 2.92 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
let text = document.getElementById('text')
console.log('Text ==> ', text);
let buttons = document.getElementsByClassName('action-btn')
console.log(buttons);
let fontOptions = document.getElementById('font-family')
console.log(fontOptions);
let fontSize = document.getElementById('font-size')
console.log(fontSize);
fontOptions.addEventListener('change',function(){
console.log(this.value);
if(this.value === 'monospace'){
text.style.fontFamily = 'monospace'
}
if(this.value === 'serif'){
text.style.fontFamily = 'serif'
}
if(this.value === 'sans-serif'){
text.style.fontFamily = 'sans-serif'
}
})
fontSize.addEventListener('change',function(){
console.log(this.value);
if(this.value === 'heading'){
text.style.fontSize = '41px'
}
if(this.value === 'sub-heading'){
text.style.fontSize = '25px'
}
if(this.value === 'normal'){
text.style.fontSize = '15px'
}
})
for (let i = 0; i < buttons.length; i++) {
buttons[i].addEventListener('click', function () {
console.log(this);
switch (this.innerText) {
case 'Bold':
if (text.style.fontWeight === 'bold') {
text.style.fontWeight = 'normal';
} else {
text.style.fontWeight = 'bold';
}
break;
case 'Italic':
if (text.style.fontStyle === 'italic') {
text.style.fontStyle = 'normal';
} else {
text.style.fontStyle = 'italic';
}
break;
case 'Underline':
if (text.style.textDecoration === 'underline') {
text.style.textDecoration = 'none';
} else {
text.style.textDecoration = 'underline';
}
break;
case 'Center':
if (text.style.textAlign === 'center') {
text.style.textAlign = 'left'; // reset back
} else {
text.style.textAlign = 'center';
}
break;
case 'Left':
if (text.style.textAlign === 'left') {
text.style.textAlign = 'initial'; // reset
} else {
text.style.textAlign = 'left';
}
break;
case 'Right':
if (text.style.textAlign === 'right') {
text.style.textAlign = 'initial';
} else {
text.style.textAlign = 'right';
}
break;
case 'Justify':
if (text.style.textAlign === 'justify') {
text.style.textAlign = 'initial';
} else {
text.style.textAlign = 'justify';
}
break;
}
});
}