Sha256: aeeac8cda10fc30bc851b8df55b8298021d50aadf53d18eec70fc2fb4af25b8d

Contents?: true

Size: 1.99 KB

Versions: 46

Compression:

Stored size: 1.99 KB

Contents

"use strict";

const HTMLElementImpl = require("./HTMLElement-impl").implementation;

const Document = require("../generated/Document");
const DocumentFragment = require("../generated/DocumentFragment");

const { cloningSteps, domSymbolTree } = require("../helpers/internal-constants");
const { clone } = require("../node");

class HTMLTemplateElementImpl extends HTMLElementImpl {
  constructor(globalObject, args, privateData) {
    super(globalObject, args, privateData);

    const doc = this._appropriateTemplateContentsOwnerDocument(this._ownerDocument);
    this._templateContents = DocumentFragment.createImpl(this._globalObject, [], {
      ownerDocument: doc,
      host: this
    });
  }

  // https://html.spec.whatwg.org/multipage/scripting.html#appropriate-template-contents-owner-document
  _appropriateTemplateContentsOwnerDocument(doc) {
    if (!doc._isInertTemplateDocument) {
      if (doc._associatedInertTemplateDocument === undefined) {
        const newDoc = Document.createImpl(this._globalObject, [], {
          options: {
            parsingMode: doc._parsingMode,
            encoding: doc._encoding
          }
        });
        newDoc._isInertTemplateDocument = true;

        doc._associatedInertTemplateDocument = newDoc;
      }

      doc = doc._associatedInertTemplateDocument;
    }

    return doc;
  }

  // https://html.spec.whatwg.org/multipage/scripting.html#template-adopting-steps
  _adoptingSteps() {
    const doc = this._appropriateTemplateContentsOwnerDocument(this._ownerDocument);
    doc._adoptNode(this._templateContents);
  }

  get content() {
    return this._templateContents;
  }

  [cloningSteps](copy, node, document, cloneChildren) {
    if (!cloneChildren) {
      return;
    }

    for (const child of domSymbolTree.childrenIterator(node._templateContents)) {
      const childCopy = clone(child, copy._templateContents._ownerDocument, true);
      copy._templateContents.appendChild(childCopy);
    }
  }
}

module.exports = {
  implementation: HTMLTemplateElementImpl
};

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