Skip to content

New Features In One Point Three

Tim Down edited this page Mar 22, 2019 · 10 revisions

Documentation home

New features in Rangy 1.3

New TextRange module

Demo page

Character and word-based Range and Selection manipulation, relative to the visible text on the page. This is a major new module with some powerful features:

  • moveStart(), moveEnd(), move() and expand() Range methods inspired by IE's TextRange object
  • Page text search, using a string or a regular expression
  • Character offset-based selection save and restore, immune to changes in innerHTML
  • Selection snap to words
  • Cross-browser innerText implementation
  • Selection and range trimming

New Highlighter module

Demo page

API to allow creation, removal, serialization and deserialization of highlights within a page. It uses either character offsets relative to the page's textContent or the TextRange module's character-based features to keep track of highlight positions. This should be an improvement on the approach of the previous, unofficial Highlighter module, whose performance worsened exponentially as the number of highlights increased.

Renamed CSS Class Applier module to Class Applier module

The file name in the latest Rangy build is now rangy-classapplier.js rather than rangy-cssclassapplier.js.

Property and method name changes

The old methods are still present as aliases but are deprecated and may be removed in the future.

  • rangy.createCssClassApplier() renamed to rangy.createClassApplier()
  • rangy.getIframeSelection() is now redundant. Use rangy.getSelection() instead.
  • rangy.createIframeRange() is now redundant. Use rangy.createRange() instead.
  • rangy.createIframeRangyRange() is now redundant. Use rangy.createRangyRange() instead.

Additions and enhancements

  • AMD support
  • NPM module called rangy
  • Bower support via rangy-release repository
  • Browserify support
  • Rangy's main entry functions are now much more permissive. For example, rangy.createRange() and rangy.getSelection() and all related methods now accept a Window, Document or iframe element
  • Added setStartAndEnd() convenience method to Range
  • Added getBookmark() and moveToBookmark() methods to Range and Selection
  • Added new useExistingElements option to class applier options object (issue 111)
  • Selection setSingleRange() now accepts an additional second parameter, direction
  • Every backwards Boolean API parameter replaced with string direction parameter. Booleans are still accepted, as are the strings "backwards", "backward", "forwards" and "forward"
  • Added applyToRanges(), unapplyToRanges() and toggleRanges() to class applier
  • Added removeEmptyElements option to class applier. When true, empty elements generated by (or appearing to be generated by) the applier are removed when applying or unapplying to a range or selection
  • Added getNativeTextRange() method to selection
  • Module loading improved: module script include order no longer matters, so long as rangy-core.js comes first. Modules now initialize automatically if Rangy has initialized. Also, the console now provides more helpful warning messages when modules fail to load.
  • New config option alertOnFail to allow control over whether Rangy displays an alert when it fails to initialize
  • New config option autoInitialize to allow control over whether Rangy automatically initializes when the page loads
  • Build script now works on non-Windows platforms
  • Various additions to rangy.dom