views:

782

answers:

3

I've been working with selection/range objects, and because to the incredible amount of inconsistencies between browsers for specific selection/range stuff (even more than the DOM) I was wondering if there was a framework that would help me get through them.

+1  A: 

fieldselection is a very usable jquery plugin for selection/range manipulation.

The MYYN
Only works for textareas and inputs though.
Tim Down
+4  A: 

(Made an answer by request ;)

Take a look at IERange:

IERange is a feature-complete implementation of W3C DOM Ranges for Internet Explorer, allowing users to write one cross-browser version of their range manipulation code.

Supports Range APIs:

  • document.createRange()
  • startContainer, startOffset, endContainer, endOffset, commonAncestorContainer, collapsed
  • setStart(), setEnd(), setStartBefore(), setStartAfter(), setEndBefore(), setEndAfter(), selectNode(), selectNodeContents(), collapse()
  • insertNode(), surroundContents()
  • extractContents(), cloneContents(), deleteContents()
  • compareBoundaryPoints(), cloneRange(), createContextualFragment(), toString()

Supports Selection APIs:

  • Range support (Webkit-style)
  • window.getSelection()
  • addRange(), removeAllRanges(), getRangeAt(), toString()
Roatin Marth
IERange's biggest strength is its algorithms for expressing a `TextRange` in terms of nodes and offsets (as a Range does) and converting such and object back into a `TextRange`. However, it cannot fully abstract away the differences between the two: for example, the underlying `TextRange` will change in response to changes in the DOM while the `IERange` built upon it will not reflect these changes. There are also discrepancies between how the user selection is represented as a Range, which are down to the browser. [continued]
Tim Down
Also note that creating an `IERange` is hugely slower than getting a DOM Range in other browsers. None of these are the library's fault; it's simply the nature of the problem. In short, best use with care and knowledge of the abstraction `IERange` represents.
Tim Down
+1  A: 

I've written a new range/selection library called Rangy that is similar in concept to IERange but goes quite a lot further. The core is pretty much complete and currently available to download. I'm currently bugfixing and documenting it and it should be only be a few weeks before a full release.

Tim Down
Thanks for your great work on Rangy Tim Down. I'm using your lib in my new project and already have send you a bug report. I think it would be a good idea to create a mailing list, so that it is possible to discuss issues/features and suggest new features (maybe with a patch). Eg., I'm currently trying to get a startOffset and endOffset for the commonAncestorContainer rather than start/end containers. This would be a helpful feature I believe.
Tom