generated from github/codespaces-blank
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
250 lines (238 loc) · 5.95 KB
/
script.js
File metadata and controls
250 lines (238 loc) · 5.95 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
let optionsButtons = document.querySelectorAll(".option-button");
let advancedOptionButton = document.querySelectorAll(".adv-option-button");
let fontName = document.getElementById("fontName");
let fontSizeRef = document.getElementById("fontSize");
let writingArea = document.getElementById("text-input");
let linkButton = document.getElementById("createLink");
let alignButtons = document.querySelectorAll(".align");
let spacingButtons = document.querySelectorAll(".spacing");
let formatButtons = document.querySelectorAll(".format");
let scriptButtons = document.querySelectorAll(".script");
let fontList = [
"Agency FB",
"Algerian",
"Arial",
"Arial Black",
"Arial Narrow",
"Arial Rounded MT Bold",
"Baskerville Old Face",
"Bell MT",
"Berlin Sans FB",
"Berlin Sans FB Demi",
"Blackadder ITC",
"Bodoni MT",
"Bodoni MT Black",
"Bodoni MT Condensed",
"Bodoni MT Poster Compressed",
"Book Antiqua",
"Bookman Old Style",
"Bookshelf Symbol 7",
"Bradley Hand ITC",
"Britannic Bold",
"Broadway",
"Brush Script MT",
"Calibri",
"Californian FB",
"Calisto MT",
"Cambria",
"Cambria Math",
"Candara",
"Castellar",
"Centaur",
"Century",
"Century Gothic",
"Century Schoolbook",
"Chiller",
"Colonna MT",
"Comic Sans MS",
"Consolas",
"Constatia",
"Cooper Black",
"Copperplate Gothic Bold",
"Copperplate Gothic Light",
"Corbel",
"Courier",
"Courier New",
"Curlz MT",
"Edwardian Script ITC",
"Elephant",
"Engravers MT",
"Eras Bold ITC",
"Eras Demi ITC",
"Eras Light ITC",
"Eras Medium ITC",
"Felix Titling",
"Fixedsys",
"Footlight MT Light",
"Forte",
"Franklin Gothic Book",
"Franklin Gothic Demi",
"Franklin Gothic Demi Cond",
"Franklin Gothic Heavy",
"Franklin Gothic Medium",
"Franklin Gothic Medium Cond",
"Freestyle Script",
"French Script MT",
"Gabriola",
"Garamond",
"Georgia",
"Gigi",
"Gill Sans MT",
"Gill Sans MT Condensed",
"Gill Sans MT Ext Condensed Bold",
"Gill Sans Ultra Bold",
"Gill Sans Ultra Bold Condensed",
"Gloucester MT Extra Condensed",
"Goudy Old Style",
"Goudy Stout",
"Haettenschweiler",
"Harlow Solid Italic",
"Harrington",
"High Tower Text",
"Impact",
"Imprint MT Shadow",
"Informal Roman",
"Jokerman",
"Juice ITC",
"Kristen ITC",
"Kunstler Script",
"Lucida Bright",
"Lucida Calligraphy",
"Lucida Console",
"Lucida Fax",
"Lucida Handwriting",
"Lucida Sans",
"Lucida Sans Typewriter",
"Lucida Typewriter",
"Lucida Sans Unicode",
"Magneto",
"Maiandra GD",
"Matura MT Script Capitals",
"Microsoft Sans Serif",
"Mistral",
"Modern",
"Modern No. 20",
"Monotype Corsiva",
"MS Outlook",
"MS Reference Sans Serif",
"MS Reference Specialty",
"MS Sans Serif",
"MS Serif",
"MT Extra",
"Niagara Engraved",
"Niagara Solid",
"OCR A Extended",
"Old English Text MT",
"Onyx",
"Palace Script MT",
"Palatino Linotype",
"Papyrus",
"Parchment",
"Perpetua",
"Perpetua Titling MT",
"Playbill",
"Poor Richard",
"Pristina",
"Rage Italic",
"Ravie",
"Rockwell",
"Rockwell Condensed",
"Rockwell Extra Bold",
"Roman",
"Script",
"Script MT Bold",
"Segoe Print",
"Segoe Script",
"Segoe UI",
"Segoe UI Light",
"Segoe UI Semibold",
"Segoe UI Symbol",
"Showcard Gothic",
"Small Fonts",
"Snap ITC",
"Stencil",
"Symbol",
"System",
"Tahoma",
"Tempus Sans ITC",
"Terminal",
"Times New Roman",
"Trebuchet MS",
"Tw Cen MT",
"Tw Cen MT Condensed",
"Tw Cen MT Condensed Extra Bold",
"Verdana",
"Viner Hand ITC",
"Vivaldi",
"Vladimir Script",
"Webdings",
"Wide Latin",
"Wingdings",
"Wingdings 2",
"Wingdings 3",
];
const intializer = () => {
highlighter(alignButtons, true);
highlighter(spacingButtons, true);
highlighter(formatButtons, false);
highlighter(scriptButtons, true);
fontList.map((value) => {
let option = document.createElement("option");
option.value = value;
option.innerHTML = value;
fontName.appendChild(option);
});
for (let i = 1; i <= 200; i++) {
let option = document.createElement("option");
option.value = i;
option.innerHTML = i;
fontSizeRef.appendChild(option);
}
fontSizeRef.value = 4;
};
const modifyText = (command, defaultUi, value) => {
document.execCommand(command, defaultUi, value);
};
optionsButtons.forEach((button) => {
button.addEventListener("click", () => {
modifyText(button.id, false, null);
});
});
advancedOptionButton.forEach((button) => {
button.addEventListener("change", () => {
modifyText(button.id, false, button.value);
});
});
linkButton.addEventListener("click", () => {
let userLink = prompt("Enter a URL to insert :");
if (/http/i.test(userLink)) {
modifyText(linkButton.id, false, userLink);
} else {
userLink = "http://" + userLink;
modifyText(linkButton.id, false, userLink);
}
});
const highlighter = (className, needsRemoval) => {
className.forEach((button) => {
button.addEventListener("click", () => {
if (needsRemoval) {
let alreadyActive = false;
if (button.classList.contains("active")) {
alreadyActive = true;
}
highlighterRemover(className);
if (!alreadyActive) {
button.classList.add("active");
}
} else {
button.classList.toggle("active");
}
});
});
};
const highlighterRemover = (className) => {
className.forEach((button) => {
button.classList.remove("active");
});
};
window.onload = intializer();