Does anyone know of any cross-browser user selection range libraries written in javascript?
I found a few jQuery plugins, (which quite frankly are too limiting and very buggy).
I would just like to know what you have found out there. Don’t send me googling this again, (I’ve spent days working on all this). Hopefully, this can be where future programmers can find the answer.
I’ve developed a cross-browser Range and selection library called Rangy. Its core is not dissimilar in concept to IERange but goes beyond it in terms of implementation of the DOM level 2 Range and HTML5 selection specifications, and also in terms of stability and workarounds for browser bugs. I think it’s the best there is out there.
There are also extra modules for saving, restoring and serializing selections and applying CSS class to ranges and selections.
https://github.com/timdown/rangy
The following uses some Rangy extensions to Ranges to easily iterate over text nodes within a selection and surround each one: