Highlight Search Term
Add a 'searchable' class to the fields you want to search
Use this in the doc
$(document).ready(function () {
if (search_term != null) {
search_term = search_term.trim();
var term = search_term;
term = term.replace(/(\s+)/, "(<[^>]+>)*$1(<[^>]+>)*");
var pattern = new RegExp("(" + term + ")", "gi");
$('#searchResults .searchable').each(function () {
var src_str = $(this).html()
src_str = src_str.replace(pattern, "<mark>$1</mark>");
src_str = src_str.replace(/(<mark>[^<>]*)((<[^>]+>)+)([^<>]*<\/mark>)/, "$1</mark>$2<mark>$4");
$(this).html(src_str);
});
}
Use this in the doc
$(document).ready(function () {
if (search_term != null) {
search_term = search_term.trim();
var term = search_term;
term = term.replace(/(\s+)/, "(<[^>]+>)*$1(<[^>]+>)*");
var pattern = new RegExp("(" + term + ")", "gi");
$('#searchResults .searchable').each(function () {
var src_str = $(this).html()
src_str = src_str.replace(pattern, "<mark>$1</mark>");
src_str = src_str.replace(/(<mark>[^<>]*)((<[^>]+>)+)([^<>]*<\/mark>)/, "$1</mark>$2<mark>$4");
$(this).html(src_str);
});
}
Comments