dom.TextRange Extends goog.dom.AbstractRange
Create a new text selection with no properties. Do not use this constructor: use one of the goog.dom.Range.createFrom* methods instead.

Inheritance

Object
     goog.dom.AbstractRange
          goog.dom.TextRange

Constructor

goog.dom.TextRange()

Instance Methods

Public Protected Private
__iterator__(opt_keys)
Returns a TextRangeIterator over the contents of the range. Regardless of the direction of the range, the iterator will move in document order.
Arguments:
opt_keys :
Unused for this iterator.
Returns:   An iterator over tags in the range.
code »
clearCachedValues_()
Clear all cached values.
code »
clone()
No description.
Returns:   A clone of this range.
code »
collapse(toAnchor)
No description.
Arguments:
toAnchor :
No description.
code »
containsRange(otherRangeopt_allowPartial)
No description.
Arguments:
otherRange :
No description.
opt_allowPartial :
No description.
code »
getBrowserRangeObject()
No description.
code »
getBrowserRangeWrapper_()
No description.
Returns:   The range wrapper object.
code »
getContainer()
No description.
code »
getEndNode()
No description.
code »
getEndOffset()
No description.
code »
getHtmlFragment()
No description.
code »
getPastableHtml()
No description.
code »
getStartNode()
No description.
code »
getStartOffset()
No description.
code »
getText()
No description.
code »
getTextRange(i)
No description.
Arguments:
i :
No description.
code »
getTextRangeCount()
No description.
code »
getType()
No description.
code »
getValidHtml()
No description.
code »
insertNode(nodebefore)
No description.
Arguments:
node :
No description.
before :
No description.
code »
isCollapsed()
No description.
code »
isRangeInDocument()
No description.
code »
isReversed()
No description.
code »
moveToNodes(startNodestartOffsetendNodeendOffsetisReversed)
Moves a TextRange to the provided nodes and offsets.
Arguments:
startNode :
The node to start with.
startOffset :
The offset within the node to start.
endNode :
The node to end with.
endOffset :
The offset within the node to end.
isReversed :
Whether the range is reversed.
code »
removeContents()
No description.
code »
saveUsingDom()
No description.
code »
select()
No description.
code »
setBrowserRangeObject(nativeRange)
No description.
Arguments:
nativeRange :
No description.
code »
surroundContents(element)
Surrounds the text range with the specified element (on Mozilla) or with a clone of the specified element (on IE). Returns a reference to the surrounding element if the operation was successful; returns null if the operation failed.
Arguments:
element :
The element with which the selection is to be surrounded.
Returns:   The surrounding element (same as the argument on Mozilla, but not on IE), or null if unsuccessful.
code »
surroundWithNodes(startNodeendNode)
No description.
Arguments:
startNode :
No description.
endNode :
No description.
code »
__iterator__()
Returns a RangeIterator over the contents of the range. Regardless of the direction of the range, the iterator will move in document order.
Returns:   An iterator over tags in the range.
code »
No description.
Returns:   A clone of this range.
code »
collapse()
Collapses the range to one of its boundary points.
code »
containsNode(nodeopt_allowPartial)
Tests if this range contains the given node.
Arguments:
node :
The node to test for.
opt_allowPartial :
If not set or false, the node must be entirely contained in the selection for this function to return true.
Returns:   Whether this range contains the given node.
code »
containsRange()
Tests if this range contains the given range.
Returns:   Whether this range contains the given range.
code »
getAnchorNode()
No description.
Returns:   The element or text node the range is anchored at.
code »
getAnchorOffset()
No description.
Returns:   The offset into the node the range is anchored at. For text nodes, this is an offset into the node value. For elements, this is an offset into the childNodes array.
code »
getBrowserRangeObject()
Range | TextRange
No description.
Returns: 
Range | TextRange
  The native browser range object.
