Sha256: aa6e3759fe330ceb7dd66bfc6cda50fca3a97d4952cefaaf8780b8752f7a4743

Contents?: true

Size: 1.29 KB

Versions: 46

Compression:

Stored size: 1.29 KB

Contents

"use strict";

const NODE_TYPE = require("../node-type");
const { domSymbolTree } = require("./internal-constants");

// https://dom.spec.whatwg.org/#concept-node-length
function nodeLength(node) {
  switch (node.nodeType) {
    case NODE_TYPE.DOCUMENT_TYPE_NODE:
      return 0;

    case NODE_TYPE.TEXT_NODE:
    case NODE_TYPE.PROCESSING_INSTRUCTION_NODE:
    case NODE_TYPE.COMMENT_NODE:
      return node.data.length;

    default:
      return domSymbolTree.childrenCount(node);
  }
}

// https://dom.spec.whatwg.org/#concept-tree-root
function nodeRoot(node) {
  while (domSymbolTree.parent(node)) {
    node = domSymbolTree.parent(node);
  }

  return node;
}

// https://dom.spec.whatwg.org/#concept-tree-inclusive-ancestor
function isInclusiveAncestor(ancestorNode, node) {
  while (node) {
    if (ancestorNode === node) {
      return true;
    }

    node = domSymbolTree.parent(node);
  }

  return false;
}

// https://dom.spec.whatwg.org/#concept-tree-following
function isFollowing(nodeA, nodeB) {
  if (nodeA === nodeB) {
    return false;
  }

  let current = nodeB;
  while (current) {
    if (current === nodeA) {
      return true;
    }

    current = domSymbolTree.following(current);
  }

  return false;
}

module.exports = {
  nodeLength,
  nodeRoot,

  isInclusiveAncestor,
  isFollowing
};

Version data entries

46 entries across 46 versions & 2 rubygems

Version Path
clapton-0.0.26 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/helpers/node.js
clapton-0.0.25 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/helpers/node.js
clapton-0.0.24 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/helpers/node.js
clapton-0.0.23 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/helpers/node.js
clapton-0.0.22 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/helpers/node.js
clapton-0.0.21 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/helpers/node.js
clapton-0.0.20 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/helpers/node.js
clapton-0.0.19 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/helpers/node.js
clapton-0.0.18 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/helpers/node.js
clapton-0.0.17 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/helpers/node.js
clapton-0.0.16 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/helpers/node.js
clapton-0.0.15 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/helpers/node.js
clapton-0.0.14 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/helpers/node.js
clapton-0.0.13 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/helpers/node.js
clapton-0.0.12 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/helpers/node.js
clapton-0.0.11 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/helpers/node.js
clapton-0.0.10 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/helpers/node.js
clapton-0.0.9 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/helpers/node.js
clapton-0.0.8 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/helpers/node.js
clapton-0.0.7 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/helpers/node.js