

Inline Commenting with JavaScript. Looking for feedback - ggreiner
http://ggreiner.com/comment.html

======
ceautery
I couldn't get it to work in Chrome ("keyCode of undefined" errors). This is
similar to something I wrote for Automattic recently.

I was pretty pleased with how I tackled annotations across block level
elements. Essentially you find your range's start and end containers, and if
they match you can just range.surroundContents on them, but otherwise you
surroundContents multiple times, once for the start container to its end, once
for the end container, from its start until the end of the range, and then for
every block element in the middle. Fun stuff.

~~~
ggreiner
Thanks for the feedback! At what point in the process did you get those
errors? I tested it almost exclusively in chrome and its worked great for me
and the friends I sent it to.

I decided not to allow commenting across line breaks because they way I
highlight commented text looked weird across line breaks. However I thought my
way of allowing commenting over HTML tags (links and such) was pretty cool. I
found all HTML tags with a regex and then started removing them one at a time
from the bottom of the page until I could find the selected text. This gives
me the starting index in the raw HTML of the selection and then I just step
through the selection (skipping html tags) to find the ending index. Probably
not the most efficient method but it works well!

