From 6d3e4dd166439a00df5898dd4c7151ee1c524638 Mon Sep 17 00:00:00 2001 From: Jochen Topf Date: Thu, 26 Feb 2015 15:43:36 +0100 Subject: Move some functions from search.js.erb into taginfo.js. These functions are generally useful and will be used in other parts of the taginfo ui soon. --- web/public/js/taginfo.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'web/public') diff --git a/web/public/js/taginfo.js b/web/public/js/taginfo.js index 5a06361..c8b7a25 100644 --- a/web/public/js/taginfo.js +++ b/web/public/js/taginfo.js @@ -228,6 +228,31 @@ function link_to_url(url) { ); } +function highlight(str, query) { + return html_escape(str).replace(new RegExp('(' + html_escape(query) + ')', 'gi'), "$1"); +} + +function link_to_key_with_highlight(key, query) { + return link( + url_for_key(key), + highlight(key, query) + ); +} + +function link_to_value_with_highlight(key, value, query) { + return link( + url_for_tag(key, value), + highlight(value, query) + ); +} + +function link_to_rtype_with_highlight(rtype, query) { + return link( + url_for_rtype(rtype), + highlight(rtype, query) + ); +} + /* ============================ */ function html_escape(text) { -- cgit v1.2.3