|
Project Information
Featured
Downloads
Links
|
A cross-browser JavaScript range and selection library. It provides a simple standards-based API for performing common DOM Range and Selection tasks in all major browsers, abstracting away the wildly different implementations of this functionality between Internet Explorer up to and including version 8 and DOM-compliant browsers. For manipulating selections in <textarea> and <input type="text"> elements, see Rangy's poorly-named and svelter twin project, Rangyinputs. Hosted files for the current stable release can always be found at http://rangy.googlecode.com/svn/trunk/currentrelease/. These are intended for use in demos using tools such as jsFiddle. Download | Change log | Documentation | Demos | Discussion group ContentsNews28 May 2012 Rangy 1.3 alpha released. The major new feature in 1.3 is the addition of the TextRange module. 26 February 2012 Rangy 1.2.3 released. This is a bugfix release that fixes issue 84 and issue 89 . 22 August 2011 Rangy 1.2 released. This release adds enhancements to the CSS class applier module and a few new core methods, plus several bugfixes. New features and documentation UsesIf you are a developing a JavaScript application that interacts with the user selection then Rangy will be able to help by providing a single API for all browsers and by simplifying common tasks. A particularly common scenario is when dealing with editable content within the browser, using designMode or contentEditable. FeaturesRangy’s main features are:
ModulesRangy also comes with modules, each of which builds on the core to provide a piece of user selection-related functionality. Current modules are:
Basic usagevar range = rangy.createRange(); // All DOM Range methods and properties supported range.selectNodeContents(document.body); // Selection object based on those in Mozilla, WebKit and Opera var sel = rangy.getSelection(); sel.removeAllRanges(); sel.addRange(range); Rangy also supplies convenience methods on its Range and Selection objects. For example, the previous two lines could be replaced by sel.setSingleRange(range); Browser supportRangy is tested and works fully in the following browsers:
Rangy may well work in many other browsers. It uses no specific browser detection, only feature detection, so any browser that has a minimal Range and Selection implementation will work to some degree. Also included are workarounds for some known flaws in older browsers such as Safari 2. |