mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-16 08:52:50 +08:00

This adds a typeahead search feature for the very large emoji table. It filters as you type to find if an emoji exists or not. The JavaScript could be adapted to work on all tables in the future.
30 lines
835 B
JavaScript
30 lines
835 B
JavaScript
$(document).ready(function () {
|
|
let input = document.getElementById('emoji-search');
|
|
let table = document.getElementById('emoji-results');
|
|
|
|
input.onkeyup = function (event) {
|
|
|
|
if (event.key === "Enter") {
|
|
event.preventDefault();
|
|
event.stopPropagation();
|
|
return false;
|
|
}
|
|
|
|
let value = input.value.toUpperCase();
|
|
let rows = table.getElementsByClassName('emoji-row');
|
|
|
|
for (let i = 0; i < rows.length; i++) {
|
|
let row = rows[i];
|
|
|
|
let match =
|
|
new RegExp(value, "i").test(row.textContent) ||
|
|
value === '';
|
|
|
|
if (match) {
|
|
row.style.display = 'table-row';
|
|
} else {
|
|
row.style.display = 'none';
|
|
}
|
|
}
|
|
}; // keyup
|
|
}); // ready
|