Sha256: f0884b383796aaaf849bbcc236a84cc7cdd892a9c2f0793092e96990579963f5

Contents?: true

Size: 1.98 KB

Versions: 46

Compression:

Stored size: 1.98 KB

Contents

"use strict";

const { convertNodesIntoNode } = require("../node");

class ChildNodeImpl {
  remove() {
    if (!this.parentNode) {
      return;
    }

    this.parentNode._remove(this);
  }

  after(...nodes) {
    const parent = this.parentNode;
    if (parent) {
      let viableNextSibling = this.nextSibling;
      let idx = viableNextSibling ? nodes.indexOf(viableNextSibling) : -1;

      while (idx !== -1) {
        viableNextSibling = viableNextSibling.nextSibling;
        if (!viableNextSibling) {
          break;
        }
        idx = nodes.indexOf(viableNextSibling);
      }

      parent._preInsert(convertNodesIntoNode(this._ownerDocument, nodes), viableNextSibling);
    }
  }

  before(...nodes) {
    const parent = this.parentNode;
    if (parent) {
      let viablePreviousSibling = this.previousSibling;
      let idx = viablePreviousSibling ? nodes.indexOf(viablePreviousSibling) : -1;

      while (idx !== -1) {
        viablePreviousSibling = viablePreviousSibling.previousSibling;
        if (!viablePreviousSibling) {
          break;
        }
        idx = nodes.indexOf(viablePreviousSibling);
      }

      parent._preInsert(
        convertNodesIntoNode(this._ownerDocument, nodes),
        viablePreviousSibling ? viablePreviousSibling.nextSibling : parent.firstChild
      );
    }
  }

  replaceWith(...nodes) {
    const parent = this.parentNode;
    if (parent) {
      let viableNextSibling = this.nextSibling;
      let idx = viableNextSibling ? nodes.indexOf(viableNextSibling) : -1;

      while (idx !== -1) {
        viableNextSibling = viableNextSibling.nextSibling;
        if (!viableNextSibling) {
          break;
        }
        idx = nodes.indexOf(viableNextSibling);
      }

      const node = convertNodesIntoNode(this._ownerDocument, nodes);

      if (this.parentNode === parent) {
        parent._replace(node, this);
      } else {
        parent._preInsert(node, viableNextSibling);
      }
    }
  }
}

module.exports = {
  implementation: ChildNodeImpl
};

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/nodes/ChildNode-impl.js
clapton-0.0.25 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/nodes/ChildNode-impl.js
clapton-0.0.24 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/nodes/ChildNode-impl.js
clapton-0.0.23 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/nodes/ChildNode-impl.js
clapton-0.0.22 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/nodes/ChildNode-impl.js
clapton-0.0.21 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/nodes/ChildNode-impl.js
clapton-0.0.20 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/nodes/ChildNode-impl.js
clapton-0.0.19 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/nodes/ChildNode-impl.js
clapton-0.0.18 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/nodes/ChildNode-impl.js
clapton-0.0.17 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/nodes/ChildNode-impl.js
clapton-0.0.16 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/nodes/ChildNode-impl.js
clapton-0.0.15 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/nodes/ChildNode-impl.js
clapton-0.0.14 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/nodes/ChildNode-impl.js
clapton-0.0.13 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/nodes/ChildNode-impl.js
clapton-0.0.12 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/nodes/ChildNode-impl.js
clapton-0.0.11 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/nodes/ChildNode-impl.js
clapton-0.0.10 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/nodes/ChildNode-impl.js
clapton-0.0.9 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/nodes/ChildNode-impl.js
clapton-0.0.8 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/nodes/ChildNode-impl.js
clapton-0.0.7 lib/clapton/javascripts/node_modules/jsdom/lib/jsdom/living/nodes/ChildNode-impl.js