all files / src/ ve.DiffTreeNode.js

100% Statements 12/12
100% Branches 10/10
100% Functions 3/3
100% Lines 12/12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61                                      91×   91×                               578× 72×     506×                   91× 60×   31×    
/*!
 * VisualEditor DiffTreeNode class.
 *
 * @copyright 2011-2019 VisualEditor Team and others; see http://ve.mit-license.org
 * @license The MIT License (MIT); see LICENSE.txt
 */
 
/* global treeDiffer */
 
/**
 * Tree node for conducting a tree diff.
 *
 * @class
 * @extends treeDiffer.TreeNode
 * @constructor
 * @param {Object} node Node of any type
 * @param {Object} config
 */
ve.DiffTreeNode = function ( node ) {
	// Parent constructor
	ve.DiffTreeNode.super.apply( this, arguments );
 
	this.doc = node.getDocument();
};
 
/* Inheritance */
 
OO.inheritClass( ve.DiffTreeNode, treeDiffer.TreeNode );
 
/* Methods */
 
/**
 * Determine whether two nodes are equal. Branch nodes are considered equal if
 * they have the same types and element.attributes. Content branch nodes are
 * only equal if they also have the same content.
 *
 * @param {ve.DiffTreeNode} otherNode Node to compare to this node
 * @return {boolean} The nodes are equal
 */
ve.DiffTreeNode.prototype.isEqual = function ( otherNode ) {
	if ( this.node.canContainContent() && otherNode.node.canContainContent() ) {
		return JSON.stringify( this.doc.getData( this.node.getOuterRange() ) ) ===
			JSON.stringify( otherNode.doc.getData( otherNode.node.getOuterRange() ) );
	} else {
		return ( this.node.getType() === otherNode.node.getType() &&
			ve.compare( this.node.getHashObject(), otherNode.node.getHashObject() ) );
	}
};
 
/**
 * Get the children of the original node
 *
 * @return {Array} Array of nodes the same type as the original node
 */
ve.DiffTreeNode.prototype.getOriginalNodeChildren = function () {
	if ( this.node.children && !this.node.canContainContent() ) {
		return this.node.children;
	}
	return [];
};