-
Notifications
You must be signed in to change notification settings - Fork 173
/
Copy pathindex.htm
173 lines (157 loc) · 5.21 KB
/
index.htm
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
<!DOCTYPE html>
<html>
<head>
<title>FIGlet Example</title>
</head>
<body>
<div>
<label for="font">Font:</label>
<select id="font">
<option value="3D Diagonal">3D Diagonal</option>
<option value="Dancing Font">Dancing Font</option>
<option value="Ghost">Ghost</option>
<option value="Graffiti">Graffiti</option>
<option value="Patorjk's Cheese">Patorjk's Cheese</option>
<option value="Standard" selected>Standard</option>
<option value="Pagga">Pagga</option>
<option value="Pawp">Pawp</option>
</select>
</div>
<div>
<label for="hLayout">Horizontal Layout:</label>
<select id="hLayout">
<option value="default" selected>Default</option>
<option value="full">Full</option>
<option value="fitted">Fitted</option>
<option value="controlled smushing">Controlled Smushing</option>
<option value="universal smushing">Universal Smushing</option>
</select>
</div>
<div>
<label for="vLayout">Vertical Layout:</label>
<select id="vLayout">
<option value="default" selected>Default</option>
<option value="full">Full</option>
<option value="fitted">Fitted</option>
<option value="controlled smushing">Controlled Smushing</option>
<option value="universal smushing">Universal Smushing</option>
</select>
</div>
<div>
<label for="width">Width:</label>
<select id="width">
<option value="none">none</option>
<option value="40" selected>40</option>
<option value="41">41</option>
<option value="42">42</option>
<option value="43">43</option>
<option value="44">44</option>
<option value="45">45</option>
<option value="80">80</option>
<option value="81">81</option>
<option value="100">100</option>
</select>
</div>
<div>
<label for="whitespaceBreak">Break on Whitespace (if width set):</label>
<select id="whitespaceBreak">
<option value="false">false</option>
<option value="true" selected>true</option>
</select>
</div>
<div>
<label for="inputText">Input:</label>
</div>
<textarea id="inputText" style="height: 100px; width: 200px">
test
123</textarea
>
<p></p>
<div>
<label for="outputFigDisplay">Output</label>
</div>
<pre>
0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999</pre
>
<div id="outputFigDisplay"></div>
<script type="text/javascript" src="../../lib/figlet.js?1"></script>
<script>
if (window.location.protocol === "file:") {
alert("fetch APi does not support file: protocol.");
}
figlet.defaults({
fontPath: "../../fonts",
});
figlet.preloadFonts(["Standard", "Ghost"], function () {
console.log("prefetching done (only did it for 2 fonts)!");
});
/*
Generates the put
*/
var update = function () {
var fontName = document.querySelector("#font option:checked").value,
inputText = document.querySelector("#inputText").value,
vLayout = document.querySelector("#vLayout option:checked").value,
hLayout = document.querySelector("#hLayout option:checked").value,
width = document.querySelector("#width option:checked").value,
whitespaceBreak = document.querySelector(
"#whitespaceBreak option:checked"
).value;
/*
How to use the text output.
The below call could also have been: figlet.text(...
*/
figlet(
inputText,
{
font: fontName,
horizontalLayout: hLayout,
verticalLayout: vLayout,
width: width === "none" ? undefined : width,
whitespaceBreak:
width === "none"
? undefined
: whitespaceBreak === "true"
? true
: false,
},
function (err, text) {
if (err) {
console.log("something went wrong...");
console.dir(err);
return;
}
document.querySelector("#outputFigDisplay").innerHTML =
"<pre>" + text + "</pre>";
}
);
/*
How to read the metadata for a font
*/
/*
figlet.metadata(fontName, function(err, options, headerComment) {
if (err) {
console.log('something went wrong...');
console.dir(err);
return;
}
console.dir(options);
console.log(headerComment);
});
*/
};
/*
GUI Controls
*/
document.querySelector("#hLayout").addEventListener("change", update);
document.querySelector("#vLayout").addEventListener("change", update);
document.querySelector("#font").addEventListener("change", update);
document.querySelector("#inputText").addEventListener("keyup", update);
document.querySelector("#width").addEventListener("change", update);
document
.querySelector("#whitespaceBreak")
.addEventListener("change", update);
update(); // init
</script>
</body>
</html>