goog.dom.TextRange
Classgoog.dom.TextRange
> goog.dom.AbstractRange
goog.dom.TextRange()
Create a new text selection with no properties. Do not use this constructor: use one of the goog.dom.Range.createFrom* methods instead.
.__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.
opt_keys
{boolean
=}
goog.dom.TextRangeIterator
}
.clone()
goog.dom.TextRange
}
.collapse(toAnchor)
Collapses the range to one of its boundary points.
toAnchor
{boolean
}
.containsNode(node, opt_allowPartial)
Inherited from goog.dom.AbstractRange
.
Tests if this range contains the given node.
node
{Node
}
opt_allowPartial
{boolean
=}
boolean
}
.containsRange(range, opt_allowPartial)
Tests if this range contains the given range.
range
{goog.dom.AbstractRange
}
opt_allowPartial
{boolean
=}
boolean
}
.createFromBrowserRange(range, opt_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.
range
{Range
|TextRange
}
opt_isReversed
{boolean
=}
goog.dom.TextRange
}
.createFromNodeContents(node, opt_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.
node
{Node
}
opt_isReversed
{boolean
=}
goog.dom.TextRange
}
.createFromNodes(anchorNode, anchorOffset, focusNode, focusOffset)
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.
anchorNode
{Node
}
anchorOffset
{number
}
focusNode
{Node
}
focusOffset
{number
}
goog.dom.TextRange
}
.getAnchorNode()
Inherited from goog.dom.AbstractRange
.
Node
}
.getAnchorOffset()
Inherited from goog.dom.AbstractRange
.
number
}
.getBrowserRangeObject()
Range
|TextRange
}
.getContainer()
Node
}
.getContainerElement()
Inherited from goog.dom.AbstractRange
.
Returns the deepest element in the tree that contains the entire range.
Element
}
.getDocument()
Inherited from goog.dom.AbstractRange
.
Document
}
.getEndNode()
Node
}
.getEndOffset()
number
}
.getFocusNode()
Inherited from goog.dom.AbstractRange
.
Node
}
.getFocusOffset()
Inherited from goog.dom.AbstractRange
.
number
}
.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.
string
}
.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.
string
}
.getStartNode()
Node
}
.getStartOffset()
number
}
.getText()
string
}
.getTextRange(i)
Get the i-th text range in this range. The behavior is undefined if i >= getTextRangeCount or i < 0.
i
{number
}
goog.dom.TextRange
}
.getTextRangeCount()
number
}
.getTextRanges()
Inherited from goog.dom.AbstractRange
.
Gets an array of all text ranges this range is comprised of. For non-multi ranges, returns a single element array containing this.
Array
.<goog.dom.TextRange
>}
.getType()
goog.dom.RangeType
}
.getValidHtml()
Returns valid HTML for this range. This is fast on IE, and semi-fast on other browsers.
string
}
.getWindow()
Inherited from goog.dom.AbstractRange
.
Window
}
.insertNode(node, before)
Inserts a node before (or after) the range. The range may be disrupted beyond recovery because of the way this splits nodes.
node
{Node
}
before
{boolean
}
Node
}
.isAttachedNode(node)
Tests if the given node is in a document.
node
{Node
}
boolean
}
.isCollapsed()
boolean
}
.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.
boolean
}
.isReversed()
boolean
}
.moveToNodes(startNode, startOffset, endNode, endOffset, isReversed)
Moves a TextRange to the provided nodes and offsets.
startNode
{Node
}
startOffset
{number
}
endNode
{Node
}
endOffset
{number
}
isReversed
{boolean
}
.removeContents()
Removes the contents of the range from the document.
.replaceContentsWithNode(node)
Inherited from goog.dom.AbstractRange
.
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.
node
{Node
}
Node
}
.saveUsingCarets()
Inherited from goog.dom.AbstractRange
.
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.
goog.dom.SavedCaretRange
?}
.saveUsingDom()
Saves the range so that if the start and end nodes are left alone, it can be restored.
goog.dom.SavedRange
}
.select()
Sets this range as the selection in its window.
.setBrowserRangeObject(nativeRange)
Sets the native browser range object, overwriting any state this range was storing.
nativeRange
{Range
|TextRange
}
boolean
}
.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.
element
{Element
}
Element
}
.surroundWithNodes(startNode, endNode)
Surrounds this range with the two given nodes. The range may be disrupted beyond recovery because of the way this splits nodes.
startNode
{Element
}
endNode
{Element
}