code »
getContainer()
No description.
Returns:   The deepest node that contains the entire range.
code »
getContainerElement()
Returns the deepest element in the tree that contains the entire range.
Returns:   The deepest element that contains the entire range.
code »
getDocument()
No description.
Returns:   The document this selection is a part of.
code »
getEndNode()
No description.
Returns:   The element or text node the range ends in.
code »
getEndOffset()
No description.
Returns:   The offset into the node the range ends in. For text nodes, this is an offset into the node value. For elements, this is an offset into the childNodes array.
code »
getFocusNode()
No description.
Returns:   The element or text node the range is focused at - i.e. where the cursor is.
code »
getFocusOffset()
No description.
Returns:   The offset into the node the range is focused at - i.e. where the cursor is. For text nodes, this is an offset into the node value. For elements, this is an offset into the childNodes array.
code »
getHtmlFragment()
Returns the HTML fragment this range selects. This is slow on all browsers. The HTML fragment may not be valid HTML, for instance if the user selects from a to b inclusively in the following html: >div<a>/div<b This method will return a</div>b If you need valid HTML, use {@link #getValidHtml} instead.
Returns:   HTML fragment of the range, does not include context containing elements.
code »
getPastableHtml()
Returns pastable HTML for this range. This guarantees that any child items that must have specific ancestors will have them, for instance all TDs will be contained in a TR in a TBODY in a TABLE and all LIs will be contained in a UL or OL as appropriate. This is semi-fast on all browsers.
Returns:   Pastable HTML of the range, including context containing elements.
code »
getStartNode()
No description.
Returns:   The element or text node the range starts in. For text ranges, the range comprises all text between the start and end position. For other types of range, start and end give bounds of the range but do not imply all nodes in those bounds are selected.
code »
getStartOffset()
No description.
Returns:   The offset into the node the range starts in. For text nodes, this is an offset into the node value. For elements, this is an offset into the childNodes array.
code »
getText()
No description.
Returns:   The text content of the range.
code »
getTextRange()
Get the i-th text range in this range. The behavior is undefined if i >= getTextRangeCount or i < 0.
Returns:   The i-th text range.
code »
getTextRangeCount()
No description.
Returns:   The number of text ranges in this range.
code »
getTextRanges()
Gets an array of all text ranges this range is comprised of. For non-multi ranges, returns a single element array containing this.
Returns:   Array of text ranges.
code »
getType()
goog.dom.RangeType
No description.
Returns: 
goog.dom.RangeType
  The type of range represented by this object.
code »
getValidHtml()
Returns valid HTML for this range. This is fast on IE, and semi-fast on other browsers.
Returns:   Valid HTML of the range, including context containing elements.
code »
getWindow()
No description.
Returns:   The window this selection is a part of.
code »
insertNode()
Inserts a node before (or after) the range. The range may be disrupted beyond recovery because of the way this splits nodes.
Returns:   The node added to the document. This may be different than the node parameter because on IE we have to clone it.
code »
isCollapsed()
No description.
Returns:   Whether the range is collapsed.
code »
isRangeInDocument()
Tests whether this range is valid (i.e. whether its endpoints are still in the document). A range becomes invalid when, after this object was created, either one or both of its endpoints are removed from the document. Use of an invalid range can lead to runtime errors, particularly in IE.
Returns:   Whether the range is valid.
code »
isReversed()
No description.
Returns:   Whether the selection is reversed.
code »
removeContents()
No description.
code »
replaceContentsWithNode(node)
Replaces the range contents with (possibly a copy of) the given node. The range may be disrupted beyond recovery because of the way this splits nodes.
Arguments:
node :
The node to insert.
Returns:   The node added to the document. This may be different than the node parameter because on IE we have to clone it.
code »
saveUsingCarets()
Saves the range using HTML carets. As long as the carets remained in the HTML, the range can be restored...even when the HTML is copied across documents.
Returns:   A range representation that can be restored as long as carets are not removed. Returns null if carets could not be created.
code »
saveUsingDom()
Saves the range so that if the start and end nodes are left alone, it can be restored.
Returns:   A range representation that can be restored as long as the endpoint nodes of the selection are not modified.
code »
select()
No description.
code »
setBrowserRangeObject(nativeRange)
Sets the native browser range object, overwriting any state this range was storing.
Arguments:
nativeRange :
Range | TextRange
The native browser range object.
Returns:   Whether the given range was accepted. If not, the caller will need to call goog.dom.Range.createFromBrowserRange to create a new range object.
code »
surroundWithNodes()
Surrounds this range with the two given nodes. The range may be disrupted beyond recovery because of the way this splits nodes.
code »

Instance Properties

browserRangeWrapper_ :
The browser specific range wrapper. This can be null if one of the other representations of the range is specified.
Code »
endNode_ :
The end node of the range. This can be null if one of the other representations of the range is specified.
Code »
endOffset_ :
The end offset of the range. This can be null if one of the other representations of the range is specified.
Code »
isReversed_ :
Whether the focus node is before the anchor node.
Code »
startNode_ :
The start node of the range. This can be null if one of the other representations of the range is specified.
Code »
startOffset_ :
The start offset of the range. This can be null if one of the other representations of the range is specified.
Code »

Static Methods

goog.dom.TextRange.createFromBrowserRange(rangeopt_isReversed)
Create a new range wrapper from the given browser range object. Do not use this method directly - please use goog.dom.Range.createFrom* instead.
Arguments:
range :
Range | TextRange
The browser range object.
opt_isReversed :
Whether the focus node is before the anchor node.
Returns:   A range wrapper object.
code »
goog.dom.TextRange.createFromBrowserRangeWrapper_(browserRangeopt_isReversed)
Create a new range wrapper from the given browser range wrapper.
Arguments:
browserRange :
The browser range wrapper.
opt_isReversed :
Whether the focus node is before the anchor node.
Returns:   A range wrapper object.
code »
goog.dom.TextRange.createFromNodeContents(nodeopt_isReversed)
Create a new range wrapper that selects the given node's text. Do not use this method directly - please use goog.dom.Range.createFrom* instead.
Arguments:
node :
The node to select.
opt_isReversed :
Whether the focus node is before the anchor node.
Returns:   A range wrapper object.
code »
goog.dom.TextRange.createFromNodes(anchorNodeanchorOffsetfocusNodefocusOffset)
Create a new range wrapper that selects the area between the given nodes, accounting for the given offsets. Do not use this method directly - please use goog.dom.Range.createFrom* instead.
Arguments:
anchorNode :
The node to start with.
anchorOffset :
The offset within the node to start.
focusNode :
The node to end with.
focusOffset :
The offset within the node to end.
Returns:   A range wrapper object.
code »
goog.dom.TextRange.isAttachedNode(node)
Tests if the given node is in a document.
Arguments:
node :
The node to check.
Returns:   Whether the given node is in the given document.
code »

Package dom

Package Reference