Skip to content

Instantly share code, notes, and snippets.

@spocke
Created December 4, 2017 10:58
Show Gist options
  • Save spocke/b009c5ef460c188c8995eb46b064a6b7 to your computer and use it in GitHub Desktop.
Save spocke/b009c5ef460c188c8995eb46b064a6b7 to your computer and use it in GitHub Desktop.
TinyMCE tree structure

TinyMCE tree structure

The tinymce tree structure is a linked rose tree where each node has a reference to it's possible siblings and parents. It has also a few mutation methods that can be used to alter the structure in place. It's very similar to the browsers dom structure except that it doesn't have a children NodeList and it's completely virtual in that it doesn't rely on the dom in any way.

Node interface

Properties

 type: Number                                     // Node type 1=element, 3=text ...
 name: String                                     // Name of the element such as “h1” or #text
 prev?: Node                                      // Previous node reference or undefined
 next?: Node                                      // Next node reference or undefined
 parent?: Node                                    // Parent node or undefined
 firstChild?: Node                                // Firstchild node reference or undefined
 lastChild?: Node                                 // Lastchild node reference or undefined
 attributes?: Attribute[]                         // Array of attributes or undefined

Methods

 replace(new:Node):Node                           // Replaces the node with a new node
 attr(name:String, value?:String):String|Node     // Sets/gets attribute value.
 clone():Node                                     // Shallow clones the node
 wrap(wrapper:Node): Node                         // Wraps the node with another node
 unwrap():void                                    // Unwraps the node.
 remove():Node                                    // Removed the node.
 append(child:Node):Node                          // Appends a child node
 insert(node: Node, refNode: Node, before?: Bool) // Inserts a node at node reference
 getAll(name: String):Node[]                      // Returns an array of matching children
 empty():Node                                     // Removes all children.
 isEmpty(elements, whitespace, predicate)         // Checks if the node is empty
 walk(prev?:Boolean):Node?                        // Walks to the next/prev node.

Attribute interface

 name: String                                     // Name of the attribute
 value: String                                    // Value of the attribute
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment