From d91e09af7d968afddf6f4f963611e0e37b0bbbd5 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Tue, 28 Apr 2015 14:01:30 +0200 Subject: Add simple filter function --- Main.hs | 8 ++++++-- data/script.js | 13 +++++++++++++ data/style.css | 1 + 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Main.hs b/Main.hs index 8d65915..fd18465 100644 --- a/Main.hs +++ b/Main.hs @@ -160,10 +160,14 @@ introduction = section_ $ do protocols :: Database -> Html () protocols db = section_ [id_ "protocols"] $ do h2_ "Protocols" - div_ [id_ "protosort"] $ do + div_ [id_ "protosort", class_ "form-inline"] $ do + label_ [for_ "filter"] "Filter" + " " + input_ [id_ "filter", type_ "text", class_ "form-control"] + " " label_ [for_ "sort"] "Sort by" " " - select_ [id_ "sort"] $ do + select_ [id_ "sort", class_ "form-control"] $ do option_ [value_ "name"] "Name" option_ [value_ "year"] "Year" forM_ (M.toList $ dalgos db) (protoentry db) diff --git a/data/script.js b/data/script.js index 94175b1..997a02e 100644 --- a/data/script.js +++ b/data/script.js @@ -18,5 +18,18 @@ $(document).ready (function () { $('#sort').change (function () { sortproto ($(this).val ()); }); + $('#filter').keyup (function () { + var search = $(this).val ().toLowerCase (); + var items = $('#protocols .protocol'); + for (var i = 0; i < items.length; i++) { + var e = $(items[i]); + if (e.data ('name').toLowerCase ().indexOf (search) >= 0) { + e.show (); + } else { + e.hide (); + } + } + }); + $('#protosort').show (); sortproto ('name'); }); diff --git a/data/style.css b/data/style.css index cc65ba2..41b24dd 100644 --- a/data/style.css +++ b/data/style.css @@ -1,5 +1,6 @@ #protosort { text-align: right; + display: hidden; } .protocol dt { -- cgit v1.2.3