I display some template
{{#each entries}}
{{> dirEntry}}
{{/each}}
Then I am highlighting searched words, replacing DOM text.
entries() {
const s = Session.get('searchTxt');
if(s) {
Meteor.setTimeout(function() {
highlight(s);
}, 1000);
}
return findLeads();
},
const highlightTextNodes = function(element, regex) {
var tempinnerHTML = element.innerHTML;
element.innerHTML = tempinnerHTML.replace(regex, '>$1<span class="highlighted">$2</span>$3<');
};
const highlight = function(searchString) {
// Starting node, parent to all nodes you want to search
const regexString = orbiter.core.txt2insensitiveregex(searchString);
var nodes = document.getElementsByClassName("entry");
_.each(nodes, function(node) {
// The regex is the secret, it prevents text within tag declarations to be affected
var regex = new RegExp(">([^<]*)?(" + regexString + ")([^>]*)?<", "ig");
highlightTextNodes(node, regex);
});
};
This breaks the template and it loses all reactivity behaviour. Every child templates autorun also are broken.
How can I highlight words client side without breaking the template ?