Transaction object

Transaction object

The Transaction object (interface) is passed as a first parameter to the callback function used in Element.transact(callback,name) method.

Element.transact provides a way to execute one or many editing actions as a single transaction that can be undone (Undo/Redo functionality) or rolled back.

All DOM modifications that are made by other methods are not transactable.

Properties

N/A

Enumeration

N/A

Methods

attr
( element:Element, name: string, value: undefined | string ) : Transact

Add or remove elements attribute by name. To remove attribute use undefined value.

tag
( element:Element, tag: string ) : Transact

Change tag of the element. For example in some cases you may want to change <p> to <li> without recreating the element.

split
( pos:bookmark, until: Element ) : Transact

Split DOM elements at pos position until the element. Example, for the markup:

<p id=test>123<b>456</b>789</p>

This code:

var p = $(p#test);
var b = p.$(b);
var pos = [bookmark: b.nodes()[0], 1, false]; // start edge of character '5' in first text node of the <b> element.
transact.split( pos, p );

will change the DOM to this state:

<p id=test>123<b>4</b><b>56</b>789</p>
wrap
( from:bookmark, to:bookmark, into: Element ) : Transact

TBD (wraps range into the element)

unwrap
( el: Element ) : Transact

TBD (moves content of the element into its parent, removes the element).

insertNode
( node: Node, el: Element, at: index [, after: true] ) : Transact

TBD (insert Node or Element at index position inside the el).

removeNode
( node: Node ) : Transact

TBD (remove Node or Element from the DOM).

insertHtml
( at:bookmark, html:string ) : [nodes]

Inserts HTML fragment at the position. Returns array of inserted [top level] nodes.

insertText
( at:bookmark, text:string ) : bookmark

Inserts text at the position. Returns bookmark of last character inserted.

removeRange
( from:bookmark, to:bookmark ) : Transact

TBD (removes range from the DOM).