The goog.dom.Range Namespace

.clearSelection(opt_win)

Clears the window's selection.

opt_win {Window=}
The window to get the selection of. Defaults to the window this class was defined in.

.createCaret(node, offset)

Create a new range wrapper that represents a caret at the given node, accounting for the given offset. This always creates a TextRange, regardless of whether node is an image node or other control range type node.

node {Node}
The node to place a caret at.
offset {number}
The offset within the node to place the caret at.
returns {goog.dom.AbstractRange}
A range wrapper object.

.createFromBrowserRange(range, opt_isReversed)

Create a new range wrapper from the given browser range object.

range {Range|TextRange}
The browser range object.
opt_isReversed {boolean=}
Whether the focus node is before the anchor node.
returns {goog.dom.AbstractRange}
A range wrapper object.

.createFromBrowserSelection(selection)

Create a new range wrapper from the given browser selection object. Note that this object does not auto-update if the user changes their selection and should be used as a snapshot.

selection {!Object}
The browser selection object.
returns {goog.dom.AbstractRange?}
A range wrapper object or null if there was an error.

.createFromNodeContents(node, opt_isReversed)

Create a new range wrapper that selects the given node's text.

node {Node}
The node to select.
opt_isReversed {boolean=}
Whether the focus node is before the anchor node.
returns {goog.dom.AbstractRange}
A range wrapper object.

.createFromNodes(startNode, startOffset, endNode, endOffset)

Create a new range wrapper that selects the area between the given nodes, accounting for the given offsets.

startNode {Node}
The node to start with.
startOffset {number}
The offset within the node to start.
endNode {Node}
The node to end with.
endOffset {number}
The offset within the node to end.
returns {goog.dom.AbstractRange}
A range wrapper object.

.createFromWindow(opt_win)

Create a new selection from the given browser window's current selection. Note that this object does not auto-update if the user changes their selection and should be used as a snapshot.

opt_win {Window=}
The window to get the selection of. Defaults to the window this class was defined in.
returns {goog.dom.AbstractRange?}
A range wrapper object, or null if there was an error.

.hasSelection(opt_win)

Tests if the window has a selection.

opt_win {Window=}
The window to check the selection of. Defaults to the window this class was defined in.
returns {boolean}
Whether the window has a selection.

.isReversed(anchorNode, anchorOffset, focusNode, focusOffset)

Returns whether the focus position occurs before the anchor position.

anchorNode {Node}
The node to start with.
anchorOffset {number}
The offset within the node to start.
focusNode {Node}
The node to end with.
focusOffset {number}
The offset within the node to end.
returns {boolean}
Whether the focus position occurs before the anchor position.