- basic search functionality

This commit is contained in:
Alex Ling
2020-02-17 15:54:19 +00:00
parent 631feb5cf9
commit 5ed6b8db1a
4 changed files with 52 additions and 2 deletions

View File

@@ -23,3 +23,6 @@
.uk-logo > img {
max-height: 90px;
}
.uk-search {
width: 100%;
}

30
public/js/search.js Normal file
View File

@@ -0,0 +1,30 @@
$(function(){
var filter = [];
var result = [];
$('.uk-card-title').each(function(){
filter.push($(this).text());
});
$('.uk-search-input').keyup(function(){
var input = $('.uk-search-input').val();
var regex = new RegExp(input, 'i');
if (input === '') {
$('.item').each(function(){
$(this).removeAttr('hidden');
});
}
else {
filter.forEach(function(text, i){
result[i] = text.match(regex);
});
$('.item').each(function(i){
if (result[i]) {
$(this).removeAttr('hidden');
}
else {
$(this).attr('hidden', '');
}
});
}
});
});