dom.SavedCaretRange Extends goog.dom.SavedRange
A struct for holding context about saved selections. This can be used to preserve the selection and restore while the DOM is manipulated, or through an asynchronous call. Use goog.dom.Range factory methods to obtain an instance, and use to obtain a SavedCaretRange. For editor ranges under content-editable elements or design-mode iframes, prefer using .

Inheritance

Constructor

goog.dom.SavedCaretRange(range)

Parameters

range : goog.dom.AbstractRange
The range being saved.

Instance Methods

Public Protected Private
createCaret_(start) !Element
Creates a caret element.
Arguments:
start : boolean
If true, creates the start caret. Otherwise, creates the end caret.
Returns: !Element  The new caret element.
code »
disposeInternal()
Dispose the saved range and remove the carets from the DOM.
code »
getCaret(start) Element
Gets carets.
Arguments:
start : boolean
If true, returns the start caret. Otherwise, get the end caret.
Returns: Element  The start or end caret in the given document.
code »
removeCarets(opt_range) goog.dom.AbstractRange | undefined
Removes the carets from the current restoration document.
Arguments:
opt_range : goog.dom.AbstractRange=
A range whose offsets have already been adjusted for caret removal; it will be adjusted if it is also affected by post-removal operations, such as text node normalization.
Returns: goog.dom.AbstractRange | undefined  The adjusted range, if opt_range was provided.
code »
restoreInternal() ?goog.dom.AbstractRange
Reconstruct the selection from the given saved range. Removes carets after restoring the selection. If restore does not dispose this saved range, it may only be restored a second time if innerHTML or some other mechanism is used to restore the carets to the dom.
Returns: ?goog.dom.AbstractRange  Restored selection.
code »
setRestorationDocument(doc)
Sets the document where the range will be restored.
Arguments:
doc : !Document
An HTML document.
code »
toAbstractRange() ?goog.dom.AbstractRange
Gets the range that this SavedCaretRage represents, without selecting it or removing the carets from the DOM.
Returns: ?goog.dom.AbstractRange  An abstract range.
code »
restore(opt_stayAlive) goog.dom.AbstractRange
Restores the range and by default disposes of the saved copy. Take note: this means the by default SavedRange objects are single use objects.
Arguments:
opt_stayAlive : boolean=
Whether this SavedRange should stay alive (not be disposed) after restoring the range. Defaults to false (dispose).
Returns: goog.dom.AbstractRange  The restored range.
code »
restoreInternal() goog.dom.AbstractRange
Internal method to restore the saved range.
Returns: goog.dom.AbstractRange  The restored range.
code »
addOnDisposeCallback(callbackopt_scope)
Invokes a callback function when this object is disposed. Callbacks are invoked in the order in which they were added.
Arguments:
callback : function(this:T):?
The callback function.
opt_scope : T=
An optional scope to call the callback in.
code »
dispose() void
Disposes of the object. If the object hasn't already been disposed of, calls #disposeInternal. Classes that extend goog.Disposable should override #disposeInternal in order to delete references to COM objects, DOM nodes, and other disposable objects. Reentrant.
Returns: void  Nothing.
code »
disposeInternal()
Deletes or nulls out any references to COM objects, DOM nodes, or other disposable objects. Classes that extend goog.Disposable should override this method. Not reentrant. To avoid calling it twice, it must only be called from the subclass' disposeInternal method. Everywhere else the public dispose method must be used. For example:
  mypackage.MyClass = function() {
    mypackage.MyClass.base(this, 'constructor');
    // Constructor logic specific to MyClass.
    ...
  };
  goog.inherits(mypackage.MyClass, goog.Disposable);

  mypackage.MyClass.prototype.disposeInternal = function() {
    // Dispose logic specific to MyClass.
    ...
    // Call superclass's disposeInternal at the end of the subclass's, like
    // in C++, to avoid hard-to-catch issues.
    mypackage.MyClass.base(this, 'disposeInternal');
  };
code »
getDisposed() boolean
Use #isDisposed instead. No description.
Returns: boolean  Whether the object has been disposed of.
code »
isDisposed() boolean
No description.
Returns: boolean  Whether the object has been disposed of.
code »
registerDisposable(disposable)
Associates a disposable object with this object so that they will be disposed together.
Arguments:
disposable : goog.disposable.IDisposable
that will be disposed when this object is disposed.
code »

Instance Properties

constructor :
No description.
Code »
A DOM helper for storing the current document context.
Code »
endCaretId_ :
The DOM id of the caret at the end of the range.
Code »
reversed_ :
Whether the range is reversed (anchor at the end).
Code »
startCaretId_ :
The DOM id of the caret at the start of the range.
Code »
constructor :
No description.
Code »
creationStack :
If monitoring the goog.Disposable instances is enabled, stores the creation stack trace of the Disposable instance.
Code »
disposed_ :
Whether the object has been disposed of.
Code »
onDisposeCallbacks_ :
Callbacks to invoke when this object is disposed.
Code »

Static Methods

goog.dom.SavedCaretRange.htmlEqual(str1str2) boolean
Returns whether two strings of html are equal, ignoring any saved carets. Thus two strings of html whose only difference is the id of their saved carets will be considered equal, since they represent html with the same selection.
Arguments:
str1 : string
The first string.
str2 : string
The second string.
Returns: boolean  Whether two strings of html are equal, ignoring any saved carets.
code »

Static Properties

goog.dom.SavedCaretRange.CARET_REGEX :
A regex that will match all saved range carets in a string.
Code »
goog.dom.SavedCaretRange.superClass_ :
No description.
Code »

Package dom

Package Reference