Debian Codegraph @

extensions/VisualEditor/lib/ve/src/ve.DiffTreeNode.js

raw symbols SCIP
1 /*!
2 * VisualEditor DiffTreeNode class.
3 *
4 * @copyright See AUTHORS.txt
5 * @license The MIT License (MIT); see LICENSE.txt
6 */
7
8 /* global treeDiffer */
9
10 /**
11 * Tree node for conducting a tree diff.
12 *
13 * @class
14 * @extends treeDiffer.TreeNode
15 * @constructor
16 * @param {Object} node Node of any type
17 * @param {Object} config
18 */
19 ve.DiffTreeNode = function ( node ) {
20 // Parent constructor
21 ve.DiffTreeNode.super.apply( this, arguments );
22
23 this.doc = node.getDocument();
24 };
25
26 /* Inheritance */
27
28 OO.inheritClass( ve.DiffTreeNode, treeDiffer.TreeNode );
29
30 /* Methods */
31
32 /**
33 * Determine whether two nodes are equal. Branch nodes are considered equal if
34 * they have the same types and element.attributes. Content branch nodes are
35 * only equal if they also have the same content.
36 *
37 * @param {ve.DiffTreeNode} otherNode Node to compare to this node
38 * @return {boolean} The nodes are equal
39 */
40 ve.DiffTreeNode.prototype.isEqual = function ( otherNode ) {
41 if ( !this.node.isDiffedAsTree() && !otherNode.node.isDiffedAsTree() ) {
42 return ve.dm.VisualDiff.static.compareNodes( this.node, otherNode.node );
43 } else {
44 return ve.dm.ElementLinearData.static.compareElementsUnannotated( this.node.element, otherNode.node.element );
45 }
46 };
47
48 /**
49 * Get the children of the original node
50 *
51 * @return {Array} Array of nodes the same type as the original node
52 */
53 ve.DiffTreeNode.prototype.getOriginalNodeChildren = function () {
54 return ( this.node.isDiffedAsTree() && this.node.children ) || [];
55 };