diff options
-rw-r--r-- | html/haddock-util.js | 27 | ||||
-rw-r--r-- | 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 = |