diff options
author | Jochen Topf <jochen@topf.org> | 2012-01-23 23:10:26 +0100 |
---|---|---|
committer | Jochen Topf <jochen@topf.org> | 2012-01-23 23:10:26 +0100 |
commit | c07a5bce1a4815453e643309697e92eff5cbf667 (patch) | |
tree | 0ef02fa8ec41fbd12d6c45cb17be78c9286d6003 /web | |
parent | 64fd0326701f75027efd6b82ac0ce28571041ec5 (diff) | |
download | taginfo-c07a5bce1a4815453e643309697e92eff5cbf667.tar taginfo-c07a5bce1a4815453e643309697e92eff5cbf667.tar.gz |
Improved and simplified highlighting of search results
Diffstat (limited to 'web')
-rw-r--r-- | web/public/js/taginfo.js | 23 | ||||
-rw-r--r-- | web/viewsjs/search.js.erb | 4 |
2 files changed, 9 insertions, 18 deletions
diff --git a/web/public/js/taginfo.js b/web/public/js/taginfo.js index cc6ed20..ec5a372 100644 --- a/web/public/js/taginfo.js +++ b/web/public/js/taginfo.js @@ -246,20 +246,6 @@ function pp_value(value) { return pp_value_replace(value); } -function pp_value_with_highlight(value, highlight) { - //var values = value.split(new RegExp(highlight, 'i')); - var values = value.split(highlight); - values = jQuery.map(values, function(value, i) { - return pp_value_replace(value); - }); - highlight = pp_value_replace(highlight); - return values.join('<b>' + highlight + '</b>'); -} - -function link_to_value_with_highlight(key, value, highlight) { - return link(url_for_tag(key, value), pp_value_with_highlight(value, highlight)); -} - function link_to_key(key, highlight) { return link( url_for_key(key), @@ -269,8 +255,13 @@ function link_to_key(key, highlight) { ); } -function link_to_value(key, value) { - return link(url_for_tag(key, value), pp_value(value)); +function link_to_value(key, value, highlight) { + return link( + url_for_tag(key, value), + highlight === undefined ? + pp_value(value) : + value.replace(new RegExp('(' + highlight + ')', 'gi'), "<b>$1</b>") + ); } function link_to_tag(key, value) { diff --git a/web/viewsjs/search.js.erb b/web/viewsjs/search.js.erb index cbaa842..ee7d33b 100644 --- a/web/viewsjs/search.js.erb +++ b/web/viewsjs/search.js.erb @@ -36,7 +36,7 @@ var create_flexigrid_for = { return { 'cell': [ print_with_ts(row.count_all), link_to_key(row.key), - link_to_value_with_highlight(row.key, row.value, query) + link_to_value(row.key, row.value, query) ] }; }); return data; @@ -60,7 +60,7 @@ var create_flexigrid_for = { return { 'cell': [ print_with_ts(row.count_all), link_to_key(row.key, q[0]), - link_to_value_with_highlight(row.key, row.value, q[1]) + link_to_value(row.key, row.value, q[1]) ] }; }); return data; |