SelectionStart SelectionEnd Range

248 views Asked by At

I'm analyzing a piece of software made by others, it's called Editarea. This software is made in Javascript and it colorizes the word step by step while you're typing. This is the most useful feature of this software for me, as I have to make an editor which colorizes the words in real time. The problem is that I cannot understand "HOW" this task is being done by the javascript editor of editarea.

Is it possible to perform a real time color of a text in javascript without actually using onkeypress or onkeydown events? Or, for being more specific, is it possible to perform it by selecting a portion of text with a selection object or a range object depending of which browser the user is using?

I'm wandering because a cannot use a debugger(the script is all included in a string in the original version) so it's very hard to understand where the script i'm modifing is changing the color of the text.So I'm only asking if it can really be done only with a selection object or you absolutely need an onkeypress or onkeydown event to perform the task.

Thank you all for the answer.

Agnese

1

There are 1 answers

0
Justin Russo On

I don't have time to dig through their code, however, I can give you a clue as to where to look.

There is an obfuscated area of code in the form of a literal string being evaluated when the code runs, at the bottom of the 'edit_area_full.js' file. Take this code and look for everywhere either JQuery or raw Javascript is using this DOM element. I bet at some point, an event handler is being added dynamically when this code runs during the body 'onload' event.