I have to highlight some words in a div[contenteditable=true] without modifying its html so I am duplicating the div and positioning the copy right behind the original and then apply some span around the words I need to higlight.
The original div may modify its class/attributes at any time so I want to keep the copy updated with any css changes and to do this I have this function which gets called everytime I call my highlighting function.
My problem is that this function takes to much time to execute, around 60 ms whereas the rest of my script takes about 1-4 ms.
What am I doing wrong here or how can I speed it up?
function positionOutputWindow(original,copy)
{
//console.log("positionOutputWindow");
//var start = new Date().getTime();
if (
!original ||
!copy ||
original.attr('id') == undefined ||
copy.attr('id') == undefined
) { return; }
var original_obj = original.get(0);
var copy_obj = copy.get(0);
var offset = original.offset();
copy.offset(offset);
copy.css({
'position': 'absolute',
'z-index': '2',
'color': 'transparent',
'flood-color': 'transparent',
'-webkit-text-fill-color': 'transparent',
//'overflow': 'hidden',
'outline': 'solid 0px red'/*,
'width': original.width() + 'px',
'height': original.height() + 'px'*/
});
copy.css("background",original.css("background"));
original.css({
//'overflow': 'hidden',
'background': 'transparent',
'position': 'relative',
'z-index': '3',
'outline': 'solid 0px green'
});
copy.width(original.width());
copy.height(original.height());
if ( original.get(0).nodeName == "INPUT" || original.get(0).nodeName == "TEXTAREA" )
{
copy.width(original_obj.scrollWidth);
copy.offset({ top: offset.top, left: offset.left - original_obj.scrollLeft });
}
copy.offset({ top: offset.top, left: offset.left });
copy.find('*').css('color','transparent');
//console.log("runtime position window " + (new Date().getTime() - start));
}