aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--public/filter.js11
-rw-r--r--views/index.slim13
2 files changed, 23 insertions, 1 deletions
diff --git a/public/filter.js b/public/filter.js
new file mode 100644
index 0000000..0fd918f
--- /dev/null
+++ b/public/filter.js
@@ -0,0 +1,11 @@
+document.getElementById('filter').addEventListener('change', function (e){
+ var value = e.target.value;
+ let results = document.querySelectorAll('li[data-gitsource]');
+ results.forEach(function (i) {
+ if (value == '-' || i.getAttribute('data-gitsource') == value) {
+ i.style.display = 'block';
+ } else {
+ i.style.display = 'none';
+ }
+ });
+});
diff --git a/views/index.slim b/views/index.slim
index 5a4f96f..64bff9e 100644
--- a/views/index.slim
+++ b/views/index.slim
@@ -7,9 +7,18 @@ form action=url('/') method='get'
input type='submit' value='Search'
- if @results && @results.any?
+ p
+ | Filter:
+ select#filter<
+ option value='-' selected='selected'
+ | All
+ - @results.map { |r| r['source'] }.uniq.sort.each do |v|
+ option value=v
+ = v
+
ul.result
- @results.each do |r|
- li
+ li data-gitsource=r['source']
img.source src=r['icon'] alt=r['source'] title=r['source']
- unless r['avatar_url'].nil?
img.avatar src=r['avatar_url'] alt=''
@@ -22,3 +31,5 @@ form action=url('/') method='get'
time.light< = r['last_activity_at']
- if !r['description'].nil? && r['description'] != ''
p = r['description']
+
+script src="/filter.js"