webif/var/mongoose/html/lib/jquery.plugin/highlight/highlight.js
hummypkg 0f1bbed6b9 migrating
git-svn-id: file:///root/webif/svn/humax/pkg/src/webif/trunk@1789 2a923420-c742-0410-a762-8d5b09965624
2014-02-21 21:25:33 +00:00

45 lines
879 B
JavaScript

function highlight(obj, searchTerm)
{
var bodyText = obj.innerHTML;
stag = "<span class=yellowshade>";
etag = "</span>";
var newText = "";
var i = -1;
var lcSearchTerm = searchTerm.toLowerCase();
var lcBodyText = bodyText.toLowerCase();
while (bodyText.length > 0)
{
i = lcBodyText.indexOf(lcSearchTerm, i + 1);
if (i < 0)
{
newText += bodyText;
bodyText = "";
}
else
{
if (bodyText.lastIndexOf(">", i) >=
bodyText.lastIndexOf("<", i))
{
if (lcBodyText.lastIndexOf("/script>", i) >=
lcBodyText.lastIndexOf("<script", i))
{
newText += bodyText.substring(0, i) +
stag +
bodyText.substr(i,
searchTerm.length) + etag;
bodyText = bodyText.substr(i +
searchTerm.length);
lcBodyText = bodyText.toLowerCase();
i = -1;
}
}
}
}
obj.innerHTML = newText;
}