MCPcopy Create free account
hub / github.com/TruthHun/BookStack / innerHighlight

Function innerHighlight

static/js/jquery.highlight.js:2–23  ·  view source on GitHub ↗
(node, pat)

Source from the content-addressed store, hash-verified

1jQuery.fn.highlight = function(pat) {
2 function innerHighlight(node, pat) {
3 var skip = 0;
4 if (node.nodeType === 3) {
5 var pos = node.data.toUpperCase().indexOf(pat);
6 if (pos >= 0) {
7 var spannode = document.createElement('em');
8 spannode.className = 'search-highlight';
9 var middlebit = node.splitText(pos);
10 var endbit = middlebit.splitText(pat.length);
11 var middleclone = middlebit.cloneNode(true);
12 spannode.appendChild(middleclone);
13 middlebit.parentNode.replaceChild(spannode, middlebit);
14 skip = 1;
15 }
16 }
17 else if (node.nodeType === 1 && node.childNodes && !/(script|style)/i.test(node.tagName)) {
18 for (var i = 0; i < node.childNodes.length; ++i) {
19 i += innerHighlight(node.childNodes[i], pat);
20 }
21 }
22 return skip;
23 }
24 return this.each(function() {
25 innerHighlight(this, pat.toUpperCase());
26 });

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected