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.

text 
( element:Element | Node, newText: string ) : Transact

Changes text of the element or text node.

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 ) : Bookmark

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>

The function returns bookmark set to position inside until element.

wrap
( from:bookmark, to:bookmark, into: Element ) : Transact

Wraps from..to range into the element. 

Returns two bookmarks - start and end of content range that was wrapped.

unwrap
( el: Element ) : [bookmark,bookmark]

Moves content of the element into its parent (P), removes the element. 

Returns two bookmarks - start and end of content range that was merged into P element. 

insertNode
( at:bookmark, node: Node ) : Transact

Insert Node or Element at at position in the DOM).

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).