diff --git a/public/css/mango.css b/public/css/mango.css index ed3f5c5..1eb7922 100644 --- a/public/css/mango.css +++ b/public/css/mango.css @@ -23,3 +23,6 @@ .uk-logo > img { max-height: 90px; } +.uk-search { + width: 100%; +} diff --git a/public/js/search.js b/public/js/search.js new file mode 100644 index 0000000..d840353 --- /dev/null +++ b/public/js/search.js @@ -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', ''); + } + }); + } + }); +}); diff --git a/src/views/index.ecr b/src/views/index.ecr index 9b118a2..ae384b5 100644 --- a/src/views/index.ecr +++ b/src/views/index.ecr @@ -1,8 +1,14 @@

Library

<%= titles.size %> titles found

+
+ +
<%- titles.each_with_index do |t, i| -%> -
+