(node)
| 67 | */ |
| 68 | jQuery.fn.highlightText = function(text, className) { |
| 69 | function highlight(node) { |
| 70 | if (node.nodeType == 3) { |
| 71 | var val = node.nodeValue; |
| 72 | var pos = val.toLowerCase().indexOf(text); |
| 73 | if (pos >= 0 && !jQuery(node.parentNode).hasClass(className)) { |
| 74 | var span = document.createElement("span"); |
| 75 | span.className = className; |
| 76 | span.appendChild(document.createTextNode(val.substr(pos, text.length))); |
| 77 | node.parentNode.insertBefore(span, node.parentNode.insertBefore( |
| 78 | document.createTextNode(val.substr(pos + text.length)), |
| 79 | node.nextSibling)); |
| 80 | node.nodeValue = val.substr(0, pos); |
| 81 | } |
| 82 | } |
| 83 | else if (!jQuery(node).is("button, select, textarea")) { |
| 84 | jQuery.each(node.childNodes, function() { |
| 85 | highlight(this); |
| 86 | }); |
| 87 | } |
| 88 | } |
| 89 | return this.each(function() { |
| 90 | highlight(this); |
| 91 | }); |
no test coverage detected