Problem
I am trying to figure out the selection offset from a specific node using javascript.
Let's say I have the following HTML
<p>Hi there. This <strong>is blowing my mind</strong> with difficulty.</p>
If I choose from a breath to difficulties, it gives me an offset from the #textnode inside <strong>. I need a line offset from <p> innerHTMLand a selection length. In this case, the offset will be 26, and the length will be 40.
My first thought was to do something with line offsets, etc., but you could easily have something like
<p> Hi there. This <strong>is awesome</strong>. For real. It <strong>is awesome</strong>.</p>
which will violate this method because there are identical nodes. I also need the option of ejecting nodes. Say I have something like this
<p>Hi there. <a href="#" rel="inserted">This <strong>is blowing</a> my mind</strong> with difficulty.</p>
I want to throw out the elements with rel="inserted"when I do the calculation. I still want to get the result 26 and 40.
What i'm looking for
. <span> <strong>, <p>.
rel="inserted". , . . - DOM, .
document.getSelection() . WebKit. jQuery - , , .
.
HTML, .