searchHighlight
// gets the term from the URL
function getSearchTerm() {
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++) {
hash = hashes[i].split('=');
vars.push(hash[0]);vars[hash[0]] = hash[1];
}
return vars;
}
// highlights the term inside the content
// also includes the menu--can control in the CSS
var term = getSearchTerm()["Highlight"];
term = decodeURIComponent(term);
var src_str = $("section.main-section").html();
sterm = term.replace(/(\s+)/,"(<[^>]+>)*$1(<[^>]+>)*");
var pattern = new RegExp("("+term+")", "gi");
src_str = src_str.replace(pattern, "<mark>$1</mark>");
src_str = src_str.replace(/(<mark>[^<>]*)((<[^>]+>)+)([^<>]*<\/mark>)/,"$1</mark>$2<mark>$4");
$("section.main-section").html(src_str);