MCPcopy Create free account
hub / github.com/TimMcCool/scratchattach / highlight

Function highlight

docs/_build/html/_static/doctools.js:74–113  ·  view source on GitHub ↗
(node, addItems)

Source from the content-addressed store, hash-verified

72 */
73jQuery.fn.highlightText = function(text, className) {
74 function highlight(node, addItems) {
75 if (node.nodeType === 3) {
76 var val = node.nodeValue;
77 var pos = val.toLowerCase().indexOf(text);
78 if (pos >= 0 &&
79 !jQuery(node.parentNode).hasClass(className) &&
80 !jQuery(node.parentNode).hasClass("nohighlight")) {
81 var span;
82 var isInSVG = jQuery(node).closest("body, svg, foreignObject").is("svg");
83 if (isInSVG) {
84 span = document.createElementNS("http://www.w3.org/2000/svg", "tspan");
85 } else {
86 span = document.createElement("span");
87 span.className = className;
88 }
89 span.appendChild(document.createTextNode(val.substr(pos, text.length)));
90 node.parentNode.insertBefore(span, node.parentNode.insertBefore(
91 document.createTextNode(val.substr(pos + text.length)),
92 node.nextSibling));
93 node.nodeValue = val.substr(0, pos);
94 if (isInSVG) {
95 var rect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
96 var bbox = node.parentElement.getBBox();
97 rect.x.baseVal.value = bbox.x;
98 rect.y.baseVal.value = bbox.y;
99 rect.width.baseVal.value = bbox.width;
100 rect.height.baseVal.value = bbox.height;
101 rect.setAttribute('class', className);
102 addItems.push({
103 "parent": node.parentNode,
104 "target": rect});
105 }
106 }
107 }
108 else if (!jQuery(node).is("button, select, textarea")) {
109 jQuery.each(node.childNodes, function() {
110 highlight(this, addItems);
111 });
112 }
113 }
114 var addItems = [];
115 var result = this.each(function() {
116 highlight(this, addItems);

Callers 1

doctools.jsFile · 0.85

Calls 1

jQueryFunction · 0.85

Tested by

no test coverage detected