Generalized Search

Generalized the search to work with any table
with some basic classes and some updated
JavaScript, we can now search colors and emojis.
This commit is contained in:
Khalid Abuhakmeh
2020-10-02 13:19:00 -04:00
committed by Patrik Svensson
parent b1db8a9403
commit e0947708c9
6 changed files with 68 additions and 45 deletions

View File

@ -1,30 +0,0 @@
$(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

View File

@ -0,0 +1,35 @@
$(document).ready(function () {
$('.filter').each(function () {
let input = this;
let table = document.getElementById(input.dataset.table);
input.onkeyup = function (event) {
if (event.key === "Enter") {
event.preventDefault();
event.stopPropagation();
return false;
}
let value = input.value.toUpperCase();
let rows = table.getElementsByClassName('search-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