Skip to content

Commit 0869294

Browse files
committed
Support for images
1 parent dea0616 commit 0869294

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/index.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ function initNameFilterMap(data: SearchEntry[]) {
110110
nameFilterMap['.'] = 'FULL STOP';
111111
}
112112

113+
var useImages = false;
114+
113115
// translates from a hex codepoint string to the actual character
114116
function codeToString(code: string):string {
115117
return String.fromCodePoint(parseInt(code, 16));
@@ -239,6 +241,11 @@ function fmtExample(cell: CellComponent) {
239241
if (!val) {
240242
return "";
241243
}
244+
if (useImages) {
245+
const codepoint = cell.getRow().getData().code;
246+
const prefix = codepoint.slice(0, -2);
247+
return `<img src="https://ucd-images.fileformat.info/${prefix}/u${codepoint.toLowerCase()}.svg" alt="U+${codepoint}" style="height:2em;">`;
248+
}
242249

243250
const mapped = exampleMap[val] || val;
244251
return `<span style="font-size:2em;">${mapped}</span>`;
@@ -455,6 +462,9 @@ async function main() {
455462
detail = (value == "1" || value.toLowerCase() == "true");
456463
continue;
457464
}
465+
if (key == "images") {
466+
useImages = (value == "1" || value.toLowerCase() == "true");
467+
}
458468
if (key && value) {
459469
filters.push({ field: key, type: "=", value: value });
460470
}
@@ -622,7 +632,8 @@ async function main() {
622632
footerElement: `<span class="w-100 mx-2 my-1">
623633
<img src="/favicon.svg" class="pe-2" style="height:1.2em;" alt="UnicodeSearch logo"/><span class=" d-none d-sm-inline">UnicodeSearch</span>
624634
<span id="rowcount" class="px-3">Rows: ${data.length.toLocaleString()}</span>
625-
<input id="showhidecolumns" type="checkbox" class="ms-2 me-1" ${detail ? "checked" : ""} title="Toggle detail columns" /> <span class="d-none d-md-inline">Show/Hide Detail Columns</span><span class="d-md-none">Details</span>
635+
<input id="showhidecolumns" type="checkbox" class="ms-2 me-1" ${detail ? "checked" : ""} title="Toggle detail columns" /> <span class="d-none d-md-inline">Show detail columns</span><span class="d-md-none">Details</span>
636+
<input id="imagecheckbox" type="checkbox" class="ms-2 me-1" ${useImages ? "checked" : ""} title="Font vs Images" /> <span class="d-none d-md-inline">Use images in examples</span><span class="d-md-none">Images</span>
626637
<a class="d-none d-lg-block float-end" href="https://github.com/FileFormatInfo/unicodesearch">Source</a>
627638
</span>`,
628639
});
@@ -663,6 +674,17 @@ async function main() {
663674
}
664675
window.history.replaceState(null, "", "?" + qs.toString());
665676
}
677+
document.getElementById("imagecheckbox")!.onclick = () => {
678+
useImages = !useImages;
679+
const qs = new URLSearchParams(window.location.search);
680+
if (useImages) {
681+
qs.set("images", "1");
682+
} else {
683+
qs.delete("images");
684+
}
685+
window.history.replaceState(null, "", "?" + qs.toString());
686+
table.redraw(true);
687+
};
666688
});
667689

668690
document.getElementById("loading")!.style.display = "none";

0 commit comments

Comments
 (0)