diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index c860800..d721dcf 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -16,7 +16,7 @@ jobs: strategy: matrix: - node-version: [14.x] + node-version: [20.x] steps: - uses: actions/checkout@v2 diff --git a/build/intro.js.txt b/build/intro.js.txt index e3e0699..9f5fdeb 100644 --- a/build/intro.js.txt +++ b/build/intro.js.txt @@ -1,7 +1,7 @@ /*! * treeDiffer.js * - * Version 1.1.0 + * Version 1.1.1 * https://github.com/Tchanders/treeDiffer.js * * Released under the MIT license diff --git a/demo/.eslintrc.json b/demo/.eslintrc.json index 5c22cae..54d2fb1 100644 --- a/demo/.eslintrc.json +++ b/demo/.eslintrc.json @@ -2,6 +2,7 @@ "root": true, "extends": "wikimedia/client", "globals": { - "treeDiffer": "readonly" + "treeDiffer": "readonly", + "OO": "readonly" } } diff --git a/demo/DomTreeNode.js b/demo/DomTreeNode.js new file mode 100644 index 0000000..f8a510e --- /dev/null +++ b/demo/DomTreeNode.js @@ -0,0 +1,51 @@ +/** + * Tree node for conducting a tree diff on DOM nodes. + * + * @class + * @extends treeDiffer.TreeNode + * + * @constructor + * @param {Node} node DOM node + */ +treeDiffer.DomTreeNode = function ( node ) { + // Parent constructor + treeDiffer.DomTreeNode.parent.call( this, node ); +}; + +OO.inheritClass( treeDiffer.DomTreeNode, treeDiffer.TreeNode ); + +/** + * Determine whether two tree nodes are equal. Here nodes are considered + * equal if they have the same tagName (if they are not text nodes), or + * have the same text content (if they are text nodes). + * + * @param {treeDiffer.TreeNode} otherNode The node to compare to this node + * @return {boolean} Nodes are equal + */ +treeDiffer.DomTreeNode.prototype.isEqual = function ( otherNode ) { + if ( this.node.nodeType === Node.TEXT_NODE ) { + return otherNode.node.nodeType === Node.TEXT_NODE && + otherNode.node.textContent === this.node.textContent; + } else { + return otherNode.node.tagName === this.node.tagName; + } +}; + +/** + * Gets children of the original node. + * + * @return {Array} Array of nodes the same type as the original node + */ +treeDiffer.DomTreeNode.prototype.getOriginalNodeChildren = function () { + const children = [], + childNodes = this.node.childNodes; + + for ( let i = 0, ilen = childNodes.length; i < ilen; i++ ) { + const childNode = childNodes[ i ]; + if ( !( childNode.nodeType === Node.TEXT_NODE && childNode.textContent.match( /^\s*$/ ) ) ) { + children.push( childNode ); + } + } + + return children; +}; diff --git a/demo/index.html b/demo/index.html index 58027a3..7347881 100644 --- a/demo/index.html +++ b/demo/index.html @@ -50,6 +50,7 @@