From 12b1c76fefc78b2a0fa54138a550c73802b1847d Mon Sep 17 00:00:00 2001 From: Neil Mitchell Date: Thu, 11 Jan 2007 17:07:09 +0000 Subject: Add searching on the index page --- html/haddock-util.js | 27 +++++++++++++++++++++++++++ src/Haddock/Backends/Html.hs | 14 +++++++++++--- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/html/haddock-util.js b/html/haddock-util.js index 4280d19c..fe471453 100644 --- a/html/haddock-util.js +++ b/html/haddock-util.js @@ -13,3 +13,30 @@ function toggle(button,id) n.display = "none"; } } + + +function quick_search() +{ + perform_search(false); +} + +function full_search() +{ + perform_search(true); +} + + +function perform_search(full) +{ + var text = document.getElementById("searchbox").value.toLowerCase(); + var table = document.getElementById("indexlist"); + var children = table.firstChild.childNodes; + for (var i = 0; i < children.length; i++) + { + var c = children[i]; + var s = c.firstChild.firstChild.data; + var show = s.toLowerCase().indexOf(text) != -1; + + c.style.display = (show ? "" : "none"); + } +} diff --git a/src/Haddock/Backends/Html.hs b/src/Haddock/Backends/Html.hs index 36be7909..d46e0df4 100644 --- a/src/Haddock/Backends/Html.hs +++ b/src/Haddock/Backends/Html.hs @@ -413,11 +413,12 @@ ppHtmlIndex odir doctitle maybe_package maybe_html_help_format let html = header (documentCharacterEncoding +++ thetitle (toHtml (doctitle ++ " (Index)")) +++ - styleSheet) +++ + styleSheet +++ + (script ! [src jsFile, thetype "text/javascript"] $ noHtml)) +++ body << vanillaTable << ( simpleHeader doctitle maybe_contents_url Nothing maybe_source_url maybe_wiki_url - index_html + search_box index_html ) writeFile (pathJoin [odir, indexHtmlFile]) (renderHtml html) @@ -430,7 +431,14 @@ ppHtmlIndex odir doctitle maybe_package maybe_html_help_format Just "devhelp" -> return () Just format -> fail ("The "++format++" format is not implemented") where - index_html = td << table ! [cellpadding 0, cellspacing 5] << + -- colspan 2, marginheight 5 + search_box :: HtmlTable + search_box = tda [colspan 2, thestyle "padding-top:5px;"] << search + where + search :: Html + search = "Search: " +++ input ! [identifier "searchbox", strAttr "onkeyup" "quick_search()"] +++ " " +++ input ! [value "Search", thetype "button", onclick "full_search()"] + + index_html = td << table ! [identifier "indexlist", cellpadding 0, cellspacing 5] << aboves (map indexElt index) indexInitialLetterLinks = -- cgit v1.2.3